How can i change the "name" of my picture when using the imread('name') function?

4 次查看(过去 30 天)
What i want to do is have a loop go through and read the name of every picture i have.
What i can't do is change the 'Name'(of the image) in a function like imread('Name') in the following way. (i believe this is because 'Name' is interpreted as a string)
(also the names of my pictures are integer values already)
for i = 1:n
image = imread('NameOfMyImage');
end % code

采纳的回答

Christiaan
Christiaan 2015-4-2
Dear Ely,
To import an image in MATLAB, you have to specify the extension. (i.e. Name.jpg)
In the code below you find a method how you can dynamically load multiple images in MATLAB with a for loop and give them the correct name. In the example is assumed you have JPG images. However you can extend the example yourself to also load PNG images. (for this example you need three images: Name_1.jpg, Name_2.jpg and Name_3.jpg.
clc;clear;close all;
% this is how you create a string in a for loop
for i = 1:3
name_of_the_file = sprintf('Name_%d.jpg', i)
name_of_the_image = sprintf('Name_%d', i)
image = imread(name_of_the_file);
assignin('base',name_of_the_image,image);
clear image name_of_the_file name_of_the_image i
end
Good luck! Christiaan

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by