Newer
Older
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import numpy as np
def conf_test(rad, thr):
'''
Assuming a linear function between min and max confidence level, the plot below shows
how the confidence (y axis) is computed as function of radiance (x axis).
This case illustrates alpha < gamma, obviously in case alpha > gamma, the plot would be
flipped.
gamma
c 1 ________
o | /
n | /
f | /
i | beta /
d 1/2 |....../
e | /
n | /
c | /
e 0________/
| alpha
--------- radiance ---------->
'''
radshape = rad.shape
rad = rad.reshape(np.prod(radshape))
if thr.ndim == 1:
thr = np.full((rad.shape[0], 4), thr[:4]).T
coeff = np.power(2, (thr[3] - 1))
hicut = thr[0]
beta = thr[1]
locut = thr[2]
power = thr[3]
confidence = np.zeros(rad.shape)
alpha, gamma = np.empty(rad.shape), np.empty(rad.shape)
flipped = np.zeros(rad.shape)
# if thr.ndim == 2:
gamma[hicut > locut] = thr[0, hicut > locut]
alpha[hicut > locut] = thr[2, hicut > locut]
flipped[hicut > locut] = False
gamma[hicut < locut] = thr[2, hicut < locut]
alpha[hicut < locut] = thr[0, hicut < locut]
flipped[hicut < locut] = True
# else:
# gamma[hicut > locut] = thr[0]
# alpha[hicut > locut] = thr[2]
# flipped[hicut > locut] = False
# gamma[hicut < locut] = thr[2]
# alpha[hicut < locut] = thr[0]
# flipped[hicut < locut] = True
# Rad between alpha and beta
# range_ = 2. * (beta - alpha)
# s1 = (rad[rad <= beta] - alpha) / range_
# if flipped is False:
# confidence[rad <= beta] = coeff * np.power(s1, power)
# if flipped is True:
# confidence[rad <= beta] = 1. - (coeff * np.power(s1, power))
range_ = 2. * (beta - alpha)
s1 = (rad - alpha) / range_
idx = np.nonzero((rad <= beta) & (flipped is False))
confidence[idx] = coeff[idx] * np.power(s1[idx], power[idx])
idx = np.nonzero((rad <= beta) & (flipped is True))
confidence[idx] = coeff[idx] * np.power(s1[idx], power[idx])
# Rad between beta and gamma
# range_ = 2. * (beta - gamma)
# s1 = (rad[rad > beta] - gamma) / range_
# if flipped is False:
# confidence[rad > beta] = 1. - (coeff * np.power(s1, power))
# if flipped is True:
# confidence[rad > beta] = coeff * np.power(s1, power)
range_ = 2. * (beta - gamma)
s1 = (rad - alpha) / range_
idx = np.nonzero((rad > beta) & (flipped is False))
confidence[idx] = coeff[idx] * np.power(s1[idx], power[idx])
idx = np.nonzero((rad > beta) & (flipped is True))
confidence[idx] = coeff[idx] * np.power(s1[idx], power[idx])
# Rad outside alpha-gamma interval
confidence[(rad > gamma) & (flipped is False)] = 1
confidence[(rad < alpha) & (flipped is False)] = 0
confidence[(rad > gamma) & (flipped is True)] = 0
confidence[(rad < alpha) & (flipped is True)] = 1
confidence[confidence > 1] = 1
confidence[confidence < 0] = 0
return confidence