0001 function [VY,row] = mars_image_scaling(marsD)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 VY = [];
0017 if nargin < 1
0018 marsD = [];
0019 end
0020 if isempty(marsD)
0021 mod_code = spm_input('Modality of images to scale', '+1', 'b', ...
0022 'PET|FMRI|Other', [1 2 3], 2);
0023 else
0024 mod_code = is_fmri(marsD) + 1;
0025 end
0026
0027 switch mod_code
0028 case 1
0029 dGM = 50;
0030 sess_str = 'Subject';
0031 case 2
0032 dGM = 100;
0033 sess_str = 'Session';
0034 case 3
0035 dGM = 0;
0036 sess_str = 'Subject';
0037 end
0038
0039 VY = [];
0040 Global = [];
0041
0042 [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Extract data from ROI(s)');
0043
0044
0045 if isempty(marsD)
0046 spmf = 0;
0047 else
0048 spmf = spm_input('Images from:', '+1','b',['SPM design|GUI select'], ...
0049 [1 0], 2);
0050 end
0051
0052
0053 if spmf
0054 if ~has_images(marsD);
0055 warning('Design structure does not specify images');
0056 return
0057 end
0058 VY = get_images(marsD);
0059 row = block_rows(marsD);
0060 nsess = length(row);
0061 end
0062
0063 if isempty(VY)
0064
0065 nsess = spm_input(sprintf('No of %ss', sess_str), '+1', 'r', 1, 1);
0066
0067 for s = 1:nsess
0068 simgs = spm_get(Inf, mars_veropts('get_img_ext'), ...
0069 sprintf('Data images %s %d', sess_str, s));
0070 row{s} = (1:size(simgs, 1))'+size(VY,1);
0071 VY = strvcat(VY, simgs);
0072 end
0073 end
0074 if isempty(VY), return, end
0075
0076
0077 askGMf = 1;
0078 if spmf
0079 gopts = {''};
0080 glabs = ['SPM design|' sess_str ' specific scaling',...
0081 '|Proportional scaling|Raw data'];
0082 tmp = spm_input('Scaling from:', '+1', 'm', glabs, 1:4, 1);
0083 if tmp == 1
0084 Global = [];
0085 askGMf = 0;
0086 else
0087
0088 VY = strvcat(VY(:).fname);
0089 if tmp == 2
0090 Global = 'None';
0091 elseif tmp == 3
0092 Global = 'Scale';
0093 elseif tmp == 4
0094 Global = [];
0095 end
0096 end
0097
0098 else
0099 glabs = [sess_str ' specific scaling',...
0100 '|Proportional scaling|Raw data'];
0101 tmp = spm_input('Scaling from:', '+1', 'm', glabs, [1 2 3], 1);
0102 if tmp == 1
0103 Global = 'None';
0104 elseif tmp == 2
0105 Global = 'Scale';
0106 else
0107 Global = [];
0108 end
0109 end
0110
0111
0112 GM = 0;
0113 if askGMf
0114 GM = spm_input('Scale grand mean to (0=raw)','+1','r',dGM,1);
0115 end
0116
0117
0118 if ischar(VY)
0119 fprintf('\n%-40s: %30s','Mapping files',' ')
0120 VY = spm_vol(VY);
0121 fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done')
0122 end
0123
0124
0125 if ~isempty(Global)
0126
0127
0128
0129 q = length(VY);
0130 g = zeros(q,1);
0131 fprintf('%-40s: %30s','Calculating globals',' ')
0132 for i = 1:q
0133 fprintf('%s%30s',repmat(sprintf('\b'),1,30),sprintf('%4d/%-4d',i,q))
0134 g(i) = spm_global(VY(i));
0135 end
0136 fprintf('%s%30s\n',repmat(sprintf('\b'),1,30),'...done')
0137
0138
0139 if (GM == 0)
0140 GM = mean(g);
0141 end
0142
0143
0144
0145 gSF = GM./g;
0146 if strcmp(Global,'None')
0147 for i = 1:nsess
0148 j = row{i};
0149 gSF(j) = GM./mean(g(j));
0150 end
0151 end
0152
0153
0154
0155 for i = 1:q, VY(i).pinfo(1:2,:) = VY(i).pinfo(1:2,:)*gSF(i); end
0156
0157 end
0158
0159
0160