source: aedes_rot3d.m @ 80

Last change on this file since 80 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 2.2 KB
RevLine 
[80]1function B = aedes_rot3d(A,k,dim)
2% AEDES_ROT3D - Rotate 3D (or 4D) matrix in 90 degree steps in 3 dimensions
[2]3%
4%
5% Synopsis:
6%
7% Description:
8%
9% Examples:
10%
11% See also:
12%
13
[39]14% This function is a part of Aedes - A graphical tool for analyzing
[36]15% medical images
[2]16%
[36]17% Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi>
18%
[45]19% Department of Physics, Department of Neurobiology
[39]20% University of Kuopio, FINLAND
[36]21%
22% This program may be used under the terms of the GNU General Public
23% License version 2.0 as published by the Free Software Foundation
24% and appearing in the file LICENSE.TXT included in the packaging of
25% this program.
26%
27% This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28% WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
[2]29
[36]30
[2]31if nargin<2
[80]32  error('AEDES_ROT3D: Too few input arguments!')
[2]33elseif nargin<3
34  dim = 3; % Use dim 3 as a default
35end
36
[51]37if ndims(A)>4 || ~( isnumeric(A) || islogical(A) )
38  error('First input argument must be a numerical 3D (or 4D)-matrix!')
[2]39end
40
41if ~isnumeric(k) || ~any(k==[0 1 2 3 4])
42  error('The second input argument has to be a scalar 0,1,2,3, or 4!')
43end
44
45switch dim
46  case 1
[53]47        if k==1 % Rotate 90 degrees along dim 1 (rows)
48          B = flipdim(permute(A,[3 2 1 4]),1);
49        elseif k==2 % Rotate 180 degrees along dim 1 (rows)
50          B = flipdim(flipdim(A,3),1);
51    elseif k==3 % Rotate 270 degrees along dim 1 (rows)
52          B = flipdim(permute(A,[3 2 1 4]),3);
53        elseif k==0 || k==4
54          B=A;
55        end
56  case 2
57        if k==1 % Rotate 90 degrees along dim 2 (cols)
[51]58      B = flipdim(permute(A,[1 3 2 4]),3);
[53]59    elseif k==2 % Rotate 180 degrees along dim 2 (cols)
[2]60      B = flipdim(flipdim(A,3),2);
[53]61    elseif k==3 % Rotate 270 degrees along dim 2 (cols)
[51]62      B = flipdim(permute(A,[1 3 2 4]),2);
[2]63    elseif k==0 || k==4
64      B=A;
[53]65        end
[2]66  case 3
67    if k==1 % Rotate 90 degrees along dim 3
[51]68      B = flipdim(permute(A,[2 1 3 4]),1);
[2]69    elseif k==2 % Rotate 180 degrees along dim 3
70      B = flipdim(flipdim(A,2),1);
71    elseif k==3 % Rotate 270 degrees along dim 3
[51]72      B = flipdim(permute(A,[2 1 3 4]),2);
[2]73    elseif k==0 || k==4
74      B=A;
[51]75        end
[2]76  otherwise
77    return
78end
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008