0

我试图让用户在 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    
4

2 回答 2

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    
于 2013-08-12T06:48:30.787 回答
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(灰度图像)数组。

于 2013-08-11T05:19:18.970 回答