forked from netstim/leaddbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ea_detthresh.m
56 lines (55 loc) · 1.99 KB
/
ea_detthresh.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
function thresh=ea_detthresh(atlases,atlas,img)
% Function that will return the threshold according to user settings for a
% specific region in the atlas.
%
% USAGE:
%
% thresh = ea_detthresh(atlases,atlas,img)
%
% INPUTS:
% atlases: structure loaded from 'atlas_index.mat' under atlas folder
% atlas: index of query region (needed when the threshold preset is a vector)
% img: 3D image data of the query region, used to determine the real
% threshold in case of relative threshold used
%
% OUTPUT:
% thresh: threshold to be applied to the region defined in the atlas
%
% .. AUTHOR:
% - Andreas Horn, Original file
% - Daniel Duarte, Documentation
if isfield(atlases,'threshold')
switch atlases.threshold.type
case 'percentage'
try
sso=sort(img(img>0));
thresh=sso(round(length(sso)*(1-atlases.threshold.value))); % preserve % of voxels.
catch
thresh=sso(1);
end
case 'percentage_vector'
sso=sort(img(img>0));
if atlases.threshold.value(atlas)==1 % include everything
thresh=sso(end)-eps;
else
try
thresh=sso(round(length(sso)*(1-atlases.threshold.value(atlas)))); % preserve % of voxels.
catch
thresh=sso(1);
end
end
case 'relative_intensity'
thresh=max(img(:))*(1-atlases.threshold.value);
case 'relative_intensity_vector'
thresh=max(img(:))*(1-atlases.threshold.value(atlas));
case 'absolute_intensity'
thresh=atlases.threshold.value;
case 'absolute_intensity_vector'
thresh=atlases.threshold.value(atlas);
otherwise
warning(['Threshold type not recognized: ',atlases.threshold.type,'. Overwriting with default.']);
thresh=max(img(:))*0.5;
end
else
thresh=max(img(:))*0.5;
end