Pergunta

can anyone help me to save my resulted images by using imwrite

source = 'C:\Y\';
im_number=5; 
for i=1:5 
 image{i}=im2double(imread([source,'Carbon_', num2str(i)],'tif'));  
 image{i}=double(image{i});
 B{i}= Sftfun(image{i});
 B{i}=uint32(B{i});
 imwrite(B{i},[source,'face_', num2str(i)],'tif');
end
Foi útil?

Solução

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:

  1. Do not save your images to a cell array called image. MATLAB has a built-in command called image which takes in a matrix and displays it to the screen for you as an image. Bear in mind this is not the same as imshow. By doing this assignment, you will shadow over the actual image command, and so any scripts that rely on this function will result in an error.
  2. 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.
  3. 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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top