# Systematic Review of Anomaly Detection in Hyperspectral Remote Sensing Applications
## 5 Unstructured Background Models
### Nearest Neighbor Detectors  
Besides the family of the RX detectors, the detectors based on the principle of the spectrally nearest neighbors (NN) [80; 81] can be categorized as the unstructured background anomaly detectors. For the background characterization, a spectral distance of PUT to the \(C\)-nearest neighbor can be used as a detection statistic, an average distance of the PUT to the \(C\)-nearest neighbors, or a distance of the PUT to the average of the \(C\)-nearest neighbors [82]. A choice between various distance metrics could be made: Euclidean, Mahalanobis, spectral angle [83], Manhattan [84], or Chebyshev [85].  
The basic NN anomaly detector can be mathematically formulated as follows. Let \(w_{i}\) be the weight, which depends on the distance from the PUT \(\underline{x}\) and background spectral vectors \(\{\underline{x}_{i}\}\). Consider that background vectors are sorted by some distance metric to \(\underline{x}\) (such that \(\underline{x}_{1}\) is the closest). Now, a simple weight vector \(\underline{w}\) for one PUT can be determined as [82]:  
\[w_{i}=\left\{\begin{array}{ll}1,&\text{if}\;\;i\leq C\\ 0,&\text{if}\;i>C\end{array}\right., \tag{20}\]  
where \(C\) denotes the chosen number of the nearest neighbors. The detection statistic for the \(C\)-NN detector that uses the distance from the PUT (\(\underline{x}\)) to the average of \(C\)-NN can now be formulated as [82]:  
\[D_{NN}(\underline{x}|\mathcal{B})=\parallel\underline{x}-\frac{1}{N}\sum_{i= 1}^{N}w_{i}\cdot\underline{x}_{i}\parallel\begin{array}{ll}H_{1}\\ >>\\ <\\ H_{0}\end{array}\lambda \tag{21}\]  
where \(\mathcal{B}=\{w_{i},\;\underline{x}_{i}\}_{i=1}^{N}\) presents the background model determined by a weight vector \(\underline{w}\) and spectral background vectors \(\underline{x}_{i}\), and \(\parallel\parallel\) denotes the distance operator.  
The \(C\)-NN detector enables simple implementation, but its complexity depends on the selection of a distance metric. Additionally, for every PUT, the spectral distance to every background pixel needs to be calculated and sorted, which is computationally expensive. Finally, the criterion for the selection of optimal number \(C\) is not intuitively determined. It should be greater than the overall number of expected anomaly pixels, which could be difficult to foresee in real applications.  
A Euclidean distance transformation for anomaly detection in spectral imagery has been proposed by [PERSON] and [PERSON] [86]. They introduced the nearest neighbor transformation (NNT), in which the spectral \(k\)-nearest neighbors for every pixel in the HS image are determined using the ATRIA [87]. ATRIA is the algorithm, based on the Delaunay triangulation, that offers an efficient determination of a selection of the nearest neighbors. The NNT creates a new \(k\)-dimensional image where every \(i\)-th band contains the Euclidean distance of every pixel to its \(i\)-th spectrally nearest neighbor. A similar approach can also be found in the work of [PERSON] and [PERSON] [88]. The standard RX detector or some other detection statistic can then be applied to the data transformed by the NNT. The NNT can also be regarded as the preprocessing step for the anomaly detectors that use the subspace models, which are explained later in the paper.