문제

I have 500 images named Image1.tif all the way to Image500.tif and I need to convert all of them to grayscale and save them as Image1A.tif to Image500A.tif. Is there a quick way to do this? Thank you.

도움이 되었습니까?

해결책

If you have Image Processing Toolbox you can use RGB2GRAY function.

for k=1:500
    Ic=imread(['Image' num2str(k) '.tif']);
    Ig=rgb2gray(Ic);
    imwrite(Ig,['Image' num2str(k) 'A.tif'],'tif')
end

If you don't there is a solution here. Substitute rgb2gray line with:

Ig = 0.2989 * Ic(:,:,1) + 0.5870 * Ic(:,:,2) + 0.1140 * Ic(:,:,3); 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top