【问题标题】:how to load a stack of images on matlab [closed]如何在matlab上加载一堆图像[关闭]
【发布时间】:2014-03-24 10:38:13
【问题描述】:

我在一个文件夹中有 170 张 png 图像。 我想将它们加载并存储在矩阵/数组/单元格数组中,以便我可以轻松访问和修改它们,但我一开始就卡住了。 我该怎么做?哪种结构最好?

【问题讨论】:

    标签: arrays image matlab


    【解决方案1】:

    假设它们的大小相同,在包含图像的文件夹中:

    list=dir('*.png'); % read all the .pngs in your folder
    
    Image1=imread(list(1).name); % read the first image to calculate the dimentions of your stack
    ImSize=size(Image1)
    
    ImageStack=zeros(ImSize(1),ImSize(2),length(list)); % preallocate your stack with zeros
    
    
    for ii=1:length(list)
    
        Image=imread(list(ii).name
        ImageStack(:,:,ii)=rgb2gray(Image); % copy an image in each step of the third dimsion of your stack 
    end
    

    如果您需要颜色信息,只需将另一个维度添加到 ImageStack 并忘记 rgb2gray()。希望对您有所帮助!

    【讨论】:

    • 如果我有不同尺寸的图像怎么办?我应该使用元胞数组吗?
    • 这取决于您以后要如何处理它们:单元格数组是一种可能性,但是如果您想避免这种情况,您还可以在每次迭代中计算Image 的大小,然后@ 987654325@ 但随后您将用零填充图像,并且必须在另一个循环中计算 ImageStack 的大小...
    • 好的!我明白了!感谢您的帮助,非常有帮助!
    猜你喜欢
    • 1970-01-01
    • 2011-12-10
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    相关资源
    最近更新 更多