The problem with your code is that you are casting your image to uint32
. If you are trying to save your image as a TIF
file, you can only save it as 8-bit or 16-bit. Consulting the MATLAB documentation, you can only save with these two bit depths. 32-bit depths are not supported.
Consult the MATLAB documentation for more details: http://www.mathworks.com/help/matlab/ref/imwrite.html
As such, either cast the image as 8-bit or 16-bit (through im2uint8
or im2uint16
), or normalize your image so that it goes from [0,1]
(through im2double
).
I also have some comments about your code that do need fixing for readability:
- Do not save your images to a cell array called
image
. MATLAB has a built-in command calledimage
which takes in a matrix and displays it to the screen for you as an image. Bear in mind this is not the same asimshow
. By doing this assignment, you will shadow over the actualimage
command, and so any scripts that rely on this function will result in an error. im_number
seems to be an unused variable. I'm not sure what its purpose is, but I'd say it's safe to remove this statement as well.- Get rid of the following statement as you are already converting the image to a
double
type in the previous line:
image{i} = double(image{i});
Aside
It seems that you have asked a similar question here: save tif 32 bit images by using imwrite
This question has already been resolved in that you are not able to save 32-bit images using imwrite
. However, someone in this thread has posted a workaround for you to use in MATLAB. Try using that instead of imwrite
.