Transform NIFTI mm coordinate to SPM-Right-m coordinate [Xspm] = vb_nifti_mm_to_spm_right_mm(Xnft, fname) Xnft ; NIFTI [mm] coordinate (Npoint x 3) fname : file name of T1 image file Xspm : SPM-Right [m] coordinate Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [Xspm] = vb_nifti_mm_to_spm_right_mm(Xnft, fname) 0002 % Transform NIFTI mm coordinate to SPM-Right-m coordinate 0003 % [Xspm] = vb_nifti_mm_to_spm_right_mm(Xnft, fname) 0004 % Xnft ; NIFTI [mm] coordinate (Npoint x 3) 0005 % fname : file name of T1 image file 0006 % Xspm : SPM-Right [m] coordinate 0007 % 0008 % Copyright (C) 2011, ATR All Rights Reserved. 0009 % License : New BSD License(see VBMEG_LICENSE.txt) 0010 0011 [hdr, filetype] = load_nii_hdr_cbi(fname); 0012 0013 % --- File type check field 0014 % nii.filetype = 0015 % 0 : Analyze .hdr/.img , (.hdr : 348 byte) 0016 % 1 : NIFTI .hdr/.img , (.hdr : 348 byte) 0017 % 2 : NIFTI .nii , (.nii : 348 byte hdr + image data) 0018 0019 if filetype == 0 0020 % Analyze format 0021 Xspm = Xnft; 0022 return 0023 end 0024 0025 [Trans , dim] = get_coord_trans_mat(fname); 0026 0027 % Trans : transform matrix from voxcel to mm coordinate defined by NIFTI 0028 % [x y z 1] = [i j k 1] * Trans 0029 % Xnft = Vox * Trans 0030 % Vox = Xnft * inv(Trans) 0031 0032 % Image center in NIFTI coordinate 0033 center = vb_affine_trans(dim/2 , Trans); 0034 0035 % Vox = dim/2 <-> Xnft = center 0036 % Xspm = 0 <-> Xnft = center 0037 % Xspm = Xnft - center 0038 % Xnft = Xspm + center 0039 0040 % Get SPM-Right-mm coordinate 0041 Xspm = vb_repadd(Xnft , -center); 0042 0043 return 0044 0045 % Get NIFTI mm coordinate from SPM-Right-m 0046 % Xnft = vb_repadd(Xspm * 1000 , center) ;