-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplyMask.m
More file actions
31 lines (25 loc) · 807 Bytes
/
Copy pathapplyMask.m
File metadata and controls
31 lines (25 loc) · 807 Bytes
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
function mri = applyMask(mri,mask)
if ischar(mask)
mask = MRIread(mask);
mask = mask.vol;
elseif isMRI(mask)
mask = mask.vol;
end
mask = logical(mask);
for sInd = 1:length(mri)
if ~isMRI(mri(sInd)) && isfield(mri(sInd),'mri')
mri(sInd).mri = applyMask(mri(sInd).mri,mask);
continue
end
if ~isempty(mri(sInd).vol) || ( isfield(mri(sInd),'vec') && ~isempty(mri(sInd).vec) )
if ~isempty(mri(sInd).vol)
mri(sInd).vol = permute(mri(sInd).vol,[4 5 6 1 2 3]);
mri(sInd).vol(:,:,:,~mask) = nan;
mri(sInd).vol = permute(mri(sInd).vol,[4 5 6 1 2 3]);
mri(sInd).vec = [];
else
mri(sInd).vec = mri(sInd).vec(:,mask(mri(sInd).vol2vec),:,:);
end
end
mri(sInd).vol2vec = mask;
end