Image 从目录加载所有图像
我有一个目录中的某些图像,我想加载所有这些图像进行一些处理。我尝试使用Image 从目录加载所有图像,image,matlab,image-processing,matlab-cvst,Image,Matlab,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,
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
我收到一个错误,因为无法读取xyz.jpg未找到此类文件或目录,其中xyz是我在该目录中的第一个映像。我还想从目录中加载所有格式的图像,而不仅仅是jpg…我如何才能做到这一点 我相信您想要的是
imread
功能,而不是load
。请参阅。完整路径(inc.目录)不包含在imgfiles.name中,只包含文件名,因此它找不到文件,因为您没有告诉它要查找的位置。如果不想更改目录,请在读取文件时再次使用fullfile
您还使用了错误的函数读取图像-请尝试imread。
其他注意事项:,并且您的循环在每一步都会覆盖I2,因此您将只得到一个图像,而不是四个图像。您可以轻松加载具有相同类型的多个图像,如下所示:
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
function Seq=loadImages(imgPath,imgType)
%imgPath='path/to/images/folder/';
%imgType='*.png';%根据图像类型进行更改
images=dir([imgPath-imgType]);
N=长度(图像);
%检查图像
if(~exist(imgPath,'dir'))| | N您可以使用计算机视觉系统工具箱中的对象。它从给定的目录加载图像文件名,并使您能够按顺序读取图像。它还使您可以选择递归到子目录。在读取图像时,我如何再次提供fullfile。您能编写代码吗?您真的有吗查看了forfullfile
?我必须将路径更改为“path/to/images/folder/”以使其正常工作。这仍然是一个很好的解决方案。我强烈建议使用fullfile
从文件夹和文件名创建图像路径,以便正确考虑后续斜杠和文件系统差异。