matlabpermutationd3dimage

Permutation of pages of a 3d array in matlab


I have a 3D array representing an image in MATLAB. I want to reverse the position of pages(in my case slices). Let's assume the number of pages is N. I want to replace first page with Nth, second with (N-1)th and so on.. Is there any function to do it in matlab. Now I am using the code below, but I have to avoid nested for loops, that is why I am looking for a prepared function. Any help would be appreciated.

Thank you in advance

I = ones(size(Image,1),size(Image,2),size(Image,3));
k=1;
for n=size(Image,3):-1:1
    I(:,:,k) = Image(:,:,n);
    k = k+1;
end

Solution

  • You can simply

    I = Image(:,:,end:-1:1);