MATLAB: How to save image

digital image processingimage processingImage Processing Toolboxsave image

I have a set of image data which is 256×256 matrix. I display the image data using the code below;
load topomatrix;
figure;
imshow(topomatrix,'displayrange',[]);
colormap('jet');
Now, I want to save the image with full display range and colormap, anyone know how to do it, is it using IMWRITE?
imwrite(topomatrix, 'topo.jpg');
Does anyone know how to do it, thank in advance!!!

Best Answer

You'll need to scale it and convert it to an 8 bit RGB image.
image8Bit = uint8(255 * mat2gray(topomatrix));
jetMap = jet(256);
imshow(image8bit);
colormap(jetMap);
rgbImageToSave = ind2rgb(image8Bit, jetMap);
imwrite(rgbImageToSave, 'rgbImage.png'); % Save as PNG to avoid jpeg artifacts.