2012-02-15 58 views
0

我有使用imread命令由一个具有我想读从文件夹中一个循环图像的各种图像的文件夹,任何建议如何做到这一点的最佳 感谢读取图像一个

+0

告诉我们你已经什么试过。 – Oli 2012-02-15 20:41:49

+4

可能的重复[在MATLAB中加载多个图像](http://stackoverflow.com/questions/2408112/loading-multiple-images-in-matlab) – yuk 2012-02-15 20:57:52

回答

0

您必须同步您的图像名称才能在循环中读取。他们必须像image1.jpg,image2.jpg,image3.jpg ...你有10个像这样的图像。

NumberOfimages=10;  %chose the number of images you want to give input 
prefix_image='image'; %change the desired input image name here only 
fileformat='.jpg';  %change the desired input image format here only 

for num=1:NumberOfimages 
    image = imread(strcat(prefix_image,num2str(num),fileformat)); 
end 
+0

请不要在你的帖子中签名。请参阅[常见问题#签名]。 – Gilles 2012-02-18 18:32:54

1
  • 您可以使用dir函数获取目录中的所有文件。这将返回结构的载体,它也包括文件名
  • 遍历所有的结构
  • 检查文件是否是一个图像(例如检查扩展)
  • 读取图像
-1

这可以帮助您!

S = struct2cell(dir('*.jpg')); 
FileNames = S(1,:); 
lenDb = length(FileNames); 

result= struct('img', {}); 

for j = 1 : lenDb 


    result(j).img = imread(FileNames{j}) 
end 

所有的图像都在结构 “result.img”

要访问只需要调用的结果(NUM).IMG

例:

图像(结果(1)。 img)

0

以及该功能将帮助您在一次甚至diferent名称看了很多图片:

首先把所有的图片文件夹中,例如:d:/实验室/

他们必须在本例同样的格式:TIF

调用的函数,你键入:

A=imread_many(); 

个,所有的图像将在变量A

,如果你想在第一图像您键入A{1}如果u希望第二个U型A{2} ...等

function [ A ] = imread_many() 

    srcFiles = dir('D:\lab\*.tif'); % the folder in which ur images exists 
for i = 1 : length(srcFiles) 
    filename = strcat('D:\lab\',srcFiles(i).name); 
    A{i} = imread(filename); 
    figure, imshow(A{i}); 
end 

end 
0
srcFiles = dir('C:\Users\Omm\Downloads\multicharacterrec\*.png'); % the folder in which ur images exists 
for i = 1 : length(srcFiles) 
    filename = strcat('C:\Users\Omm\Downloads\multicharacterrec\',srcFiles(i).name); 
    I = imread(filename); 
    figure, imshow(I);