Convert grayscale CMYK to RGB

21 次查看(过去 30 天)
I have some images of fish scales that are CMYK gray that I would like to convert to RGB. They read in as a m x n x 4 sheet array with imread. They do not have a color profile, using iccread on them returns an error ('No Icc profile found in TIFF file'). The original looks like this:
When I try to convert with the following:
im=imread('example_img.TIF');
C = makecform('cmyk2srgb')
im2=applycform(im,C);
It returns a m x n x 3 sheet array, but when I look at it in imshow (or write to a file) the color is wrong (it is way too dark):
Some of the features are visible, but the background is wonky. I've checked, it's not just that it's inverted (i.e. imcomplement doesn't fix it). I have tried many color profiles (reading in with iccread), like so:
inprof = iccread('BlackWhite.icc');
outprof = iccread('sRGB.icm');
C = makecform('icc',inprof,outprof);
im2=applycform(im,C);
but none result in an appropriate looking image. Does anyone have any ideas? I have attached the example image.

采纳的回答

Guillaume
Guillaume 2020-2-13
I have some images of fish scales that are CMYK gray
Not according to the metadata:
>> imfinfo('example_img.TIF')
ans =
struct with fields:
[..] %fields elided for brevity
ColorType: 'truecolor'
[..]
PhotometricInterpretation: 'RGB'
StripOffsets: [1×4426 double]
SamplesPerPixel: 4
[..]
ExtraSamples: 2
It's a RGB image with 4 samples per pixel which is indeed one too many but ExtraSamples of 2 tells you that the extra channel is (unnassociated) alpha data.
So, you can display your image as is just using the first 3 channels. Optionally, you can use the 4th channel to add some transparency to your image but considering that the transparency is all 255, it's not going to change anything.
img = imread('example_img.TIF');
himg = imshow(img(:, :, 1:3)); %display RGB values
himg.AlphaData = im2double(img(:, :, 4)); %add transparency but every pixel is fully opaque anyway
  1 个评论
Rob Campbell
Rob Campbell 2020-2-15
Aha! Thanks! I did not know that the alpha data might be encoded in there.
Cheers, Rob

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by