Access image metadata using imfinfo() method call on an imageDatastore() object
2 views (last 30 days)
Show older comments
I am writing a script that reads a table of timeseries data and plots the data then animates the plots by stepping through the data for each timestamp displaying a red dot and the value on the plots. This part is OK so i havent shown any code from here.
Additionally (and the part im struggling with) I have photos that I would like to display as the animation reaches the corresponding timestamp of the photo.
Is it NOT possible to call imfinfo() on an imageDatastore() file? Ive read the input arguements section but still not sure in Information about graphics file - MATLAB imfinfo - MathWorks Australia
Code and error message for calling imfinfo() on an imageDatastore() file below:
%Create a Datastore of the 10 images
imds = imageDatastore("C:\Users\edavidson\Documents\MATLAB\Sandbox\Photo");
%Iterate through imds, read the DateTime value using imfinfo() and diplay
%image if the image DateTTime value matches the current DateTime value,
%then stop the for loop.
for i = 1:10
img = readimage(imds,i);
info = imfinfo('img');
if info.DateTime == '2022:05:20 07:00:03' %<--hardcoded datetime value matching a specifc image for the concept
imshow(img);
break;
end
end
Error message:
>> PhotoPlot
Error using imfinfo (line 142)
Unable to open file "img" for reading.
Error in PhotoPlot (line 14)
info = imfinfo('img');
Thanks
0 Comments
Answers (1)
Sourav Karmakar
on 13 Oct 2022
Hi Ed,
The "imfinfo" function takes 'filename' as an input and returns a structure whose fields contain information about the image(i.e. the graphics file, 'filename').
Here, in the attached code you are passing the image array data(stored in variable 'img') instead of the filename, and that's why the error occured. To resolve this issue, you have to perform the below modifications:
%Create a Datastore of the 10 images
imds = imageDatastore("C:\Users\edavidson\Documents\MATLAB\Sandbox\Photo");
%Iterate through imds, read the DateTime value using imfinfo() and diplay
%image if the image DateTTime value matches the current DateTime value,
%then stop the for loop.
for i = 1:10
% I've added two ways to pass the filename, use either one
% 1st option
[img, fileinfo] = readimage(imds,i);
info = imfinfo(fileinfo.Filename);
% 2nd option
info = imfinfo(imds.Files{i});
if info.DateTime == '2022:05:20 07:00:03' %<--hardcoded datetime value matching a specifc image for the concept
imshow(img);
break;
end
end
0 Comments
See Also
Categories
Find more on Read, Write, and Modify Image in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!