Error saving PDF containing two images

1 回表示 (過去 30 日間)
Lluis Roca
Lluis Roca 2020 年 5 月 6 日
コメント済み: Lluis Roca 2020 年 5 月 7 日
I have a button that its aim is to save an image and its threshold version. When I run the code below, I get this error?
Error using mlreportgen.dom.Image
Invalid input for argument 1 (p0):
Value must be a character vector or string scalar.
How can I generate a report that include both of the images?
Code:
function ButtonPushed(app, event)
import mlreportgen.dom.*;
import mlreportgen.report.*
folder = 'E:/';
file = 'sh2.png'
fullFileName = fullfile(folder, file);
I= imread(fullFileName);
level = graythresh(I);
BW = imbinarize(I,level);
filter = {'*.pdf'};
[file, pathPDF] = uiputfile([folder,filter{1}])
if file ~= 0
d = Document('myPDF','pdf');
d.OutputPath = [pathPDF,file];
img1 = Image(fullFileName);
img1.Style = [img1.Style {ScaleToFit}];
img2 = Image(BW);
img2.Style = [img2.Style {ScaleToFit}];
append(d,img1);
append(d,img2);
close(d);
end

採用された回答

Rahul Singhal
Rahul Singhal 2020 年 5 月 7 日
Hi Lluis,
The error occurs at line:
img2 = Image(BW);
Error occurs because mlreportgen.dom.Image does not accept binary image as input but only accepts path of an image file.
You can first write the binary image to an output image file using imwrite and then use the generated image file path to create the DOM Image. For e.g.,
>> imwrite(BW, 'sample.png');
>> img2 = Image('sample.png');
Thanks,
Rahul
  1 件のコメント
Lluis Roca
Lluis Roca 2020 年 5 月 7 日
Thanks. Maybe add it to new release wishlist

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by