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
댓글 수: 3
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Filtering and Enhancement에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!