필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Recap
Recap 2016년 3월 15일
편집: Image Analyst 2016년 3월 15일
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