Home > vbmeg > functions > tool_box > spmtools > vb_sn_and_graymatter_file_create.m

vb_sn_and_graymatter_file_create

PURPOSE ^

Create SPM normalization file and Gray matter file using SPM5/8 function.

SYNOPSIS ^

function vb_sn_and_graymatter_file_create(mri_file)

DESCRIPTION ^

 Create SPM normalization file and Gray matter file using SPM5/8 function.

 [Usage]
    vb_sn_and_graymatter_file_create(mri_file);

 [Input]
    mri_file: NIfTI(.nii) or LAS analyze file(.img)

 [Output]
    spm_normalization file :  mri_file(base) + '_sn.mat' 
    gray matter file       :  'c1' + mri_file

 [Note]
    SPM path should be added to MATLAB.
    addpath(genpath(spm_path));

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vb_sn_and_graymatter_file_create(mri_file)
0002 % Create SPM normalization file and Gray matter file using SPM5/8 function.
0003 %
0004 % [Usage]
0005 %    vb_sn_and_graymatter_file_create(mri_file);
0006 %
0007 % [Input]
0008 %    mri_file: NIfTI(.nii) or LAS analyze file(.img)
0009 %
0010 % [Output]
0011 %    spm_normalization file :  mri_file(base) + '_sn.mat'
0012 %    gray matter file       :  'c1' + mri_file
0013 %
0014 % [Note]
0015 %    SPM path should be added to MATLAB.
0016 %    addpath(genpath(spm_path));
0017 %
0018 
0019 %
0020 % --- Previous check
0021 %
0022 spm = which('spm.m');
0023 if isempty(spm)
0024     error('SPM path should be added to MATLAB.');
0025 end
0026 if nargin ~= 1
0027     error('Please check function usage.');
0028 end
0029 if exist(mri_file, 'file') ~= 2
0030     error('Specified file not found %s', mri_file);
0031 end;
0032 
0033 %
0034 % --- Main Procedure
0035 %
0036 
0037 mri_file = [mri_file, ',1'];
0038 
0039 % Segment(SPM5/8)
0040 spm_dir = which('spm.m');
0041 gray_file  = fullfile(spm_dir, 'tpm', 'grey.nii');
0042 white_file = fullfile(spm_dir, 'tpm', 'white.nii');
0043 csf_file   = fullfile(spm_dir, 'tpm', 'csf.nii');
0044 
0045 opt.tmp      = str2mat(gray_file, white_file, csf_file);
0046 opt.ngaus    = [2; 2; 2; 4];
0047 opt.regtype  = 'mni';
0048 opt.warpreg  = 1;
0049 opt.warpco   = 25;
0050 opt.biasreg  = 0.0001;
0051 opt.biasfwhm = 60;
0052 opt.samp     = 3;
0053 opt.msk      = '';
0054 
0055 res = spm_preproc(mri_file, opt);
0056 
0057 % Create SN-MAT
0058 sn  = spm_prep2sn(res);
0059 
0060 [pth, nam]   = vb_get_file_parts(mri_file);
0061 sn_filename  = fullfile(pth, [nam '_seg_sn.mat']);
0062 vb_save_struct(sn_filename, sn);
0063 
0064 % Create Graymatter
0065 output.GM  = [0 0 1];
0066 output.WM  = [0 0 0];
0067 output.CSF = [0 0 0];
0068 output.biascor = 0;
0069 output.cleanup = 0;
0070 spm_preproc_write(sn, output);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005