I want to convert an image to dimension MxNx3 from MxNx4.

2 次查看(过去 30 天)
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

采纳的回答

DGM
DGM 2024-9-22
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 个)

类别

Help CenterFile Exchange 中查找有关 Image Filtering and Enhancement 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by