【发布时间】:2014-03-24 10:38:13
【问题描述】:
我在一个文件夹中有 170 张 png 图像。 我想将它们加载并存储在矩阵/数组/单元格数组中,以便我可以轻松访问和修改它们,但我一开始就卡住了。 我该怎么做?哪种结构最好?
【问题讨论】:
我在一个文件夹中有 170 张 png 图像。 我想将它们加载并存储在矩阵/数组/单元格数组中,以便我可以轻松访问和修改它们,但我一开始就卡住了。 我该怎么做?哪种结构最好?
【问题讨论】:
假设它们的大小相同,在包含图像的文件夹中:
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 的大小...