change orientation of image to RAS coordinate img = change_img_orient_ras(img,R) --- Input img : 3D image R : rotation matrix from current axis to RAS coordinate
0001 function img = change_img_orient_ras(img,R) 0002 % change orientation of image to RAS coordinate 0003 % img = change_img_orient_ras(img,R) 0004 % --- Input 0005 % img : 3D image 0006 % R : rotation matrix from current axis to RAS coordinate 0007 0008 % orient = get_orient_from_rot(R) 0009 % --- orient 0010 % orient : axis dim to get RAS coordinate 0011 % = [orient_x orient_y orient_z] 0012 % orient_x : Left to Right axis dim of current image 0013 % orient_y : Posterior to Anterior axis dim of current image 0014 % orient_z : Inferior to Superior axis dim of current image 0015 % 0016 % Left to Right 1 0017 % Posterior to Anterior 2 0018 % Inferior to Superior 3 0019 % Right to Left -1 0020 % Anterior to Posterior -2 0021 % Superior to Inferior -3 0022 % 0023 % Copyright (C) 2011, ATR All Rights Reserved. 0024 % License : New BSD License(see VBMEG_LICENSE.txt) 0025 0026 orient = get_orient_from_rot(R); 0027 0028 % --- change axis of image 0029 img = permute(img, abs(orient)); 0030 0031 % orient = [3 1 2] 0032 % img(j3,j1,j2) = img(j1,j2,j3) 0033 0034 dim = size(img); 0035 0036 % --- flip image 0037 if orient(1) < 0 0038 img(1:dim(1),:,:) = img(dim(1):-1:1,:,:); 0039 end 0040 if orient(2) < 0 0041 img(:,1:dim(2),:) = img(:,dim(2):-1:1,:); 0042 end 0043 if orient(3) < 0 0044 img(:,:,1:dim(3)) = img(:,:,dim(3):-1:1); 0045 end