How to store figure as image matrix with specific resolution
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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])
0 Kommentare
Antworten (1)
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
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.
I made a suggestion nearly a decade ago... https://www.mathworks.com/matlabcentral/answers/1325-what-is-missing-from-matlab#answer_1913
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 ?
Siehe auch
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!