Matlab Extract images from a subplot in .fig format

2 visualizaciones (últimos 30 días)
Chanda Simfukwe
Chanda Simfukwe el 15 de Sept. de 2021
Comentada: Chanda Simfukwe el 15 de Sept. de 2021
How can I extract images from a subplot figure. fig?
Here is the fig file drive.google.com/file/d/1fSPaYYgZBPQy0pt6Oml36NoAOEqvsWIu/… and the fig of interest is drive.google.com/file/d/1z1Tf3fyONbB0aDxX8P5r17VOV9ltCYbo/… I want to save the fig of interest into a png file. I am not very familiar with subplots just a beginner in Matlab coding thanks.
I tried with this code but it didn't give me the output I needed.
fig = openfig( 'IC_01.fig' , 'new' , 'invisible' );
imgs = findobj(fig, 'type' , 'image' );
thiscmap = get(fig, 'colormap' );
for K = 1 : length(imgs)
thisimg = get(imgs(K), 'CData' );
% now do something with it for illustration purposes
thisfilename = sprintf( 'extracted_image_%03d.jpg' , K);
imwrite(thisimg, thiscmap, thisfilename);
end
Thank You.
  2 comentarios
Image Analyst
Image Analyst el 15 de Sept. de 2021
Try getimage() to get the image in the axes
imageInTheAxes = getimage(handleToAxes);
Chanda Simfukwe
Chanda Simfukwe el 15 de Sept. de 2021
Thanks a lot for the help, it worked very well.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 15 de Sept. de 2021
fig = openfig( 'IC_01.fig' , 'new' , 'invisible' );
imgs = findobj(fig, 'type' , 'image' );
im_wanted = imgs(4);
ax = im_wanted.Parent;
thisimage = im_wanted.CData;
thiscmap = ax.Colormap;
imwrite(thisimage, thiscmap, 'extracted_image.jpg');

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by