Specify Path for Image in Report Generator

I have a pdf generated via MatLab Report Generator. I have a few remaining issues. I have spent days trying to resolve via search of this and other forums.
I am posting each issue individually.
This issue. Specify Path for Image in Report Generator
The following line is used in an Example Report. This works and finds the image in the local directory or in a directory via the addpath function.
img1 = Image(which('ngc6543a.jpg'));
Unfortunately, I will be supplied an Excel sheet which will supply a list of images with the full image path. There may be hundreds of images and directories in the list (and the database has more than 500,000 images). I am comfortable splitting the path and filename into different variables.
Simplified file list:
'C:\Dir1\ngc6543a.jpg'
'G:\Dir2\ngc6543a.jpg'
'S:\Dir1\SubDir\ngc6543a.jpg'
When I tried the following I always get an error.
img1 = Image(which('C:\Dir1\ngc6543a.jpg'));
Please help me use the correct syntax to include the full path, eg. 'C:\Dir1\ngc6543a.jpg'.
I do not believe it is feasible to keep adding the image 'path' to the system addpath function for such high volumes.
Also... if anyone could please post a link to the Image(which)) syntax. I cannot find it.

1 Comment

"Please help me use the correct syntax to include the full path, eg. 'C:\Dir1\ngc6543a.jpg'."
img1 = Image('C:\Dir1\ngc6543a.jpg'); % get rid of WHICH()

Sign in to comment.

Answers (1)

I don't know what "Image" is. Is that your own function or a special function for the Report Generator? It's not the built-in image function because MATLAB is case sensitive.
And what's the point of using which()?
Since you already seem to have the filenames in a cell array or table because you read them in from Excel, why not simply use the index of the one you want?
[numbers, fileNames, raw] = xlsread(workbookName);
img1 = Image(fileNames{3}); % Use filename #3.

12 Comments

I am comfortable extracting path and filename components from Excel or any other source.
What I struggle with is that the following line is an example supplied by Matlab and I can only assume Image and which() are functions available via the Report Generator extensions / object model.
img1 = Image(which('ngc6543a.jpg'));
This line works when the image is in the local directory, but does not work when I try to use the full path.
Also.... I cannot find any documentation for Image or Which.
Here is a link to the worked example, placing 2 images on a pdf page..
I can see the potential of MatLab Report Generator .... but it is challlenging for me to get my prototype working. I have it now 99% there ... but the inability for me to include an image without first having to move it to the local folder, or add hundreds of paths to the default paths parameter, is a major limitation of adopting Report Generator more extensively.
Image seems to be a function you get when you do the "import" commands. But I can't find any documentation for it. Evidently they're calling which() to get the full path and name of the image file. They're assuming it's on the search path somewhere but that you just want to pass in the base file name for some reason. I believe you could pass in the full filename directly if you have it, just like I showed you already. Does that not work? Did you look over all files and use isfile to see if the file actually exists before you try to use it? If you still have trouble, attach your workbook, or filenames variable in a .mat file, so I can check it out.
Thanks for the prompt reply. I will send you listings when I get back to my Pc. 10 mins.
To answer your question....
Supplying the full path does not work. I will triple check again in the next few mins.
I have tried every combination, including placing the full path as a variable, using (f,p) format or (p,f) where p = path and f the filename.
I am horrified that the documentation is so poor for such a critical feature. I have spent 3 days trying to figure this out and only raised a ticket as a last resort.
I am also totally frustrated that all of the examples do not show how to use a full path and assume the image is in the local directory.
What time zone are you in?
I'm in Eastern US time zone. I'm surprised the full path name as a character array does not work since that is exactly what which() returns. Where is the documentation on Image (with a capital I not a lower case i)? I can't find it.
I have just realized the MatLab prototype app / script I have will not show the problem, as I have coded around the problem to advance other aspects of the report required.
I will do a simple example, based on the MatLab example, but attempt to open image files outside of the 'path' parameter.
I will post the listing and workbook etc... in probably an hour or two... Have to deal with a conference call in 10 mins here.
I cannot find it either.
Thank you for your interest.
This is really basic stuff and there is probably a simple reason why this is so problematic.
Here are two examples. The first (SideBySidePicsExampleV2.m) is based on the example at this link.
This works as expected.
The second (SideBySidePicsExampleV2.m) uses images on my V drive, which are not in a local directory or path parameter.
In SideBySidePicsExampleV2.m I have tested the existence of both files and they both pass.
I get this error message.
Error using mlreportgen.dom.Image
Invalid image type: .
Error in SideBySidePicsExampleV2 (line 33)
img1 = Image(which(ImageAndPath1));
Both Matlab scripts attached.
Stephen23
Stephen23 on 25 Nov 2022
Edited: Stephen23 on 25 Nov 2022
"I get this error message."
Why are you calling WHICH with a full path? The entire point of WHICH is to return the path of something that:
  1. is not a full path, and
  2. is on the MATLAB search path (the WHICH documentation makes this very clear: "If item is a file name including the extension, and it is in the current working folder or on the MATLAB path, then which displays the full path of item.")
If you already have the full path of something that is not on the MATLAB search path, then WHICH does absolutely nothing for you. Image Analyst pointed this out six hours ago, so it is unclear why you are still calling WHICH.
Get rid of WHICH.
"I can only assume Image and which() are functions available via the Report Generator extensions / object model."
Rather than assuming, finding the Image documentation took me ... eight seconds: I clicked on the link you posted, then clicked on "Functions" at the top of the page, then "Images, Figures, Axes..." in the Category browser, and then finally on "mlreportgen.dom.Image". There is no restriction on the image needing to be on the search path.
WHICH is a base MATLAB function, completely unrelated to Report Generator:
Thanks for your feedback.
  1. I cannot find any documentation for Which.
  2. I cannot find any documentation for Image.
Can anyone suggest what syntax I should use to be able to place an image on a Pdf, where the image is NOT on a local folder or in a folder defined by the Path parameter.
I would love to understand or see the syntax for Which and Image.
I will try img1 = Image('V:/TestDir/TestImg.jpg').
img1 = Image('V:/TestDir/TestImg.jpg')
This works ...
Thanks for getting me there.
If anyone can point me to the Documentation for 'Which' and 'Image' I would really appreciate it.
Regards.
I found the Which documentation. https://uk.mathworks.com/help/matlab/ref/which.html
The key was to add the word function to the search parameter.
Stephen23
Stephen23 on 25 Nov 2022
Edited: Stephen23 on 25 Nov 2022
"I cannot find any documentation for Which. I cannot find any documentation for Image."
I gave links to both of those in my previous comment, and I also explained the exact three clicks you need to find the Image documentation from the page you already were looking at. But here they are again:
I am sure that after three days reading about this topic you have already read the entire Report Generator documentation twice over, but perhaps someone else might find these screenshots useful:
"If anyone can point me to the Documentation for 'Which' and 'Image' I would really appreciate it."
Tip: practice using the documentation. Always look at what is displayed in the browser (LHS) and at the very top and bottom of every page. There is a lot of hyperlinking and a lot of information, so you have to keep your eyes open.

Sign in to comment.

Categories

Find more on Scripts in Help Center and File Exchange

Products

Release

R2022b

Tags

Asked:

on 25 Nov 2022

Edited:

on 25 Nov 2022

Community Treasure Hunt

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

Start Hunting!