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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by