|
62 | 62 | % rather than being a missing value) or binary map. In this case, you |
63 | 63 | % can use 'treat_zero_as_data', 1 to treat the zeros as data values. |
64 | 64 | % |
| 65 | +% **exclude_zero_mask_values** |
| 66 | +% |
65 | 67 | % :Outputs: |
66 | 68 | % **similarity_output** |
67 | 69 | % Matrix of similarity measures. |
|
138 | 140 | % than missing data |
139 | 141 | % |
140 | 142 |
|
141 | | - |
142 | 143 | % --------------------------------- |
143 | 144 | % Defaults and optional inputs |
144 | 145 | % --------------------------------- |
|
148 | 149 | doignoremissing = false; % ignore warnings for missing voxels |
149 | 150 | doprintwarnings = true; % print warnings regarding missing voxels, etc. |
150 | 151 | treat_zero_as_data = false; % Treat zero value as missing data. |
| 152 | +exclude_zero_mask_values = false; |
151 | 153 |
|
152 | 154 | if any(strcmp(varargin, 'ignore_missing')) |
153 | 155 | doignoremissing = true; |
|
181 | 183 | treat_zero_as_data = true; |
182 | 184 | end |
183 | 185 |
|
| 186 | +if any(strcmp(varargin, 'exclude_zero_mask_values')) |
| 187 | + exclude_zero_mask_values = true; |
| 188 | +end |
| 189 | + |
184 | 190 | % if docosine && docorr, error('Choose either cosine_similarity or correlation, or no optional inputs for dot product'); end |
185 | 191 |
|
186 | 192 | % --------------------------------- |
|
210 | 216 |
|
211 | 217 | end |
212 | 218 |
|
| 219 | +if exclude_zero_mask_values |
| 220 | + |
| 221 | + badvals_mask = pattern_weights == 0 | isnan(pattern_weights); |
| 222 | + |
| 223 | +else |
| 224 | + |
| 225 | + badvals_mask = isnan(pattern_weights); |
213 | 226 |
|
| 227 | +end |
214 | 228 |
|
215 | 229 |
|
216 | 230 | % --------------------------------- |
|
232 | 246 | switch sim_metric |
233 | 247 | case 'corr' |
234 | 248 |
|
235 | | - similarity_output(:, i) = image_correlation(dat, pattern_weights(:, i), badvals); |
| 249 | + similarity_output(:, i) = image_correlation(dat, pattern_weights(:, i), badvals, badvals_mask); |
236 | 250 |
|
237 | 251 | case 'cosine' |
238 | 252 |
|
|
377 | 391 | end % function |
378 | 392 |
|
379 | 393 |
|
380 | | -function r = image_correlation(dat, pattern_weights, badvals, varargin) |
| 394 | +function r = image_correlation(dat, pattern_weights, badvals, badvals_mask) |
381 | 395 |
|
382 | 396 |
|
383 | 397 | for i = 1:size(dat, 2) % Loop because we may have different voxel exclusions in each image |
384 | 398 |
|
385 | | - inmask = ~badvals(:, i); |
| 399 | + inmask = ~badvals(:, i) & ~badvals_mask(:, i); |
386 | 400 |
|
387 | 401 | r(i, 1) = corr(pattern_weights(inmask), dat(inmask, i)); % Correlation, excluding out-of-image pattern_weights image-wise |
388 | 402 |
|
|
0 commit comments