将多个图像矢量存储到矩阵的行

时间:2017-06-03 22:23:53

标签: matlab image-processing

我有一个包含200个BMP图像的文件夹,我正在读取所有图像,将每个图像转换为矢量,然后尝试将这些图像矢量存储到矩阵中。以下是不言自明的代码,虽然它看起来很正确但是当我运行脚本时它给了我以下错误。

Error in Readallimages (line 16)
immat(437580,k)=imtovector 
Subscripted assignment dimension mismatch.`

myFolder = 'C:\Users\Sana\Desktop\DermoscopyImages';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', 
myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.bmp');
bmpFiles = dir(filePattern);
immat=zeros(437580,200);

  for k = 1:length(bmpFiles)
      baseFileName = bmpFiles(k).name;
      fullFileName = fullfile(myFolder, baseFileName);
      fprintf(1, 'Now reading %s\n', fullFileName);
      imageArray = rgb2gray(imread(fullFileName)); %Read images
      imtovector=double(imageArray(:));      %Convert 2D image to 1D vector
      immat(437580,k)=imtovector           %Store image vector to matrix
      imshow(imageArray);  % Display image.
      drawnow; % Force display to update immediately.
  end`

非常感谢在这方面提供任何形式的帮助。 谢谢inadvance

0 个答案:

没有答案