Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Norm.m

Go to the documentation of this file.
00001 function [err, out_fn] = Norm (InBrik, N_runs, run, run_norm, run_mask, foutid_log)
00002 %
00003 %   [err, norm_fn] = Norm(InBrik, N_runs, run)
00004 %
00005 %Purpose:
00006 %   
00007 %   Normalize the original dataset so that the beta values in 3dDeconvolve would be automatically percent signal change.
00008 %   
00009 %Input Parameters:
00010 %   
00011 %   
00012 %   
00013 %Output Parameters:
00014 %   err : 0 No Problem
00015 %       : 1  Problems
00016 %   
00017 %   
00018 %      
00019 %Key Terms:
00020 %   
00021 %More Info :
00022 %   
00023 %   
00024 %   
00025 %
00026 %     Author : Gang Chen
00027 %     Date : Mon Oct 20 11:26:38 EDT 2003
00028 %     SSCC/NIMH/ National Institutes of Health, Bethesda Maryland
00029 
00030 
00031 %Define the function name for easy referencing
00032 FuncName = 'Norm';
00033 
00034 %Debug Flag
00035 DBG = 1;
00036 
00037 %initailize return variables
00038 err = 1;
00039 
00040 [InBrikPrefix, InBrikView, InBrikExt] =  AfniPrefix (InBrik);
00041 rm_cmmd = 'rm -f ';
00042         
00043 %Originally 3dClipLevel was used to generate a cliplevel for each run,
00044 %then a step function chops off those voxel outside of the brain.
00045 %But due to the concern of losing the sensitive amygdala and orbitofrontal cortex,
00046 %it might be better to run 3dAutomask, which is roughly equivalent to
00047 %3dClipLevel but would protect amygdala and orbitofrontal cortex regions
00048 %from being masked.
00049 
00050 %create command for executing 3dAutomask
00051 if (run_mask.do == 1),
00052    automask_fn = sprintf('%s_msk', InBrikPrefix);
00053    automask = sprintf('3dAutomask -dilate %i -prefix %s %s%s', run_mask.N_dilate, automask_fn, InBrikPrefix, InBrikView);
00054    fprintf(2, '\nRunning: %s\n', automask);
00055    fprintf(foutid_log, '%s\n', automask);
00056    [s,w] = system(automask);
00057    if (s),
00058       fprintf(2,'Error during 3dAutomask: \n\n%s\n\n',w);
00059       while (1); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00060    end
00061         rm_cmmd = sprintf('%s %s%s%s', rm_cmmd, automask_fn, InBrikView, InBrikExt);
00062         
00063         %If no normalization, do masking
00064    if (run_norm == 0), 
00065            out_fn = sprintf('%s_mask', InBrikPrefix);
00066       mask_signal = sprintf('3dcalc -fscale -a  %s%s  \\\n', InBrikPrefix, InBrikView);
00067            mask_signal = sprintf('%s    -b %s%s \\\n', mask_signal, automask_fn, InBrikView);
00068            mask_signal = sprintf('%s    -expr  "a*b" \\\n', mask_signal);
00069       mask_signal = sprintf('%s    -prefix %s', mask_signal, out_fn);
00070            fprintf(2, '\nRunning: %s\n', mask_signal);
00071            fprintf(foutid_log, '%s\n', mask_signal);
00072            [s,w] = system(mask_signal);
00073       if (s),
00074          fprintf(2,'Error during 3dcalc: \n\n%s\n\n',w);
00075          while (1); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00076       end
00077    end
00078         rm_cmmd = sprintf('%s %s%s%s', rm_cmmd, automask_fn, InBrikView, InBrikExt);
00079 end     
00080         
00081 if (run_norm == 1),   %for normalization
00082    out_fn = sprintf('%s_norm', InBrikPrefix);
00083    concat = sprintf('3dTcat -prefix %s ', out_fn);
00084         
00085    for (i=1:1:N_runs),
00086    
00087    %store each mean dataset in a temporary file, and delete it before leaving this function.
00088       mean_fn = sprintf('%s_mean%i', InBrikPrefix, i);
00089            get_mean = sprintf('3dTstat -mean -prefix %s %s%s''[%i..%i]''', mean_fn, InBrikPrefix, InBrikView, run(i).first, run(i).last);
00090       fprintf(2, '\nRunning: %s\n', get_mean);
00091            fprintf(foutid_log, '%s\n', get_mean);
00092            [s, w] = system(get_mean);
00093            if (s),
00094          fprintf(2,'Error at running 3dTstat: \n\n\n%s\n', w);
00095          while (1); fprintf(2,'Halted: Ctrl+c to exit');pause; end
00096       end
00097                 
00098         %normalizing
00099 %       norm_signal = sprintf('3dcalc -datum float -a  %s%s''[%i..%i]''  \\\n', InBrikPrefix, InBrikView, run(i).first, run(i).last);
00100            norm_signal = sprintf('3dcalc -fscale -a  %s%s''[%i..%i]''  \\\n', InBrikPrefix, InBrikView, run(i).first, run(i).last);
00101         norm_signal = sprintf('%s    -b %s%s \\\n', norm_signal, mean_fn, InBrikView);
00102                 if (run_mask.do == 1), 
00103                    norm_signal = sprintf('%s    -c %s%s \\\n', norm_signal, automask_fn,InBrikView); 
00104                 %       norm_signal = sprintf('%s    -expr  "(a/b*100)*step(b-clip_level)" \\\n', norm_signal);
00105            norm_signal = sprintf('%s    -expr  "(a/b*100)*c" \\\n', norm_signal);
00106                 else norm_signal = sprintf('%s    -expr  "a/b*100" \\\n', norm_signal);
00107                 end
00108            norm_out_fn = sprintf('%s_norm%i', InBrikPrefix, i);
00109         norm_signal = sprintf('%s    -prefix %s', norm_signal, norm_out_fn);
00110                 fprintf(2, '\nRunning: %s\n', norm_signal);
00111            fprintf(foutid_log, '%s\n', norm_signal);
00112            [s,w] = system(norm_signal);
00113       if (s),
00114          fprintf(2,'Error during 3dcalc: \n\n%s\n\n',w);
00115          while (1); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00116       end
00117         
00118         %Concatenate the above files together
00119            concat = sprintf('%s %s%s%s', concat, norm_out_fn, InBrikView, InBrikExt);
00120         
00121         %create remove command for deleting those individual percent signal change and mean file for each run.
00122            rm_cmmd = sprintf('%s %s%s%s %s%s%s', rm_cmmd, norm_out_fn, InBrikView, InBrikExt, mean_fn, InBrikView, InBrikExt);  
00123 
00124    end
00125 
00126 %Concatenate all runs back together
00127    fprintf(2, '\nRunning: %s\n', concat);
00128    fprintf(foutid_log, '%s\n', concat);
00129    [s,w] = system(concat);
00130    if (s),
00131       fprintf(2,'Error during running 3dTcat: \n\n%s\n\n',w);
00132       while (1); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00133    end  
00134 end
00135 
00136 %Don't forget to remove those temporary files above.
00137 fprintf(2, '\nRemoving: %s\n', rm_cmmd);
00138 fprintf(foutid_log, '%s\n', rm_cmmd);
00139 [s,w] = system(rm_cmmd);
00140 if (s),
00141     fprintf(2,'Error during rm: \n\n%s\n\n',w);
00142     while (1); fprintf(2,'Halted: Ctrl+c to exit'); pause; end
00143 end
00144 
00145 err = 0;
00146 return;
 

Powered by Plone

This site conforms to the following standards: