【问题标题】:Matlab - Opening more then one image extension - working with imagesMatlab - 打开一个以上的图像扩展 - 使用图像
【发布时间】:2015-03-26 13:41:54
【问题描述】:

我需要打开并放入相同的矢量 .jpg 图像和 .bmp 图像。 我可以打开 .jpg 或 .bmp,但我需要同时打开。

这是我的代码:

    image_folder = 'C:\Users\Marco\Desktop\teste';    
    filenames = dir(fullfile(image_folder, '*.jpg')); 
    total_images = numel(filenames); 

    for n=1:total_images
    images{n} = imread(sprintf('color%03d.jpg',n));  
    end;

(在这个例子中我打开 jpgs 但我需要打开 .jpg 和 .bmp )

【问题讨论】:

  • 我尝试了类似 for n=1:total_images2 images2{n} = imread(sprintf('cor%03d.jpg',n)); end 但我不知道如何将 images1{n} 和 images2{n} 放在一起

标签: image matlab matlab-figure matlab-guide


【解决方案1】:

filenames = dir() 应该给你需要循环浏览的文件名;您不必从 jpg 文件中解析 bmp。如果目录只包含您想要的图像,您可以尝试以下操作:

imageFolder = 'C:\Users\Marco\Desktop\teste\';
filenames = dir(imageFolder);

numImages = length(filenames)-2; % exclude counting '.' and '..'
images = cell(numImages,1);

n = 1;
for i = 1:length(filenames)
    if filenames(i).name(1) ~= '.'
        images{n} = imread([imageFolder filenames(i).name]);
        n = n+1;
    end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    • 2017-07-14
    • 2016-05-24
    • 2021-11-14
    • 2020-02-08
    相关资源
    最近更新 更多