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

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
Use this
[rows, cols, channels] = size(img)

댓글을 달려면 로그인하십시오.

 채택된 답변

Subhadeep Koley
Subhadeep Koley 2020년 2월 16일
편집: Subhadeep Koley 2020년 2월 16일

0 개 추천

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

mohammed alany
mohammed alany 2020년 2월 16일
still, i can't find the exact size of image
@ mohammed alany The below line should give you the size of the image
[rows, cols, channels] = size(img)
What you see when you are executing this line?
mohammed alany
mohammed alany 2020년 2월 17일
It shows the correct size, but after i saved the image, it has incorrect position of pixels
Subhadeep Koley
Subhadeep Koley 2020년 2월 17일
@ mohammed alany Where you are saving the image in workspace or in disk?
"it has incorrect position of pixels..." What values it is giving?
mohammed alany
mohammed alany 2020년 2월 17일
After plotting the polygons, I saved the figure and use it as input to another function, but the position of polygons isn’t in the exact location,
Image Analyst
Image Analyst 2020년 2월 17일
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 2020년 2월 17일
@image analyst @subhadeep koley Thanks for your reply, but can you please write me the exact code? What you mean by burn

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2020년 2월 16일

댓글:

2020년 2월 17일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by