Convert figure to image within the workspace?

48 visualizzazioni (ultimi 30 giorni)
Ryan
Ryan il 30 Lug 2012
Risposto: Gerard Knijnenburg il 19 Feb 2021
Hi all,
I am writing a plot tool that will be used to import data, generate plots, and then save those plots as .png files.
Prior to saving the plots, I would like to rotate the entire image 90 degrees (for printing reasons). Right now the only way I've figured out how to do this is to use the print function to save the current figure, then re-open that file as an image, rotate it, and re-save it again.
This works fine, but isn't exactly efficient (I need to create over 2,000 plots). Does anyone know a way to convert the figure to an image object within the workspace (ie without having to save and then re-open it)?
Here's what I have so far:
print(f_handle, '-dpng', file_name);
img = imread(file_name,'png');
img = imrotate(img,-90);
imwrite(img,file_name);
Thanks! Ryan

Risposte (2)

Jan
Jan il 31 Lug 2012
Modificato: Jan il 31 Lug 2012
See the orient command.
This command is mentioned in the "See also" line of "help print".

Gerard Knijnenburg
Gerard Knijnenburg il 19 Feb 2021
Hi Ryan or Anyone that found this question.
Use:
Workspace_Image = print('-RGBImage');
This will save the current active plot/figure as an image file in your workspace.
Best Regards
Gerard

Categorie

Scopri di più su Convert Image Type in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by