我正在尝试让用户在MATLAB中使用以下命令从文件夹中选择图像:
uigetfile('*.tiff','Select the image files')
我希望将图像写入具有n
元素的数组或矩阵(n
是图像选择循环中选择的图像数)。
我尝试了多种不同的方式,所以任何帮助都会非常感激。 谢谢你。
这是我最近的尝试:
function imagereader
x={};
i=1;
response = 1;
while response ~= 0
[FileName] = uigetfile('*.tiff','Select the image files')
x{i} = FileName;
choice = questdlg('Do you wish to select more images?','Image selection','Yes','No','No');
switch choice
case 'Yes'
response = 1;
i+1;
case 'No'
response = 0;
end
end
while i >= 1
image(x{i})
i-1;
end
答案 0 :(得分:1)
我修改了你的例子。希望它有所帮助:
function imagereader
x={};
i=1;
response = 1;
while response ~= 0
[FileName,PathName] = uigetfile('*.tiff','Select the image files');
[FileName,PathName]
x{i} = imread([PathName, FileName]);
choice = questdlg('Do you wish to select more images?','Image selection','Yes','No','No');
switch choice
case 'Yes'
response = 1;
i+1;
case 'No'
response = 0;
end
end
while i >= 1
figure;
imshow(x{i});
i = i-1;
end
答案 1 :(得分:0)
最直接的方法是将图像存储在包含n
个单元格的单元格数组中:
filenames = uigetfiles('*.tiff','Select the image files', 'multiselect', 'on' );
n = numel(filenames); % number of files selected
imgs = cell( n , 1 ); % pre-allocate space
for ii=1:n
imgs{ii} = imread( filenames{ii} );
end
如果您的所有图像大小相同,则可以将它们堆叠成4D(彩色图像)/ 3D(灰度图像)阵列。