如何读取多个图像并将其存储在MATLAB中?



这是目前为止的代码,

clear;clc;
path = uigetdir(); %open directory
if isequal(path,0) 
disp('User selected Cancel');
return
else
disp(['User selected ', (path)]); 
end
% pathPattern = fullfile(path); 
theFiles = dir(path); %Get list of all files with desired pattern
for k = 3 :5  %Change length when needed
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %sn', fullFileName)
end
a = imread(fullFileName);

我的问题是imread只从我的目录中读取一个图像,我需要它读取所有图像并将它们存储在单元格数组中。我从网上试了很多答案,但到目前为止都没有效果。

存储在循环内的单元格数组中,因为它允许不同大小的图像。如果您事先知道图像的大小相同,那么使用常规的数字数组将会快得多。

clear, clc
path = uigetdir(); % open directory
if isequal(path,0) 
disp('User selected Cancel');
return
else
disp(['User selected ', (path)]); 
end
theFiles = dir(path);       % Get list of all files with desired pattern
for k = 3:length(theFiles)  % Change length when needed
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1,'Now reading %sn', fullFileName)
a{k-2} = imread(fullFileName);
end
a

相关内容

  • 没有找到相关文章

最新更新