예제 #1
0
def gmrx_anomaly(hsi_img, n_comp, mask=None):
    """
	Gaussian Mixture RX Anomaly Detector
	 fits GMM assuming entire image is background
	 assigns pixels to highest posterior probability mixture component
	 computes pixel Mahlanobis distance to component mean

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_comp - number of Gaussian components to use

	Outputs:
	  gmrx_out - detector output image

	8/7/2012 - Taylor C. Glenn - [email protected]
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
    gmm_out, kwargsout = img_det(gmrx_helper,
                                 hsi_img,
                                 None,
                                 mask,
                                 n_comp=n_comp)
    return gmm_out
예제 #2
0
def ace_rt_max_detector(hsi_img, tgt_sig, mask = None, mu = None, sig_inv = None):
	"""
	Adaptive Cosine/Coherence Estimator given Multiple Target Signatures.
	Confidence value is the max ace score over all target signatures.

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x n_sig - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 mu - background mean (n_band x 1 column vector)
	 siginv - background inverse covariance (n_band x n_band matrix)

	Outputs:
	 ace_out - detector image
	 mu - mean of input data
	 siginv - inverse covariance of input data

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
	if tgt_sig.ndim == 1:
		tgt_sig = tgt_sig[:, np.newaxis]

	ace_rt_max_out, kwargsout = img_det(ace_rt_max_helper, hsi_img, tgt_sig, mask, mu = mu, sig_inv = sig_inv)
	return ace_rt_max_out, kwargsout['mu'], kwargsout['sig_inv']
예제 #3
0
def ccmf_detector(hsi_img, tgt_sig, mask = None, n_comp = 5, gmm = None):
	"""
	Class Conditional Matched Filters

	inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_comp - number of Gaussian components to use
	 gmm - optional mixture model structure from previous training data

	outputs:
	 ccmf_out - detector image
	 gmm - mixture model learned from input image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
	if tgt_sig.ndim == 1:
		tgt_sig = tgt_sig[:, np.newaxis]

	ccmf_out, kwargsout = img_det(ccmf_helper, hsi_img, tgt_sig, mask, n_comp = n_comp, gmm = gmm)

	return ccmf_out, kwargsout['gmm']
예제 #4
0
def cem_detector(hsi_img, tgt_sig, mask=None):
    """
	Constrained Energy Minimization Detector
	 solution to filter with minimum energy projected into background space

	Ref: J. C. Harsanyi, ?Detection and classification of subpixel spectral signatures in hyperspectral image sequences,? Ph.D. dissertation, University of Maryland Baltimore County, 1993.

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sigs - target signatures (n_band x n_sigs)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	 cem_out - detector image
	 w - cem filter

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    cem_out, kwargsout = img_det(cem_helper, hsi_img, tgt_sig, mask)

    return cem_out, kwargsout['w']
예제 #5
0
def palm_detector(hsi_img, tgt_sig, mask=None, n_comp=5):
    """
	Pairwise Adaptive Linear Matched Filter

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_comp - number of Gaussian components to use

	Outputs:
	 palm_out - detector image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    palm_out, kwargsout = img_det(palm_helper,
                                  hsi_img,
                                  tgt_sig,
                                  mask,
                                  n_comp=n_comp)
    return palm_out
예제 #6
0
def smf_max_detector(hsi_img, tgt_sig, mask=None, mu=None, sig_inv=None):
    """
	Spectral Matched Filter, Max over targets

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sigs - target signatures (n_band x n_signatures)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	 smf_out - detector image

	8/8/2012 - Taylor C. Glenn
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    n_sig = tgt_sig.shape[1]
    n_row, n_col, n_band = hsi_img.shape

    sig_out = np.zeros((n_row, n_col, n_sig))

    for i in range(n_sig):
        sig_out[:, :, i], kwargsout = img_det(smf_det_array_helper,
                                              hsi_img,
                                              tgt_sig[:, i][:, np.newaxis],
                                              mask,
                                              mu=mu,
                                              sig_inv=mu)

    smf_out = np.max(sig_out, 2)
    return smf_out
