MATLAB: Saving a true color image

true color image

I created a true color image using values for RGB:
R = 1;
G = 0.3301;
B = 0.9;
truecolor_image = cat(3, R, G, B);
filt_image = image(truecolor_image);
Now when I try to have Matlab save this image:
imwrite(filt_image, 'Filter Color.png');
All I get is a blank white pixel. Even after re-sizing to a 300 by 300 pixel image, the figure is still white and blank. How do I save this color image?

Best Answer

When you are calling image it returns a handle, which is a float value that you can use to modify the image in the plot window after you display it. For instance
handl = image(truecolor_image)
set(handl, 'cdata', 200)
What you are doing is writing this handle, which is a float, to a file. You want to write the actual matrix to the file. So, it is sufficient to write:
imwrite(truecolor_image, 'Filter Color.png');
Related Question