如何使用matlab获取文件夹中多个图像的宽度和高度?

时间:2017-06-15 15:46:00

标签: matlab image-processing

如何使用matlab获取文件夹中多个图像(.bmp)的宽度和高度? 我知道一张图片

         Infoimage = imfinfo(filename);
         width=Infoimage.Width();
         height=Infoimage.Height();

我写的下面的代码是我的代码的一部分,它获取每个图像的宽度和高度并传递给我的函数:

         filename = getAllFiles('/my directory path')
         Infoimage = imfinfo(filename);
         width=Infoimage.Width();
         height=Infoimage.Height();

但错误是,我不知道如何确定我的文件名类型

Expected FILENAME to be one of these types:
char
Instead its type was cell.
Error in untitled4 (line 2)
          Infoimage = imfinfo(filename);

任何解决方案?

更新

getALLFiles.m

function fileList = getAllFiles(dirName)

  dirData = dir(dirName);      %# Get the data for the current directory
  dirIndex = [dirData.isdir];  %# Find the index for directories
  fileList = {dirData(~dirIndex).name}';  %'# Get a list of the files
  if ~isempty(fileList)
    fileList = cellfun(@(x) fullfile(dirName,x),...  %# Prepend path to files
                       fileList,'UniformOutput',false);
  end
  subDirs = {dirData(dirIndex).name};  %# Get a list of the subdirectories
  validIndex = ~ismember(subDirs,{'.','..'});  %# Find index of subdirectories
                                               %#   that are not '.' or '..'
  for iDir = find(validIndex)                  %# Loop over valid subdirectories
    nextDir = fullfile(dirName,subDirs{iDir});    %# Get the subdirectory path
    fileList = [fileList; getAllFiles(nextDir)];  %# Recursively call getAllFiles
  end

end

1 个答案:

答案 0 :(得分:1)

您可以构建一个imageDatastore并使用imageDatastore中的Files属性来显示使用imfinfo的大小。 imageDatastore允许您递归浏览文件夹,正如您在上面的示例中所做的那样。

imds = imageDatastore(dirName,'FileExtensions',{'.bmp'},'IncludeSubfolders',true);

fileList = imds.Files