从目录加载所有图像

aus*_*ima 6 matlab image image-processing matlab-cvst

我在目录中有一些图像,我想加载所有这些图像进行一些处理.我尝试过使用这个load功能.

imagefiles = dir('F:\SIFT_Yantao\demo-data\*.jpg');      
nfiles = length(imagefiles);    % Number of files found
 for i=1:nfiles
 currentfilename=imagefiles(i).name;
 I2 = imread(currentfilename);
 [pathstr, name, ext] = fileparts(currentfilename);
 textfilename = [name '.mat'];
fulltxtfilename = [pathstr textfilename];
load(fulltxtfilename);
descr2 = des2;
frames2 = loc2;
do_match(I1, descr1, frames1, I2, descr2, frames2) ;
end
Run Code Online (Sandbox Code Playgroud)

我收到一个错误,因为无法读取xyz.jpg没有找到这样的文件或目录,其中xyz是我在该目录中的第一个图像.
我还想从目录加载所有格式的图像,而不仅仅是jpg ......我怎么能这样做?

小智 10

您可以轻松加载具有相同类型的多个图像,如下所示:

function Seq = loadImages(imgPath, imgType)
    %imgPath = 'path/to/images/folder/';
    %imgType = '*.png'; % change based on image type
    images  = dir([imgPath imgType]);
    N = length(images);

    % check images
    if( ~exist(imgPath, 'dir') || N<1 )
        display('Directory not found or no matching images found.');
    end

    % preallocate cell
    Seq{N,1} = []

    for idx = 1:N
        Seq{d} = imread([imgPath images(idx).name]);
    end
end
Run Code Online (Sandbox Code Playgroud)