I have an image that is 234x432x4 size wise. I tried imshow() and image(), but it doesn't work. What do I use?

17 visualizzazioni (ultimi 30 giorni)
I have an image that is 234x432x4 size wise. I tried imshow() and image(), but it doesn't work. What do I use?

Risposte (2)

John D'Errico
John D'Errico il 29 Set 2022
You have a 4 channel image, most likely CMYK, certainly not RGB.
For example:
imshow(rand(234,432,3))
As you can see, there is no problem. However,
imshow(rand(234,432,4))
Error using images.internal.imageDisplayValidateParams>validateCData
Multi-plane image inputs must be RGB images of size MxNx3.

Error in images.internal.imageDisplayValidateParams (line 30)
common_args.CData = validateCData(common_args.CData,image_type);

Error in images.internal.imageDisplayParseInputs (line 79)
common_args = images.internal.imageDisplayValidateParams(common_args);

Error in imshow (line 253)
images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});
So assuming you have a CMYK image, you will need to convert it into equivalent RGB code values. Of course, I would not be surprised if there may be some gamut issues involved, so some colors will not be represented as well as you might desire.
If, in fact, you have a multispectral image of some other ilk, again, you need to convert it into an appropriate 3 channel color space.
  3 Commenti
John D'Errico
John D'Errico il 30 Set 2022
In any case, those tools are unable to handle 4 channel images for display. The image needs to be 3 channels, so it needs to be converted properly, if the image is to be viewed as something that makes sense. I do admit that viewing scenes as if they were RGB that are actually expressed as encoded L*a*b* often makes for an interesting (but confusing) picture though.

Accedi per commentare.


DGM
DGM il 1 Ott 2022
Modificato: DGM il 1 Ott 2022
If the image is CMYK, hyperspectral, or simply a volumetric image, then this answer really doesn't apply. Admittedly, it's more likely that an imported 4-channel image is not RGBA, but I'm going to assume you somehow managed to get an RGBA image assembled.
If the image is RGBA, then MIMT has tools for handling it. The basic idea is to just composite the image with a standard opaque background. At that point, it's just an RGBA image and the display tools can handle it just fine.
Using alphasafe() and imshow():
% a PNG with alpha (RGB + A)
[inpict,~,alpha] = imread('sources/standardmods/peppers_rgba.png');
% put the image back together (RGBA)
inpict = joinalpha(inpict,alpha);
% composite the image with checkerboard padding for the purpose of viewing
safepict = alphasafe(inpict); % using default options
% display the RGB representation of the RGBA image
imshow(safepict)
Alternatively, MIMT imshow2() handles RGBA images, as well as other things that imshow() doesn't. It's a bit janky since the default view controls were changed a few years ago, but maybe I'll fix that someday.
% a PNG with alpha (RGB + A)
[inpict,~,alpha] = imread('sources/standardmods/peppers_rgba.png');
% put the image back together (RGBA)
inpict = joinalpha(inpict,alpha);
% display the RGB representation of the RGBA image
imshow2(inpict)
The idea behind the first example can certainly be done without MIMT tools. This is one of several answers describing how to do basic image composition without specialized tools. I chose this one because it includes a simple example showing how the checkerboard matting can be generated.
When doing composition "manually" like this, it'll be important to pay attention to the class and scale of the image data.

Prodotti


Release

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by