Change orientation of analyze file image avw = change_orient_analyze(avw, orient_now) avw = change_orient_analyze(avw, orient_now, flip_sw) --- Input/output avw.hdr - a struct with image data parameters. avw.img - a 3D matrix of image data (double precision). orient_now : orient number of current image flip_sw : RAS or LAS switch = -1 : LAS [default] = +1 : RAS --- orient_now orient_now = [orient_now_x orient_now_y orient_now_z] orient_now_x : current x-axis orient number defined below orient_now_y : current y-axis orient number defined below orient_now_z : current z-axis orient number defined below --- orient number Left to Right 1 [R] % Right to Left -1 [L] Posterior to Anterior 2 [A] % Anterior to Posterior -2 [P] Inferior to Superior 3 [S] % Superior to Inferior -3 [I] --- orient 'orient_now' us transformed to 'orient' in the program orient : axis dim to get RAS coordinate = [orient_x orient_y orient_z] orient_x : Left to Right axis dim of current image orient_y : Posterior to Anterior axis dim of current image orient_z : Inferior to Superior axis dim of current image current image axis dim is [+-1/+-2/+-3] for [+-x/+-y/+-z] --- Example - 現在の座標軸の方向 orient_now = [2 -3 1]; % x+: A , y+: I , z+: R : AIR - RAS座標へ置換 orient = [3 1 -2]; % z -> X, x -> Y, -y -> Z : RAS --- Permutation of axis img_RAS(j3,j1,j2) = img_now(j1,j2,j3) --- Flip axis img_RAS = img_RAS(:,:,N3:-1:1) Made by Masa-aki Sato 2008-02-17
0001 function avw = change_orient_analyze(avw, orient_now, flip_sw) 0002 % Change orientation of analyze file image 0003 % avw = change_orient_analyze(avw, orient_now) 0004 % avw = change_orient_analyze(avw, orient_now, flip_sw) 0005 % --- Input/output 0006 % avw.hdr - a struct with image data parameters. 0007 % avw.img - a 3D matrix of image data (double precision). 0008 % orient_now : orient number of current image 0009 % flip_sw : RAS or LAS switch 0010 % = -1 : LAS [default] 0011 % = +1 : RAS 0012 % --- orient_now 0013 % orient_now = [orient_now_x orient_now_y orient_now_z] 0014 % orient_now_x : current x-axis orient number defined below 0015 % orient_now_y : current y-axis orient number defined below 0016 % orient_now_z : current z-axis orient number defined below 0017 % --- orient number 0018 % Left to Right 1 [R] % Right to Left -1 [L] 0019 % Posterior to Anterior 2 [A] % Anterior to Posterior -2 [P] 0020 % Inferior to Superior 3 [S] % Superior to Inferior -3 [I] 0021 % 0022 % --- orient 0023 % 'orient_now' us transformed to 'orient' in the program 0024 % orient : axis dim to get RAS coordinate 0025 % = [orient_x orient_y orient_z] 0026 % orient_x : Left to Right axis dim of current image 0027 % orient_y : Posterior to Anterior axis dim of current image 0028 % orient_z : Inferior to Superior axis dim of current image 0029 % current image axis dim is [+-1/+-2/+-3] for [+-x/+-y/+-z] 0030 % --- Example 0031 % - 現在の座標軸の方向 0032 % orient_now = [2 -3 1]; % x+: A , y+: I , z+: R : AIR 0033 % - RAS座標へ置換 0034 % orient = [3 1 -2]; % z -> X, x -> Y, -y -> Z : RAS 0035 % --- Permutation of axis 0036 % img_RAS(j3,j1,j2) = img_now(j1,j2,j3) 0037 % --- Flip axis 0038 % img_RAS = img_RAS(:,:,N3:-1:1) 0039 % 0040 % Made by Masa-aki Sato 2008-02-17 0041 0042 % avw = avw_img_read(fname); 0043 0044 if ~exist('orient_now','var'), orient_now = [2 -3 1]; end; 0045 if ~exist('flip_sw','var'), flip_sw = -1; end; 0046 0047 orient = zeros(1,3); 0048 0049 % Convert 'orient_now' to 'orient' 0050 for j=1:3 0051 ix = find( abs(orient_now) == j ); 0052 orient(j) = ix * sign(orient_now(ix)); 0053 end 0054 0055 % Left/Right flip switch 0056 orient(1) = orient(1)*flip_sw; 0057 0058 fprintf('Orient = [%d %d %d]\n', orient) 0059 0060 % 0061 % --- Change orientation of image 0062 % 0063 avw = change_orient_ras(avw , orient); 0064 0065 return 0066 % --- sform transform 0067 % i = 0 .. dim[1]-1 0068 % j = 0 .. dim[2]-1 0069 % k = 0 .. dim[3]-1 0070 % x = srow_x[0] * i + srow_x[1] * j + srow_x[2] * k + srow_x[3] 0071 % y = srow_y[0] * i + srow_y[1] * j + srow_y[2] * k + srow_y[3] 0072 % z = srow_z[0] * i + srow_z[1] * j + srow_z[2] * k + srow_z[3] 0073 % --- matrix form 0074 % [x ; y ; z] = R * [i ; j ; k] + T 0075 0076 % No flip case 0077 % x = i + T1 (i=0:N1-1) 0078 % = ii + X0 (ii=1:N1, X0=T1-1) 0079 % Flip case 0080 % x = -i + T1 (i=0:N1-1) 0081 % ii= N1 - i (ii=1:N1) 0082 % x = ii + X0 (ii=1:N1, X0=T1-N1) 0083 0084 %dim = avw.hdr.dime.dim(2:4) 0085 %pixdim = avw.hdr.dime.pixdim(2:4) 0086 0087 % DIM = avw.hdr.dime.dim(2:4) % 画像サイズ 0088 % VOX = avw.hdr.dime.pixdim(2:4) % voxelサイズ 0089 % TYPE = avw.hdr.dime.datatype % data type 0090 % ORIGIN = avw.hdr.hist.originator(1:3) % 画像の原点