-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwithin_voxel_z_scoring.m
41 lines (38 loc) · 1.55 KB
/
within_voxel_z_scoring.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function within_voxel_z_scoring(list_images, mask_path)
% Perform within-voxel z-scoring throughout an entire list of images
% FORMAT within_voxel_z_scoring(list_images, mask)
% list_images - cells column, each cell contains the path of one image
% mask_path - path to a binary mask to constrain the area where
% z-scoring is performed. It should be the same mask used
% for the univariate model used as input to the
% multivariate analysis
%
%
%__________________________________________________________________________
%
% The function does not return any output but each image that has been z-scored
% is saved in the exact same folder as the original with the exact same
% name but starting with the prefix 'z_'
hmask = spm_vol(mask_path);
[mask, cmask] = spm_read_vols(hmask);
cmask(4,:) = 1;
voxmask = hmask.mat\cmask;
voxmask = voxmask(:,mask > .1);
im_mean = nan(size(mask));
im_std = nan(size(mask));
mattmp = spm_get_data(list_images,voxmask(1:3,:));
mattmp_mean = mean(mattmp,1);
mattmp_sd = std(mattmp,1);
im_mean(mask > .1) = mattmp_mean;
im_std(mask > .1) = mattmp_sd;
for j = 1:size(list_images,1)
htmp = spm_vol(list_images{j});
voltmp = spm_read_vols(htmp, mask);
voltmp = (voltmp - im_mean)./im_std;
[htmppathstr, htmpname, htmpext] = fileparts(htmp.fname);
htmp.fname = fullfile(htmppathstr, ['z_' htmpname htmpext]);
htmp.dt = [64 0];
spm_write_vol(htmp, voltmp);
fprintf('saving %s \n', htmp.fname)
end
end