Saving a montage image

36 ビュー (過去 30 日間)
Janhavi Srirangaraj
Janhavi Srirangaraj 2019 年 4 月 26 日
コメント済み: Koosha 2022 年 1 月 23 日
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.

採用された回答

Rik
Rik 2019 年 4 月 27 日
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 件のコメント
Rik
Rik 2020 年 9 月 9 日
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 2022 年 1 月 23 日
Thank u soooo much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by