Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Recap
Recap le 15 Mar 2016
Modifié(e) : Image Analyst le 15 Mar 2016
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

Réponse acceptée

Image Analyst
Image Analyst le 15 Mar 2016
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 commentaires
Recap
Recap le 15 Mar 2016
I get that now but what about when it loops? where does it stack then?
Image Analyst
Image Analyst le 15 Mar 2016
Modifié(e) : Image Analyst le 15 Mar 2016
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by