How to convert image .mat back to the mlreportgen.dom.Image object?

조회 수: 2 (최근 30일)
John
John 2021년 1월 5일
편집: John 2021년 1월 19일
In report generator, an Image object can be inserted in the report in this way:
mlreportgen.dom.*
rpt = Document('my_report','pdf');
img = Image('my_image.jpg');
img.Style = {Width('5in'),HAlign('center')};
append(rpt, img);
Now, the image is already read into .mat data with:
read_img = imread('my_image.jpg'); % now, read_img is in 640x480x3 uint8 format
How to create an Image object as above but from this later read_img data?
img = Image(anyway_some_function(read_img));

채택된 답변

Sean de Wolski
Sean de Wolski 2021년 1월 19일
You'll need to write the image back to disk as the report generator needs to deserialize it from this format into the report. If the image is in a figure, you can use print, exportgraphics or use my FigureDeployer class which wraps around it and makes it easy.
Alternatively, you could use the Figure command with the mlreportgen.report.* api but this would require changing other things about your reporter structure.
  댓글 수: 1
John
John 2021년 1월 19일
편집: John 2021년 1월 19일
I thought it wasn't beautiful, but did in the same way as yours.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Nitin Kapgate
Nitin Kapgate 2021년 1월 13일
You can create an Image Object from the "read_img" data using the following code:
read_img = imread('my_image.jpg'); % Read the image
img = image(read_img);
You can refer to the documentation of "image" function to learn more about it.
  댓글 수: 1
John
John 2021년 1월 19일
This doesn't resolve the issue:
import mlreportgen.dom.*
read_img = imread('my_image.jpg');
img = image(read_img); % this runs, but forces an image display
report_image = Image(img); % this still give error below
What we want is an mlreportgen.dom.Image object. Above command generates the error:
Error using mlreportgen.dom.Image
Invalid input for argument 1 (p0):
Value must be a character vector or string scalar.
Error in Untitled (line 4)
report_image = Image(img);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by