MATLAB: Problem with saving a data file as image

empty imageimwrite

Whenever I use imwrite to save a data as a png/bmp/jepg file, the result file is always an empty image. Whereas, in imshow the image is there. Where could be the problem?
I am using Windows 7 OS with R2014a MATLAB
Kindly give me a solution.

Best Answer

It's probably a floating point image. Cast to uint8 and then try it
uint8Image = uint8(255 * mat2gray(yourImage));
imwrite(uint8Image, filename);
Related Question