MATLAB Answers

How do I convert a figure directly into an image matrix in MATLAB 7.6 (R2008a)?

547 views (last 30 days)
I have a figure with a plot created using the following code:
mesh(peaks(50));
I would like to convert the figure into an image within MATLAB without having to first print it to a file and read it back into MATLAB.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 19 Dec 2018
A figure can be converted into an image using the GETFRAME and FRAME2IM functions in MATLAB. For example, the following code creates a snapshot of the current figure and writes it to an image in variable "X" with colormap stored in "Map":
F = getframe(gcf);
[X, Map] = frame2im(F);
If the frame contains true-color data, then "Map" will be an empty matrix.
For more information on the GETFRAME and FRAME2IM functions, consult the documentation by executing the following at the MATLAB prompt:
doc getframe
doc frame2im

  1 Comment

Mohammad Bhat
Mohammad Bhat on 23 Feb 2018
It gets converted into equal information I mean to say all pixels have same information

Sign in to comment.

More Answers (1)

Leslie Solorzano
Leslie Solorzano on 16 Dec 2016
https://se.mathworks.com/help/matlab/ref/frame2im.html

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2008a

Translated by