-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_make_wmmask_fsseg_rh.m
65 lines (53 loc) · 2.24 KB
/
s_make_wmmask_fsseg_rh.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
function s_make_wmmask_fsseg_rh
%
% This script makes the white-matter mask from freesurfer segmentation
%
% Copyright Franco Pestilli (c) Stanford University, 2014
% Path to subjects
datapath = '/media/lcne/matproc';
% Subject names
subjects = {'am160914'};
for isubj = 1:length(subjects)
matRoiFolder = fullfile(matProcDir,subjects{isubj},'ROIs');
% white-matter mask filename
wmMaskFile = fullfile(matRoiFolder,'rh_wmmask_fs.nii.gz');
[~,wmMaskFileName,~] = fileparts(wmMaskFile);
wmMaskFileName = wmMaskFileName(1:end-4); %strip .nii after .gz
% freesurfer segmentation filename
fs_wm = matchfiles(fullfile(matRoiFolder,'a2009seg2acpc.nii.gz'));
% perform mri_convert to ensure freesurfer file is RAS
% only include segmentation / parcellation values defined below
eval(sprintf('!mri_convert --out_orientation RAS %s %s', fs_wm{1}, wmMaskFile));
wm = niftiRead(wmMaskFile);
invals = [16 41 49 50 51 52 58 60 12106 12113 12115 12116 12117 12118 12124 12139 12148 12149 12155 12163 12164 12165];
origvals = unique(wm.data(:));
fprintf('\n[%s] Converting voxels... ',mfilename);
wmCounter=0;noWMCounter=0;
for ii = 1:length(origvals);
if any(origvals(ii) == invals)
wm.data( wm.data == origvals(ii) ) = 1;
wmCounter=wmCounter+1;
else
wm.data( wm.data == origvals(ii) ) = 0;
noWMCounter = noWMCounter + 1;
end
end
fprintf('converted %i regions to White-matter (%i regions left outside of WM)\n\n',wmCounter,noWMCounter);
niftiWrite(wm);
%convert nifti to mat
im=niftiRead(wmMaskFile);
wmMaskRoiMat = fullfile(matRoiFolder,[wmMaskFileName, '.mat']);
%now we want to convert the image to a list of coordinates in acpc space
%find roi index locations
ndx=find(im.data);
%convert to ijk coords
[I J K]=ind2sub(size(im.data),ndx);
%convert to acpc coords
acpcCoords=mrAnatXformCoords(im.qto_xyz, [I J K]);
%now put these coordinates into the mrDiffusion roi structure
roi=dtiNewRoi(wmMaskRoiMat,'r',acpcCoords);
%save out the roi
dtiWriteRoi(roi,wmMaskRoiMat);
fprintf('\nwriting file %s\n',fullfile(wmMaskRoiMat));
end
end