简体   繁体   中英

Writing images using imwrite- Getting white images

I am writing a function that generates series of images. I am using the imwrite function to write each image to a file:

Ecc=sqrt(real(E(:,:,1)).^2+real(E(:,:,2)).^2+real(E(:,:,3)).^2+imag(E(:,:,1)).^2+imag(E(:,:,2)).^2+imag(E(:,:,3)).^2);
clf

Q=imagesc(nx/rad,ny/rad,Ecc); 
    if i==1
    cl=caxis;
    else
    caxis(cl)
    end
imwrite(Q,['Frame-',num2str(i),'.tif'],'tif');

But I am not getting the images. The files are generated just fine, but they are just white images with dimension 1x1. Any help please? Thank you

Use imwrite on Ecc instead of Q . The output of imagesc (as I recall) is a handle to the figure, which is not what you want to write out. Write out Ecc instead.

Adding to what user3817401 has written.

Completly white images can result from data not being scaled prior to being sent to imwrite. Consider following:

Ecc = (Ecc - min(min(Ecc))) / (max(max(Ecc)) - min(min(Ecc)));

promply before imwrite. This will guarantee, that the image is in range 0-1 and should solve the problem.

The function imagesc returns a handle (you store it as Q), not scaled image data. Then, the function imwrite is interpreting Q as an image. Because it is a handle, it is just 1x1 and it's value is not meaningful as an image. Try scaling Ecc as desired and then writing that instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM