从目录加载所有图像 [英] Load all the images from a directory

查看:140
本文介绍了从目录加载所有图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录中有某些图像,我想加载所有这些图像来进行一些处理。我尝试使用加载函数。

I have certain images in a directory and I want to load all those images to do some processing. I tried using the load function.

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

我收到错误,因为无法读取xyz.jpg没有这样的文件或找到目录,其中xyz是我在该目录中的第一个图像。

我还想从目录中加载所有格式的图像,而不仅仅是jpg ......我怎么能这样做?

I am getting an error as unable to read xyz.jpg no such file or directory found, where xyz is my first image in that directory.
I also want to load all formats of images from the directory instead of just jpg...how can i do that?

推荐答案

您可以轻松加载以下相同类型的多张图片:

You can easily load multiple images with same type as follows:

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

这篇关于从目录加载所有图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