Error saving PDF containing two images

4 views (last 30 days)
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?
function ButtonPushed(app, event)
import mlreportgen.dom.*;
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}];

Accepted Answer

Rahul Singhal
Rahul Singhal on 7 May 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');
  1 Comment
Lluis Roca
Lluis Roca on 7 May 2020
Thanks. Maybe add it to new release wishlist

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!