How to store figure as image matrix with specific resolution

16 Ansichten (letzte 30 Tage)
Brayden Albery
Brayden Albery am 11 Aug. 2020
Kommentiert: Walter Roberson am 12 Aug. 2020
I have a plot on a figure that I want to store in the Workspace as a grayscale image matrix with a specific number of rows and columns (corrisponding to pixel resolution). For example, storing the figure as 2080x2080 matrix. I have tried using getframe but it changes the size of the image and has poor picture quality when creating detailed plots. Using imresize after getframe moves the position of the plot and leaves a large white space in the corner. I have avoided saving images because i want to use a large amount of images later in the code as in a loop and my computer sometimes blue screens when saving images.
The first image is the figure I want; the second image is after using getframe; and the thrid image is after using imresize.
here's the code i used to capture the figure:
frame = getframe
gray = rgb2gray(frame2im(frame));
gray = imresize(gray,[image_size,image_size])

Antworten (1)

Walter Roberson
Walter Roberson am 11 Aug. 2020
One approach is to print() using the -r (resolution) option
The image you show has no axes markings or similar. I wonder if it would be better for your purpose to use Computer Vision Toolbox to insertShape() to effectively render into a buffer ?
  2 Kommentare
Brayden Albery
Brayden Albery am 12 Aug. 2020
The reason I'm doing it this way is because I'm also generating much more complicated plots and comparing the pixel values of those images with this one. getframe limits the maximum resolution I can get on the images which loses a lot of the detail, and doesn't give me any control over the size of the image. I'm trying with insertShape now.
Is there no way to convert a figure straight into a n x m matrix?
Walter Roberson
Walter Roberson am 12 Aug. 2020
Unfortunately at this time there is no way to convert graphic objects straight into a matrix without using getframe() or equivalent that probably lose resolution.
What is new is that R2020a has exportgraphics() https://www.mathworks.com/help/matlab/ref/exportgraphics.html that permits saving in vector format, and has copygraphics() https://www.mathworks.com/help/matlab/ref/copygraphics.html to copy to the system clipboard. Those might not help you... though it just might be the case that you could find something that could take a system clipboard and render it at higher resolution ?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Printing and Saving finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by