Home > vbmeg > functions > job > vb_job_fmri.m

vb_job_fmri

PURPOSE ^

Import fMRI results to VBMEG cortical act file(.act.mat) and area file(.area.mat)

SYNOPSIS ^

function vb_job_fmri(varargin)

DESCRIPTION ^

 Import fMRI results to VBMEG cortical act file(.act.mat) and area file(.area.mat)
 Support SPM earlier than spm8, tested with spm8  

 [Syntax]
    vb_job_frmi(fmri_parm);
    vb_job_fmri(proj_root, fmri_parm);   [old style]

 [Input]
    proj_root : <<string>> VBMEG project root directory.
    fmri_parm : Import parameters for fmri.

 [Output]
    none

 [History]
   2016/11/21 rhayashi
     [Change] spec of SPMmapmode changed more clearly e.g. 'mni' -> 'mni2subj'
   2016/07/26 O.Yamahista
     [Change] spm_ver is obtained from SPM.mat 
   2016/07/12 O.Yamahista
     [Fix] bug fix when importing SPM maps on MNI brain to the MNI brain model 
   2016/07/05 O.Yamashita
     [Add] process to project normalized SPM maps on the MNI brain model
   2016/07/03 O.Yamashita
     initial version

 [Note]
   @see vb_set_fmri_parm.m

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function vb_job_fmri(varargin)
0002 % Import fMRI results to VBMEG cortical act file(.act.mat) and area file(.area.mat)
0003 % Support SPM earlier than spm8, tested with spm8
0004 %
0005 % [Syntax]
0006 %    vb_job_frmi(fmri_parm);
0007 %    vb_job_fmri(proj_root, fmri_parm);   [old style]
0008 %
0009 % [Input]
0010 %    proj_root : <<string>> VBMEG project root directory.
0011 %    fmri_parm : Import parameters for fmri.
0012 %
0013 % [Output]
0014 %    none
0015 %
0016 % [History]
0017 %   2016/11/21 rhayashi
0018 %     [Change] spec of SPMmapmode changed more clearly e.g. 'mni' -> 'mni2subj'
0019 %   2016/07/26 O.Yamahista
0020 %     [Change] spm_ver is obtained from SPM.mat
0021 %   2016/07/12 O.Yamahista
0022 %     [Fix] bug fix when importing SPM maps on MNI brain to the MNI brain model
0023 %   2016/07/05 O.Yamashita
0024 %     [Add] process to project normalized SPM maps on the MNI brain model
0025 %   2016/07/03 O.Yamashita
0026 %     initial version
0027 %
0028 % [Note]
0029 %   @see vb_set_fmri_parm.m
0030 %
0031 % Copyright (C) 2011, ATR All Rights Reserved.
0032 % License : New BSD License(see VBMEG_LICENSE.txt)
0033 
0034 %
0035 % --- Previous check
0036 %
0037 spm_func = which('spm_vol');
0038 if isempty(spm_func)
0039     error('Please add SPM8 path to your MATLAB.');
0040 end
0041 if nargin == 1
0042     proj_root = [];
0043     parm = varargin{1};
0044 elseif nargin == 2
0045     proj_root = varargin{1};
0046     parm      = varargin{2};
0047 else
0048     error('Invalid usage of vb_job_fmri.');
0049 end
0050 
0051 proj_root = vb_rm_trailing_slash(proj_root);
0052 
0053 %
0054 % --- Main Procedure
0055 %
0056 
0057 % PARAMETERS
0058 % SPM results
0059 SPMmat_file = parm.SPMmat_file;
0060 brain_file  = fullfile(proj_root, parm.brain_file);
0061 
0062 % Resutls output
0063 act_file    = fullfile(proj_root, parm.act_file);
0064 area_file   = fullfile(proj_root, parm.area_file);
0065 keys_postfix = parm.keys_postfix; 
0066 
0067 % function mode
0068 Tthres  = parm.Tthres;      % important parameters
0069 Rthres  = parm.Rthres;      % unit:mm
0070 PSthres = parm.PSthres;     % unit:%
0071 SPMmapmode = parm.SPMmapmode;
0072 
0073 
0074 switch lower(SPMmapmode)
0075     case {'subj2subj'}
0076         % SPM results on Subject brain
0077         % need input parameter check
0078         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0079         vb_fmri_project_Tmap_cortex(brain_file,act_file,area_file,Tthres,Rthres,SPMimginfo);
0080 
0081         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0082         vb_fmri_project_PSmap_cortex(brain_file,act_file,area_file,PSthres,Rthres,SPMimginfo);
0083 
0084     case {'mni2subj'}
0085         % SPM results on MNI brain --> Subject brain
0086         %  need input parameter check
0087         sn_file     = parm.spm_normalization_file;
0088         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0089         vb_fmri_unsn_project_Tmap_cortex(brain_file,act_file,area_file,sn_file,Tthres,Rthres,SPMimginfo);
0090 
0091         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0092         vb_fmri_unsn_project_PSmap_cortex(brain_file,act_file,area_file,sn_file,PSthres,Rthres,SPMimginfo);
0093 
0094     case {'mni2mni'}
0095         %  SPM results on MNI brain --> MNI brain model
0096         fprintf(' SPM maps on MNI brain will projected to the MNI standard brain model ! \n');
0097 
0098         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_T' keys_postfix], 1);
0099         vb_fmri_project_Tmap_cortex(brain_file,act_file,area_file,Tthres,Rthres,SPMimginfo,1);
0100 
0101         SPMimginfo = SPMmat2SPMimginfo(SPMmat_file, ['_PS' keys_postfix],0);
0102         vb_fmri_project_PSmap_cortex(brain_file,act_file,area_file,PSthres,Rthres,SPMimginfo,1);
0103 
0104     otherwise
0105         error('SPMmapmode must be either ''subj2subj'', ''mni2subj'' or ''mni2mni'' !');
0106 end
0107 
0108 %--------------------------
0109 % Save project file
0110 %--------------------------
0111 proj_file = get_project_filename;
0112 if ~isempty(proj_file)
0113     project_file_mgr('load', proj_file);
0114     project_file_mgr('add', 'fmri_parm', parm);
0115 end
0116 
0117 
0118 
0119 %
0120 % inner function
0121 %
0122 
0123 function SPMimginfo = SPMmat2SPMimginfo(SPMmatfile,postfix,flagT)
0124 
0125 load(SPMmatfile);
0126 
0127 spm_ver = SPM.SPMid(1:strfind(SPM.SPMid,':')-1);
0128 
0129 for nn = 1 : length(SPM.xCon)
0130 
0131     % image labels
0132     labels{nn} = [SPM.xCon(nn).name postfix];
0133 
0134     % image filenames
0135     if flagT  % T-map
0136         filenames{nn}   = [SPM.xCon(nn).Vspm.fname];
0137     else     % Con-map
0138         filenames{nn}   = [SPM.xCon(nn).Vcon.fname];
0139     end
0140 
0141     % ncon
0142     ncon(nn)   = sum(SPM.xCon(nn).c > 0);
0143     % peak
0144     ixreg = find(SPM.xCon(nn).c);
0145     X     = SPM.xX.X(:,ixreg);
0146     peak(nn) = max(X(:));
0147     % baseline img
0148     a = strfind(SPM.xX.name, 'constant');
0149     for ii = 1 : length(a)
0150         if ~isempty(a{ii})
0151             ixreg = ii;
0152         end
0153     end
0154     baseimgfiles{nn} = ['beta_' num2str(ixreg, '%04d') '.img'];
0155 
0156 end
0157 
0158 spmdir = [fileparts(SPMmatfile) filesep];
0159 
0160 for nn = 1 : length(SPM.xCon)
0161     SPMimginfo(nn) = struct('dirname', spmdir, 'imgfilename', filenames{nn}, 'imglabel', labels{nn},...
0162         'ncon',ncon(nn),'peak', peak(nn), 'baseimgfilename', baseimgfiles{nn},'spm_ver',spm_ver);
0163 end

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