Error saving PDF containing two images

1 Ansicht (letzte 30 Tage)
Lluis Roca
Lluis Roca am 6 Mai 2020
Kommentiert: Lluis Roca am 7 Mai 2020
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

Akzeptierte Antwort

Rahul Singhal
Rahul Singhal am 7 Mai 2020
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

Weitere Antworten (0)

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by