MATLAB: Changing the output of the imread() function

image processingimread

When I use the imread function on a .tif file that I have done some processing with (specifically imagesc and export_fig to save it) it reads as a 640x480x3 matrix because it is seeing it as a truecolor image. Is there any way to have imread output it in a different way? I would like to have it be a 640×480 matrix if possible. If I need to provide anymore information let me know. Thanks in advance.

Best Answer

Hey Seth,
Could you just use rgb2gray on the output of imread?
I = imread('mytiff.tif');
if size(I,3) == 3
I = rgb2gray(I);
end
Or if you'd like to retain the colors, but still keep the image as 640x480 for some reason, you could use rgb2ind to create an indexed image. You'll need to store the map output as well though to maintain color information.
-Cam
Related Question