MATLAB Answers

How to save imshowpair figure using imwrite?

26 views (last 30 days)
Kirsty Bennett
Kirsty Bennett on 31 Jan 2020
Commented: Kirsty Bennett on 20 Feb 2020
How would I save the following as a binary image? I want to use imwrite, or be able to save it as a variable in the workspace so that I can use bwskel.
registered = imregister(Moving,Fixed,'Similarity',optimizer,metric);
figure
A = imshowpair(registered,Fixed);

  0 Comments

Sign in to comment.

Answers (2)

Guillaume
Guillaume on 6 Feb 2020
No, no, no, don't use print or saveas, this is possibly going to rescale your image, change the the colour depth, etc.
A simpler and reliable way is to use imfuse instead of imshowpair. imshowpair is for displaying a pair, imfuse is for creating an image of the pair. In any other way, they work exactly the same and have the same options
registered = imregister(Moving,Fixed,'Similarity',optimizer,metric);
fusedpair = imfused(registered, Fixed);
imwrite(fusedpair, 'somefile.png');

  2 Comments

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 7 Feb 2020
Thanks @Guillaume, this is clearly a better approach.
Kirsty Bennett
Kirsty Bennett on 20 Feb 2020
Thank you so much!! Literally saved me today :D

Sign in to comment.


Vinai Datta Thatiparthi
Vinai Datta Thatiparthi on 4 Feb 2020
Hey Kirsty,
Since imshowpair returns class matlab.graphics.primitive.Image, imwrite cannot be used directly. Instead, you can use the functions -
saveas(gcf, 'savedImage.jpeg', 'jpeg');
print(gcf, '-djpeg', 'savedImage.jpeg', '-r0'); % Print allows you to specify the resolution
% at which you want to save the image
Hope this helps!

  1 Comment

Kirsty Bennett
Kirsty Bennett on 6 Feb 2020
Thank you Vinai. I'll use the saveas function :)

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019a