I want to convert an image to dimension MxNx3 from MxNx4.
2 views (last 30 days)
Show older comments
For the tif image of size 289 x 289 x 4 I am not able to perform any operations such as imadjust, gray thresh etc. I am able to perform all these operations on other image with 256*256*3.
Need a way to do covert
3 Comments
Accepted Answer
DGM
on 22 Sep 2024
If you have a TIFF file, from which imread() returns a 4-channel image, then it's ostensibly a CMYK image.
If the image is legitimately a CMYK image, you can convert to sRGB or whatever colorspace using applycform(). Assuming the TIFF file contains an embedded color profile:
unzip peptiffs.zip % tiffs need to be zipped for the forum
% assuming the file has an embedded profile
iccin = iccread('pep_cmyk.tif'); % this profile is in the TIFF
iccout = iccread('sRGB.icm'); % the destination profile is part of IPT
% read the file
inpict = imread('pep_cmyk.tif');
% convert to sRGB
C = makecform('icc',iccin,iccout);
outpict = applycform(inpict,C);
imshow(outpict)
If the file does not have an embedded profile, you can use iccfind() or whatever profile you want to presume as the source profile.
Just because the file is apparently CMYK doesn't mean that's what's actually stored in it. If imwrite() is ever given a 4-channel image with a destination format of TIFF, it will write it as CMYK regardless of what those four channels mean in concept. I know I've seen "CMYK" TIFFs which were clearly not CMYK. I've created plenty which were RGBA.
inpict = imread('pep_rgba-as-cmyk.tif');
% split the image from RGBA to RGB+A
alpha = inpict(:,:,4);
inpict = inpict(:,:,1:3);
% imshow() doesn't mat transparent images
% but you can just compose the image with the axes background
hi = imshow(inpict);
hi.AlphaData = alpha;
0 Comments
More Answers (0)
See Also
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!