Error saving PDF containing two images

1 visualización (últimos 30 días)
Lluis Roca
Lluis Roca el 6 de Mayo de 2020
Comentada: Lluis Roca el 7 de Mayo de 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

Respuesta aceptada

Rahul Singhal
Rahul Singhal el 7 de Mayo de 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
  1 comentario
Lluis Roca
Lluis Roca el 7 de Mayo de 2020
Thanks. Maybe add it to new release wishlist

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by