spectralpython / spectral

Python module for hyperspectral image processing
MIT License
563 stars 138 forks source link

Add kernel matched filter #156

Open zxdawn opened 10 months ago

zxdawn commented 10 months ago

The kernel matched filter (KMF) is defined in Kwon & Nasrabadi (2007).

Briefly, Given kernel function and target/background matrix, the KMFresponse is given by:


\begin{align} 
        y(\hat{k}_r) = \frac{\hat{k}_t^T \hat{K}^{-2} \hat{k}_x}{\hat{k}_t^T \hat{K}^{-2} \hat{k}_t} \\

    where:

       \hat{k}_{t}^T=k_{t}^T-\frac{1}{N} \sum_{i=1}^N k\left(x_i, t\right) \overrightarrow{1} \\
       \hat{k}_{x}^T=k_{x}^T-\frac{1}{N} \sum_{i=1}^N k\left(x_i, x\right) \overrightarrow{1} \\

\end{align}

$\hat{K}$ is the centered kernel (Gram) matrix, K = K(X, X) = (K)ij the N × N kernel matrix whose entries are the dot products 〈φ(xi ),φ(x j )〉.

$\hat{k}$ is a kernel, such as linear kernel, polynomial kernel and Gaussian Radial Bases Function kernel (RBF).

The inverse $\hat{K}^{-2}$ may not be numerically stable if the background spectral samples are not independent. Therefore, the pseudo-inverse of K is used, which is based on eigenvalue decomposition, where eigenvectors with eigenvalues larger than eigval_min are used.

zxdawn commented 10 months ago

I have tested the preliminary version of KMF using the lan sample data and found there seems something wrong .... The notebook is on the gist.

MF

image

KMF with poly kernel

Original data: image

Normalized data: image

KMF with rbf kernel

Original data: image

Normalized data: image

tboggs commented 10 months ago

In the gist notebook, did you intend for your normalization to use an average over rows (as opposed to the entire image)? That is what your function appears to be doing.

zxdawn commented 10 months ago

Yes, because most push-broom sensors have a slightly nonuniform behavior at different cross-track positions. I see someone applied it here.

zxdawn commented 10 months ago

I have also tested with some small real data and the result is also strange. Here's the gist.