How can I display images from image names in a matrix?

1 次查看(过去 30 天)
Hello,
I'm reading image names into MATLAB from an excel file, and I'd like MATLAB to display the images associated with those image names, but I keep getting error messages when I try to use imread or imshow. All of the image names within the matrix are written as imagename.jpg and the image file is in the same folder as the saved MATLAB code, but I keep getting error messages for syntax.
I'm reading the image files into the matrix, and then trying to create the new variable images, so I can easily call them to display later.
[numbers,imagenames]=xlsread('filename.xlsx')
images=imread(imagenames) %syntax error
images(1:total)=imread(imagenames(1:total)) %syntax error
If someone could please explain how to do this properly I would really appreciate it!
Thank you.

回答(2 个)

Image Analyst
Image Analyst 2016-7-31
If you want to see all of them at once, in one image, use montage
montage(imagenames);
If you want to see them all in separate figures, you can use subplot and put them in a loop
for k = 1 : length(imagenames)
thisName = imagenames{k};
figure;
imshow(thisName);
end
If imagenames does not include the folder, then you may have to prepend the folder with fullfile().
thisName = fullfile(folder, imagenames{k});

Azzi Abdelmalek
Azzi Abdelmalek 2016-7-31
[numbers,imagenames]=xlsread('filename.xlsx')
for k=1:numel(imagenames)
images{k}=imread(imagenames{k})
end
  4 个评论
Uthara Hari
Uthara Hari 2020-12-31
Hi Amanda, just found an answer to the error: add the image folder to path, and then the code would be able to read all images.
Image Analyst
Image Analyst 2020-12-31
But she said "the image file is in the same folder as the saved MATLAB code" so adding the folder name would not be needed in that situation, though I agree it's always best to add it for completeness and robustness.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by