Creating a matrix array for training images. Whats going on?

2 次查看(过去 30 天)
Can someone please explain what is going on in the second loop and how its happening.
N = 90
for i=1:N
% importing files
FName=sprintf('%d.bmp',i);
image1=imread([FFolder1, FName]);
image2=imread([FFolder2, FName]);
image3=imread([FFolder3, FName]);
% taking the 2D image (image1-3) and sticks it into the i'th
% slice (plane) of a 3D image
im1(:,:,i)=image1; % "0"
im2(:,:,i)=image2; % "1"
im3(:,:,i)=image3; % "2"
end
% What is going on in this loop?
for i=1:N
im(:,:,i)=im1(:,:,i);
im(:,:,i+N)=im2(:,:,i);
im(:,:,i+2*N)=im3(:,:,i);
end

采纳的回答

Image Analyst
Image Analyst 2016-3-15
Basically you have 3 volumetric images: im1, im2, and im3. That code stacks them on top of each other to form a new volumetric image that is equal to the height of all 3 summed together (because they're stacked in the Z direction).
  4 个评论
Recap
Recap 2016-3-15
I get that now but what about when it loops? where does it stack then?
Image Analyst
Image Analyst 2016-3-15
编辑:Image Analyst 2016-3-15
If im is already preallocated, it's basically inserting the three layers in at the proper level. If it's not, then the last line basically "grows" the stack taller and then those planes are there and the next iteration the two lower planes will be inserted and another layer added on the top. Put this line into the for loop and you'll see what it's doing
fprintf('Now inserting planes %d, %d, and %d\n', i, i+N, i+2*n);
You should be able to simply do
im = cat(3, im1, im2, im3);
instead of that for loop. This should be faster.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by