MATLAB Answers

0

Saving Figure Data into a Matrix

Royi Avital 님이 질문을 제출함. 4 Jul 2011
최근 활동 xinyue L 님이 댓글을 추가함. 14 Aug 2019
Hello.
I'm using 'image()' to display an image. I'm adding some annotations using text.
I'd like to save the final result as matrix (3 Channels of the displayed image width and height). Something like using: OI = get(imageHandler, 'CData'); Yet which includes all the annotations I added.
I know I can use 'saveas' and 'print' yet then the data undergoes some interpolation while I want the data as it is back as a matrix.
Anyone knows how to do it?
Thanks.

  댓글 수: 1

Great question!

로그인 to comment.

태그

제품

답변 수: 2

Answer by Gerd
on 4 Jul 2011
 Accepted Answer

Hi Royi,
you can use the getframe command.
logo = imread('Logo.jpg','jpg');
image(logo);
text(20,30,'Hello')
f=getframe(gcf)
new=f.cdata
imwrite(new,'new.jpg','JPEG')
Gerd

  댓글 수: 3

Hello Gerd.
Well, it's almost perfect.
Let's say I is a 250 by 250 pixels image.
I use 'image' to display it.
I add annotations on the image itself.
Using 'getframe' I get a matrix which is much bigger than 250 x 250.
I want to get back not the whole figure (As in 'saveas') but only the image itself with all the annotations.
Thanks.
xinyue L on 14 Aug 2019
I met the same question.Have you solved this problem? Looking forward to your answer.
xinyue L on 14 Aug 2019
I solved this problem just now.
You can try gca command.It returns the current figure or image.
Example:
Frame = getframe(gca);
FrameData = Frame.cdata;
imshow(FrameData)
imwrite(FrameData,'teat.png','PNG');

로그인 to comment.


Answer by Leslie Solorzano on 16 Dec 2016

https://se.mathworks.com/help/matlab/ref/frame2im.html

  댓글 수: 0

로그인 to comment.



Translated by