MATLAB Answers

save the output figure as binary image

22 views (last 30 days)
i am plotting rectangle like in the code bellow,
rectangle('Position',[96 539-450 214 161], 'FaceColor',[0 .5 .5])
axis([0 559 0 539])
i want to save the output figure as binary image "in workspace" without border and exact area.
as a result the binary image must be like 559x539
any help?

  2 Comments

mohammed alany
mohammed alany on 16 Feb 2020
Thanks dear,
but if plot without putting the axis like bellow
rectangle('Position',[96 539-450 214 161], 'FaceColor',[0 .5 .5])
How i can find the exact size of saved image
Subhadeep Koley
Subhadeep Koley on 16 Feb 2020
Use this
[rows, cols, channels] = size(img)

Sign in to comment.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 16 Feb 2020
Edited: Subhadeep Koley on 16 Feb 2020
The below code will save the figure as an image in the worksapce.
clc; close all;
rectangle('Position',[0 0 539 539], 'FaceColor',[0 .5 .5],...
'LineStyle', 'none');
axis tight; axis off;
frm = getframe(gcf);
img = frame2im(frm);
img = imresize(img, [539, 539], 'bicubic');
figure; imshow(img);
But, if you convert the image to binary (as you stated in your question) then all the color information (which you added using FaceColor) will be lost. And the image will become a black blob.

  8 Comments

Show 5 older comments
Image Analyst
Image Analyst on 17 Feb 2020
getframe is basically a bitmapped screenshot, so the polygon's won't have the original coordinates since it depends on how you scaled the figure on your display. If you want actual pixels, then you need to burn in the graphics and use imwrite().
mohammed alany
mohammed alany on 17 Feb 2020
@image analyst @subhadeep koley Thanks for your reply, but can you please write me the exact code? What you mean by burn

Sign in to comment.

More Answers (0)


Translated by