예제 #7
0
def spsmf_detector(hsi_img, tgt_sig, mask = None, mu = None, sig_inv = None):
	"""
	Subpixel Spectral Matched Filter
	 matched filter derived from a subpixel mixing model
	 H0: x = b
	 H1: x = alpha*s + beta*b
	 Ref: formulation from Eismann's book, pp 664

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 mu - background mean (n_band x 1 column vector)
	 siginv - background inverse covariance (n_band x n_band matrix)

	Outputs:
	 spsmf_out - detector image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
	if tgt_sig.ndim == 1:
		tgt_sig = tgt_sig[:, np.newaxis]

	spsmf_out, kwargsout = img_det(spsmf_helper, hsi_img, tgt_sig, mask, mu = mu, sig_inv = sig_inv)

	return spsmf_out
def ace_ss_detector(hsi_img, tgt_sig, mask=None, mu=None, sig_inv=None):
    """
	Adaptive Cosine/Coherence Estimator - Subspace Formulation

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sigs - target signatures (n_band x M - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	 ace_ss_out - detector image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    ace_ss_out, kwargsout = img_det(ace_ss_helper,
                                    hsi_img,
                                    tgt_sig,
                                    mask,
                                    mu=mu,
                                    sig_inv=sig_inv)
    return ace_ss_out
예제 #9
0
def ha_detector(hsi_img, tgt_sig, ems, mask=None, n_comp=2):
    """
	Hybrid Abundance Detector

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 ems - background endmembers
	 n_comp - number of mixture components for abundance mixtures

	Outputs:
	 ha_out - detector image

	8/27/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    ha_out, kwargsout = img_det(ha_helper,
                                hsi_img,
                                tgt_sig,
                                mask,
                                ems=ems,
                                n_comp=n_comp)
    return ha_out
예제 #10
0
def fcbad_anomaly(hsi_img, n_cluster, mask=None):
    """
	Fuzzy Cluster Based Anomaly Detection (FCBAD)
	Ref: Hytla, Patrick C., et al. "Anomaly detection in hyperspectral imagery: comparison of methods using diurnal and seasonal data." Journal of Applied Remote Sensing 3.1 (2009): 033546

	This algorithm requires skfuzz! https://pythonhosted.org/scikit-fuzzy/install.html

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_cluster - number of clusters to use

	Outputs:
	 fcbad_out - detector output image
	 cluster_img - cluster label image

	8/8/2012 - Taylor C. Glenn
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
    fcbad_out, kwargsout = img_det(fcbad_out_helper,
                                   hsi_img,
                                   None,
                                   mask,
                                   n_cluster=n_cluster)
    cluster_img = kwargsout['idx']
    return fcbad_out, cluster_img
예제 #11
0
def mtmf_statistic(hsi_img, tgt_sig, mask=None):
    """
	Mixture Tuned Matched Filter Infeasibility Statistic

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	 mtmf_out - MTMF infeasibility statistic
	 alpha - matched filter output

	8/12/2012 - Taylor C. Glenn - [email protected]
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    mnf_img, n_dim, mnf_vecs, mnf_eigvals, mnf_mu = mnf(hsi_img, 1)
    # tgt_sig = tgt_sig[:n_dim,0][:,np.newaxis]
    s = mnf_vecs @ (tgt_sig - mnf_mu)

    mtmf_out, kwargsout = img_det(mtmf_helper,
                                  mnf_img,
                                  s,
                                  mnf_eigvals=mnf_eigvals)

    return mtmf_out, kwargsout['alpha']
예제 #12
0
def knn_classifier(hsi_img, train_data, K, mask = None):
	"""
	 A simple K nearest neighbors classifier

	Inputs:
	  hsi_img - hyperspectral data cube (n_rows x n_cols x n_bands)
	  train_data - numpy void structure containing training data
	      		   train_data['Spectra'][0, i]: matrix containing training data from class i
				   train_data['name'][0, i]: matrix containing name of class i
	  mask - binary image indicating where to apply classifier
	  K - number of neighbors to use during classification

	10/31/2012 - Taylor C. Glenn
	05/12/2018 - Edited by Alina Zare
	10/2018 - Python Implementation by Yutai Zhou
	"""
	knn_out, kwargsout = img_det(knn_cfr, hsi_img, train_data, mask = mask, K = K);
	return knn_out
예제 #13
0
def md_anomaly(hsi_img, mask=None):
    """
	Mahalanobis Distance anomaly detector
	uses global image mean and covariance as background estimates

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	  dist_img - detector output image

	8/7/2012 - Taylor C. Glenn
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
    dist_img, kwargsout = img_det(md_helper, hsi_img, None, mask)
    return dist_img
예제 #14
0
def beta_anomaly(hsi_img, mask):
    """
	Beta Distribution Anomaly Detector
	 fits beta distribution to each band assuming entire image is background
	 computes negative log likelihood of each pixel in the model

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	  beta_out - detector output image

	8/24/2012 - Taylor C. Glenn
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
    beta_out, kwargsout = img_det(beta_helper, hsi_img, None, mask)
    return beta_out
예제 #15
0
def gmm_anomaly(hsi_img, n_comp, mask = None):
	"""
	Gaussian Mixture Model Anomaly Detector
	 fits GMM assuming entire image is background
	 computes negative log likelihood of each pixel in the fit model

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_comp - number of Gaussian components to use

	Outputs:
	  gmm_out - detector output image

	8/7/2012 - Taylor C. Glenn
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
	gmm_out, kwargsout = img_det(gmm_helper, hsi_img, None, mask, n_comp = n_comp)
	return gmm_out
예제 #16
0
def cbad_anomaly(hsi_img, n_cluster, mask = None):
	"""
	Cluster Based Anomaly Detection (CBAD)
	Ref: Carlotto, Mark J. "A cluster-based approach for detecting man-made objects and changes in imagery." IEEE Transactions on Geoscience and Remote Sensing 43.2 (2005): 374-387.

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_cluster - number of clusters to use

	Outputs:
	 cbad_out - detector output image
	 cluster_img - cluster label image

	8/7/2012 - Taylor C. Glenn
	5/5/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
	cbad_out, kwargsout = img_det(cbad_out_helper, hsi_img, None, mask, n_cluster = n_cluster)
	cluster_img = kwargsout['idx']
	return cbad_out, cluster_img
예제 #17
0
def smf_detector(hsi_img, tgt_sig, mask = None, mu = None, sig_inv = None):
	"""
	Spectral Matched Filter

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 mu - (optional) mean for filter (if not provided, computed from image)
	 siginv - (optional) inverse covariance for filter (if not provided, computed from image)

	Outputs:
	 smf_out - detector image
	 mu - mean of background
	 sig_inv - inverse covariance of background

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	10/2018 - Python Implementation by Yutai Zhou
	"""
	smf_out, kwargsout = img_det(smf_det_array_helper, hsi_img, tgt_sig, mask, mu = mu, sig_inv = sig_inv)
	return smf_out, kwargsout['mu'], kwargsout['sig_inv']
예제 #18
0
def sam_detector(hsi_img, tgt_sig, mask=None):
    """
	Spectral Angle Mapper

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used

	Outputs:
	 sam_out - detector image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    sam_out, kwargsout = img_det(sam_helper, hsi_img, tgt_sig, mask)

    return sam_out
예제 #19
0
def amsd_detector(hsi_img, tgt_sig, mask=None, n_dim_tgt=1, n_dim_bg=5):
    """
	Adaptive Matched Subspace Detector

	 Reference:
	 Hyperspectral subpixel target detection using the linear mixing model (article)
	 Manolakis, D. and Siracusa, C. and Shaw, G.
	 Geoscience and Remote Sensing, IEEE Transactions on
	 2001 Volume 39 Number 7 Pages 1392 -1409 Month jul

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sigs - target signature(s) (n_band x n_sig - column vectors)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_dim_tgt - number of dimensions to use for target subspace,
	             if argument is 0, use the target sigs themselves
	 n_dim_bg - number of dimensions to use for background subspace

	Outputs:
	 amsd_out - detector image

	8/22/2012 - Taylor C. Glenn
	6/02/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    amsd_out, kwargsout = img_det(amsd_helper,
                                  hsi_img,
                                  tgt_sig,
                                  mask,
                                  n_dim_tgt=n_dim_tgt,
                                  n_dim_bg=n_dim_bg)
    return amsd_out
예제 #20
0
def osp_detector(hsi_img, tgt_sig, mask = None, n_dim_ss = 2):
	"""
	Orthogonal Subspace Projection Detector

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 n_dim_ss - number of dimensions to use in the background subspace

	Outputs:
	 osp_out - detector image

	8/8/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	11/2018 - Python Implementation by Yutai Zhou
	"""
	if tgt_sig.ndim == 1:
		tgt_sig = tgt_sig[:, np.newaxis]

	osp_out, kwargsout = img_det(osp_helper, hsi_img, tgt_sig, mask, n_dim_ss = n_dim_ss)

	return osp_out
예제 #21
0
def abd_detector(hsi_img, tgt_sig, ems, mask=None):
    """
	Abundance of Target when unmixed with background endmembers

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 ems - background endmembers

	Outputs:
	 abd_out - detector image

	8/19/2012 - Taylor C. Glenn
	6/2/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    abd_out, kwargsout = img_det(abd_helper, hsi_img, tgt_sig, mask, ems=ems)

    return abd_out
예제 #22
0
def hua_detector(hsi_img, tgt_sig, ems, mask=None, n_comp=2, sig_inv=None):
    """
	Hybrid Unstructured Abundance Detector

	 Ref:
	 Hybrid Detectors for Subpixel Targets
	 Broadwater, J. and Chellappa, R.
	 Pattern Analysis and Machine Intelligence, IEEE Transactions on
	 2007 Volume 29 Number 11 Pages 1891 -1903 Month nov.

	Inputs:
	 hsi_image - n_row x n_col x n_band hyperspectral image
	 tgt_sig - target signature (n_band x 1 - column vector)
	 mask - binary image limiting detector operation to pixels where mask is true
	        if not present or empty, no mask restrictions are used
	 ems - background endmembers
	 siginv - background inverse covariance (n_band x n_band matrix)

	Outputs:
	 hua_out - detector image

	8/19/2012 - Taylor C. Glenn
	6/3/2018 - Edited by Alina Zare
	12/2018 - Python Implementation by Yutai Zhou
	"""
    if tgt_sig.ndim == 1:
        tgt_sig = tgt_sig[:, np.newaxis]

    hua_out, kwargsout = img_det(hua_helper,
                                 hsi_img,
                                 tgt_sig,
                                 mask,
                                 ems=ems,
                                 n_comp=n_comp,
                                 sig_inv=sig_inv)
    return hua_out