-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfindThreshold.m
30 lines (30 loc) · 924 Bytes
/
findThreshold.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
function bestThresh = findThreshold(iMap,tenMap)
bestThresh = 0.32;
thresh_start = 0.0001;
thresh_end = 0.32;
thresh_step = 0.01;
globalSharpness = 0;
%itterating to find best threshold
S = round((thresh_end - thresh_start)/thresh_step);
for ii=1:S
thresh = thresh_start + ii*thresh_step;
iTestMap = iMap;
iTestMap = im2bw(iTestMap,thresh);
iTestMap = ~iTestMap;
iTestMap = imdilate(iTestMap,ones(3)) - iTestMap; %identified edges
tenTestMap = iTestMap.*tenMap;
tenTestMap = tenTestMap.*iMap;
iMap = iTestMap.*iMap;
sharp_num = sum(sum(tenTestMap));
sharp_den = sum(sum(iMap));
sharpness = sharp_num/sharp_den;
if(isnan(sharpness))
break
end
% disp(sharpness);
% disp(thresh);
if(sharpness > globalSharpness)
bestThresh = thresh;
globalSharpness = sharpness;
end
end