我如何从matlab中的多个文件夹中读取图像?

时间:2012-05-16 12:37:35

标签: matlab

我的问题我将图像文件夹组织为

数据库 - > CASIA虹膜图像数据库(版本1.0) - > folder001(此文件夹更改为001到108) - > previouse文件夹包含两个文件夹,每个文件夹包含3个图像

文件夹的结构为

http://imageshack.us/photo/my-images/337/picture1ki.png/

我如何在MATLAB中阅读CASIA V1.0 1?

1 个答案:

答案 0 :(得分:1)

以下是文件夹中任意数量图像的通用代码。如果您确定每个文件夹有3个图像,并且您知道每个图像的文件名格式,则可以简化它。

%# Set the relative path for the database
basePath = 'Database/CASIA Iris Image Database (version 1.0)/';

for iFolder = 1:108
    %# Set current folder
    folder = sprintf('%s%03d/', basePath, iFolder);

    %# Find the image (e.g. bmp) files in the folder. Modify bmp for your needs.
    %#   and also modify 'left' string according to the subfolder of left images
    filenames = arrayfun(@(x) x.name, dir([folder 'left/*.bmp']),'UniformOutput',false);

    for iFile = 1:length(filenames)
        img = imread([folder filenames{iFile}]);

        %# and process the image
        %# ...

    end

    %# Modify the code for to run it for right folder
    %# ...
end
相关问题