Saving a montage image

36 visualizaciones (últimos 30 días)
Janhavi Srirangaraj
Janhavi Srirangaraj el 26 de Abr. de 2019
Comentada: Koosha el 23 de En. de 2022
I created a montage of an RGB and logical image and stored t into a variable 'h'. The content of the variable 'h' is of the type 'image'. I would like to save 'h' into a folder. I have tried to use saveas and imwrite but I am unable to do so. My code and the resulting errors are as follows. How can I save the image in variable 'h'?
ImFileOut = fullfile(ImOutFolder, ImName)
ImCell = {RGBIm, LogicalIm};
h = montage(ImCell); %file type is '1x1 Image'
saveas(h,ImFileOut);
% Error using saveas
% Invalid handle.
imwrite(h,ImFileOut);
%Error using imwrite (line 427)
%Expected DATA to be one of these types:
%numeric, logical
%Instead its type was matlab.graphics.primitive.Image.

Respuesta aceptada

Rik
Rik el 27 de Abr. de 2019
There is a difference between an image and an image object. The latter is a graphics object that is shown in the axes. It does contain the data required to write the montage to an image. The code below generates some example data and then writes a montage to a file. You can adapt it to suit your specific needs.
%generate required variables
ImOutFolder=pwd;
ImName='example_montage.png';
RGBIm=randi(127,100,100,3,'uint8');
LogicalIm=logical(randi([0 1],100,100));
%compose inputs
ImFileOut = fullfile(ImOutFolder, ImName);
ImCell = {RGBIm, LogicalIm};
%create montage and extract color data from the image object
figure(1),clf(1)%create a clean figure (use clf only in debugging)
h=montage(ImCell);
montage_IM=h.CData;
%write to file
imwrite(montage_IM,ImFileOut);
  4 comentarios
Rik
Rik el 9 de Sept. de 2020
The CData property is in the doc: on the page with properties of image objects.
If you want to hide things in a loop you have two options: open a figure at the beginning and set Visible to off. Then use explicit handles when calling montage. The other option is to reimplement montage yourself, which is what I did myself.
Koosha
Koosha el 23 de En. de 2022
Thank u soooo much.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by