-
Notifications
You must be signed in to change notification settings - Fork 24
/
hsi_detectors.py
58 lines (42 loc) · 1.04 KB
/
hsi_detectors.py
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
#
# hsi_detectors.py
#
# Copyright 2018 - Taylor Glenn - [email protected]
#
import numpy as np
import math
def topix(x):
return x.reshape( (x.shape[0]*x.shape[1],x.shape[2]) )
def toimg(pix,x,n_dim=None):
if n_dim is None:
n_dim = len(x.shape)
return pix.reshape(x.shape[:n_dim])
def smf_detector(x,tgt_sig,mu=None,siginv=None):
pix = topix(x)
n_pix,n_band = pix.shape
if mu is None:
mu = pix.mean(axis=0)
if siginv is None:
sig = np.cov(pix.T)
siginv = np.linalg.inv(sig)
s = tgt_sig - mu
z = pix - mu
f = s.dot(siginv) / math.sqrt(s.dot(siginv.dot(s)))
smf_data = z.dot(f)
return toimg(smf_data,x,2)
def ace_detector(x,tgt_sig,mu=None,siginv=None):
pix = topix(x)
n_pix,n_band = pix.shape
if mu is None:
mu = pix.mean(axis=0)
if siginv is None:
sig = np.cov(pix.T)
siginv = np.linalg.inv(sig)
s = tgt_sig - mu
z = pix - mu
st_siginv = s.dot(siginv)
A = z.dot(st_siginv)
B = np.sqrt(st_siginv.dot(s))
C = np.sqrt(np.sum(z * z.dot(siginv.T), axis=1))
ace_data = A/(B*C)
return toimg(ace_data,x,2)