I have an image that is 234x432x4 size wise. I tried imshow() and image(), but it doesn't work. What do I use?
18 ビュー (過去 30 日間)
古いコメントを表示
I have an image that is 234x432x4 size wise. I tried imshow() and image(), but it doesn't work. What do I use?
0 件のコメント
回答 (2 件)
John D'Errico
2022 年 9 月 29 日
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))
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 件のコメント
John D'Errico
2022 年 9 月 30 日
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.
Walter Roberson
2022 年 9 月 30 日
編集済み: Walter Roberson
2022 年 10 月 1 日
see through https://www.mathworks.com/help/images/ref/hypercube.colorize.html for the case of hyperspectra (that in this case happens to have four channels)
DGM
2022 年 10 月 1 日
編集済み: DGM
2022 年 10 月 1 日
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1141825/image.png)
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)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1141830/image.png)
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!