繁体   English   中英

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

[英]How to read multiple images and store them on 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 %s\n', 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 %s\n', fullFileName)
    a{k-2} = imread(fullFileName);
end

a

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM