Convert grayscale CMYK to RGB

조회 수: 21 (최근 30일)
Rob Campbell
Rob Campbell 2020년 2월 13일
댓글: Rob Campbell 2020년 2월 15일
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