Context-free hyperspectral image enhancement for wide-field optical biomarker visualization.

Many well-known algorithms for the color enhancement of hyperspectral measurements in biomedical imaging are based on statistical assumptions that vary greatly with respect to the proportions of different pixels that appear in a given image, and thus may thwart their application in a surgical environment. This article attempts to explain why this occurs with SVD-based enhancement methods, and proposes the separation of spectral enhancement from analysis. The resulting method, termed affinity-based color enhancement, or ACE for short, achieves multi- and hyperspectral image coloring and contrast based on current spectral affinity metrics that can physically relate spectral data to a particular biomarker. This produces tunable, real-time results which are analogous to the current state-of-the-art algorithms, without suffering any of their inherent context-dependent limitations. Two applications of this method are shown as application examples: vein contrast enhancement and high-precision chromophore concentration estimation.


Introduction
Color reconstruction of multi-and hyperspectral images (MSI/HSI) is, without a doubt, a mature field of research. As could be expected, given the vast amount of information contained in HSI data, translating this inherently physical content into color pictures has always been a fundamental objective. There are several ways to achieve this, but two are particularly frequent, namely (1) generating a false-color image from an a priori calculated magnitude and (2) using Color Matching Functions (CMFs) -as defined by the International Commision on Illumination (CIE)on carefully modified spectra so that only some pixels with particular spectral properties turn to a different color. The origins of both techniques date back to the 1970s [1], and were typically employed in the analysis of multispectral remote sensing measurements [2][3][4][5][6][7][8][9]. In these methods, color reconstructions are obtained by integrating spectra with the CMFs, with varying degrees of success in improving contrast in such representations.
Highlighting abnormal spectral variations within an image has been of particular interest in the past decade in Biomedical Optics research, and thus much work has been dedicated to translating these ideas to biomedical images. The main focus of these methods is to make spectral anomalies significantly more visible in color reconstructions of MSI/HSI images, obtaining an intuitive, direct visual outlier and anomaly inspection and detection framework. Examples include changing RGB channels from entropy measures of spectral information to enhance contrast in gastrointestinal HSI images [10], or extracting sublingual veins from hyperspectral images [11], as well as vein identification via blending NIR and VisNIR data [12]. However, the most significant references are the results and findings of M. Mitsui et al. [13] and N. Hashimoto et al. [14], in which abnormal variations across different wavelengths can be enhanced or turned into a different color. This procedure -highlighting or enhancing multispectral image abnormalities on different wavelengths-provides stunning visual results that implicitly relate to the physical properties of the biological material being sampled. As a consequence, these methods have been tested in ex vivo samples of breast tissue tumorectomies [15], palm vein visualization [16], multispectral images of Hematoxylin-and-Eosin (H&E) stained histological sections [17,18], as well as in vivo fluorescence-guided surgery in animal models [19]. Other methods, less related to colorimetry or biomedical optics, use the same methodology as a core component in anomaly detection for HSI remote sensing images [20], detecting bruises in apples in the Vis-NIR range [21], or for background segmentation for human detection algorithms using HSI images of the ocean [22].
In these applications, spectra are arranged in a matrix as column vectors, and Principal Component Analysis (PCA) is used to find a small set of basis vectors that can explain most of their variance, under the assumption that high-dimensional spectra actually lay in a lowdimensional manifold that can be inferred linearly. This effectively serves as a lossy compression algorithm, in which any spectrum can be specified with a few coordinates. If there are spectral features that differentiate a particular spectrum from more typical signatures, such features are exaggerated in the spectrum, producing significant contrast once the image is converted to RGB.
Unfortunately, this procedure is deeply context-dependent, as PCA exploits one well-known dimensionality reduction method from Linear Algebra, the Singular Value Decomposition (SVD) of a matrix. The SVD can be understood as an operator with provable uniqueness and, therefore, in the context of multi-and hyperspectral imaging of malignant tissue in surgical applications, its exploitation could be problematic. If the SVD provides a different result when provided different spectra in different amounts, the output singular vectors will not be the same on different images, and thus the enhancement results cannot be systematically repeatable. Such notions are mentioned in previous work [9,23], but are not further studied or analyzed. Similar problems could be faced by other methods that use context information to obtain results, such as ICA [24]. There is, thus, a requirement for a colorimetric enhancement method that only highlights desired information in a controllable and constrained fashion.
This work attempts to understand the aforementioned issues, and provide an improvement upon current techniques. First, we must describe the theoretical context and framework for hyperspectral enhancement as a spectral anomaly enhancement method, and provide proofs and examples that explain the fundamental issues shown in our experiments. Second, we propose a solution which uses a much simpler color enhancement framework, supported by a set of affinity or similarity functions that will provide the same results independently from the context of the image. We then define tunable contrast, gain and threshold parameters for color enhancement of any particular affinity function, having in mind its use in a fast-paced, timely surgical environment. Many state-of-the-art spectral optical quantification and classification algorithms could exploit the proposed method and enhance images in real time, so two applications (vein visualization and chromophore quantification) are presented. These novel solutions cannot be approached by the previously described enhancement methods, ensuring the practical applicability of the proposed methodology in a clinical setting.

Imaging equipment, preprocessing and reflectance calculations
The imaging system used for hyperspectral image capture is a custom-built hyperspectral scanning system, with an embedded computer for storage and control [25]. A general description is left in Table 1. Its fundamental optical components are an ImSpector V10E spectrograph (Specim, Spectral Imaging Ltd., Finland) paired with a generic C-mount objective lens and CMOS (Mako G-223B NIR, Allied Vision Technologies GmbH., Germany). Hot pixels due to long exposure times were corrected via dark image substraction as well as a spatial median filter of size 2. In order to obtain reflectance images, each measurement was calibrated with a white reference image at the same distance and lighting conditions. Reflectance R(λ), therefore, was calculated with the well-known equation where I s (λ) is the sample intensity measurement, I w (λ) is a white reference image under identical illumination conditions, and I bg is the background intensity due to hot pixels in the sensor. Throughout the manuscript, we will only employ reflectance images, where this calibration operation is performed, compensating for light source variability. Wavelength calibration was achieved through linear least-squares on a set of 3 known absorption peaks from a Spectralon Wavelength Calibration Standard (WCS), namely WCS-MC-020 (Labsphere, Inc. New Hampshire, USA) [26]. Relevant specifications of the imaging system are left in Table 1.

Color reconstruction
Spectra will be transformed into RGB images by using well-known methods in colorimetry. More specifically, we will use CIE 1931 Standard Observer Color Matching Functions (CMFs), which describe retinal perception of color as the sum of three stimuli. Given a sampled spectrum r ∈ R l , with l being the number of sampled channels and/or wavelengths, the CIE 1931 tristimulus values (X, Y, Z) can be approximated by Riemannian sums as follows [27]: where r = (r 1 , . . . , r l ) T is the reflectance vector, s = (s 1 , . . . , s l ) T is the power spectral density of a CIE standard light source,x,ȳ,z ∈ R l are the CMFs for a secondary light source as the colorimetric stimulus, i.e. the dot product φ = r s, and finally ∆λ is the spectral resolution. Finally, k is a normalization constant, which for secondary light sources is defined as Conversion from XYZ to RGB space was achieved with skimage.color, a Python 3 library.

Existing enhancement methods
A brief description of the algorithms that exploit PCA/SVD should be included. In particular, we will address the methods in [13] and [14,28] for multispectral enhancement. Both algorithms treat spectra in the same fashion. For the following discussion, let us arrange our n spectra as column vectors in a matrix R ∈ R l×n , i.e. R = (r 1 , . . . , r n ) T , where r i corresponds to a single spectrum, with l channels (or sample wavelengths) in total. For a single spectrum r i , its enhanced spectrum is calculated via where W ∈ R l×l is defined as the enhancement matrix, r i is the original pixel, and s i is an m-rank approximation of spectrum r i , namely and here {u j } are the left singular vectors of matrix R, α i,j = r i −r, u j is the projection of r i −r onto the j-th left singular vector, andr = 1 N n i=1 r i is the average spectrum. It is possible to rewrite these methods, understanding that we are in fact assuming that every spectrum can be expressed as the sum of four values, namely being s i the m-rank approximation of spectrum r i , d i = r i − s i is our desired vector of differences among spectra that we (ideally) wish to highlight, and n i is additive gaussian noise (r is still the average spectrum). The methods differ, therefore, by choosing W wisely, resulting in different enhancement images. Mitsui et al.'s method [13] has the objective of highlighting uncommon variations of spectra with respect to the average spectrum and to its m-rank approximation, and then exaggerating those differences selectively, depending on the wavelength we wish to enhance. In particular, W is a diagonal matrix with all of its entries set to zero except for a single channel: W = diag(w), {w i } = 0, ∀i q, and w q = k ∈ R + . The term k usually receives the name of enhancement gain. Hashimoto et al.'s method [14], on the other hand, adds color to the spectrum as a function of this same residual variation, and therefore chooses to create W as a set of column vectors, W = (w 1 , . . . , w l ), where every column is a vector of zeroes {w i } = 0, except for the qth channel, the channel whose variation we wish to highlight: w q = k · c, and here c ∈ R l is a particular desired color, synthesized in the wavelengths described by the l channels. Variable k is still the enhancement gain, a positive real number.

Singular value decomposition of a matrix
The Singular Value Decomposition of a matrix A ∈ R m×n is the factorization where the orthogonal column vectors in U = (u 1 , . . . , u r ) T are known as the left singular vectors of A, Σ = diag(σ 1 , . . . , σ r ) is a diagonal matrix whose main diagonal values are called A's singular values, and V = (v 1 , . . . , v r ) T are its right singular vectors. Finally, r = rank(A) is the rank of the matrix. The SVD is used in many classification problems as a means of dimensionality reduction of large vectors. This is due to the fact that the SVD can be understood as a lossy compression algorithm, . . , v k ) T , and k r, is known as the k-rank approximation of matrix A, an approximation with a known theoretical error [29], namely A −Ã k F = σ k+1 .
Another way of understanding the SVD of a matrix is by describing it as a quadratic optimization problem. The following definitions will be helpful in the coming sections: Definition 1 (First singular value of a matrix as an optimization problem) The first left singular vector of matrix A ∈ R m×n , u 1 , is the solution of the following optimization problem: and its corresponding singular value and right singular vector are defined by This first definition simply states that the first left singular vector is the only vector with unit norm that is most 'similar' (in terms of dot product magnitude) to all the column vectors in the matrix. In statistical terms, this is equivalent to finding the first vector that maximizes the explained variance with respect to all the columns in A (or, alternatively, the vector that explains most columns of covariance matrix A T A). In other words, u 1 is the vector that best explains the columns in A with the smallest possible error. The error in this approximation is i.e. the next singular value.

Definition 2 (Singular values of a matrix as an optimization problem) The i-th left singular vector of matrix
and its corresponding singular value and right singular vector are, respectively, The proof of these two statements are left in [30]. Once described in this manner, the SVD of A can be calculated. The solution, A = UΣV T , has a set of properties that are certainly appealing, due to the fact that the most frequent and relevant features can be seen in the first singular vectors. Unfortunately, these definitions are rather obscure which, combined with the visible features in the output of the numerical methods, may suggest assuming that a specific singular vector is associated with a specific feature, or that for every A the number of singular vectors needed to explain all the variance is always the same. Both of these assumptions are easily refuted by the following theorem: Theorem 1 (Uniqueness of the SVD of a matrix) Every matrix A ∈ C m×n has a singular value decomposition. Its singular values {σ j } are uniquely determined and, if A is square and the σ j are distinct, the left and right singular vectors {u j } and {v j } are uniquely determined up to complex signs.
The proof of this theorem is left in the Refs. [29][30][31], is sufficient to reject methods that use the SVD in a case-by-case basis, and is well beyond the scope of this article. Despite this fact, it can be insightful to find some example problems and study their properties, in order to improve our understanding of the effects that the magnitude and frequency of appearance of measured spectra produce on the output of the SVD.

Understanding why the SVD is context-dependent
The following exercise shows how PCA/SVD provides different results depending on how well-balanced the input dataset is. We will work with a matrix A with specific properties in their columns, and will show what is returned by the SVD by obtaining its singular vectors and values by hand. Measured spectra will be represented by column vectors in a matrix. This example will consist of a matrix with three different types of spectra repeated over the columns.
Proposition 1 Let α, β, γ ∈ N − {0}, and let a 1 , a 2 , a 3 ∈ R n be three column vectors such that a i × a j 0, a i , a j >0 , ∀i j. Let matrix A ∈ R m×n be a matrix with the following structure: The left singular vectors u 1 , u 2 , u 3 ∈ R n of matrix A are: We only need to rewrite the optimization problem from Definition 1 by introducing our new description for A. By using Lagrange multipliers, the optimization problem becomes and its solution can be found by means of the gradient or, equivalently, solving the eigenvalue problem which, given that rank(Q 1 ) = 1 and that Q 1 = (αa 1 + βa 2 + γa 3 )(αa 1 + βa 2 + γa 3 ) T , implies that the only possible solution is (αa 1 + βa 2 + γa 3 ) with multiplicity 1: The subsequent singular vectors can be obtained by applying Definition 2 directly. For the second singular vector, the problem can be rewritten, noting that u 1 σ 1 v T 1 = u 1 u T 1 A by virtue of Eq. (9), as which, given the properties of A, allows us to write via the following change of variable: The solution is, again, solving the eigenvalue problem Therefore, the solution for the second left singular vector u 2 is analogous to the second one, namely The rest of the singular vectors up to u r with r = rank(A) can be obtained by induction and using the same change of variable.
In summary, when applying the SVD to a set of spectra belonging to three similar (yet different) categories, the first singular vector (the vector that explains most spectra) will be near identical to the most frequent spectrum. The second singular vector will be similar to the most typical column in A, after subtracting what was explained by the first singular vector. This goes on recursively until there is no information to explain. Additionally, if vectors are proportional to one another, we will find similar undesired relationships.
A practical example of Proposition 1 is shown in Fig. 1. Each row represents a different selection of column vectors for A. The leftmost subfigure in each row shows the column vectors that compose a given matrix. The amount of column vectors of each type in the matrix are described in the legend. The other three plots show the first, second, and third left singular vectors, respectively, of a matrix with such composition. The blue and green plots in each subfigure represent the results obtained numerically via numpy.linalg.svd(), i.e. ±u i , due to the fact that the numerical method outputs each basis vector with sign indeterminacy. The black, dotted plot that is plotted over either +u i or −u i is the theoretical solution given by Proposition 1. For this example, we have used a = 0.5(1 + cos(2π(0.1)x)), b = 0.5 cos(2π(0.35)x), and with µ = −4 and σ = 4 as a small Gaussian peak anomaly in the 'spectra'. For the first hypothesis (first row of the figure), α = β = γ = 50 will be used, with a 1 = a, a 2 = a + b, and a 3 = a + b + c. Since all three vectors cannot be expressed as a sum of the other two, rank(A) = 3. As expected, u 1 is more similar to a, then u 2 is more similar to b, and finally u 3 is more similar to c. The second row shows a different hypothesis, where a 1 = a 2 = a and a 3 = a + c. Here, rank(A) = 2, and u 1 is mostly similar (dot product-wise) to a, while u 2 tends to look like c. The third left singular vector, both in the theoretical and numerical case, just represents quantization noise due to using double floating point precision, not representing anything significant (as expected).
In the context of image enhancement, we must assume some value of m in Eq. (6). Information given by the first m singular values will be discarded, and the variations among spectra beyond those vectors will be amplified. The values showcased by the first m singular values will be representative of the most frequent, most common spectra, and this result will certainly vary across hyperspectral images. The differences we will enhance, therefore, may be obscured partially or completely, depending on the image we are working with: • If m is exactly right, then s i ≈ r i − (d i + n i ), and we will be amplifying exactly the differences we wish to observe: r e,i = W(r i − s i ) + r i ≈ W(d i + n i ) + r i ≈ Wd i + r i . • If m is lower than necessary, then lim m→1 (s i ) = r i − (r i + d i + n i ), where r i is information that is common to a large number of spectra, thus obtaining a suboptimal enhancement, that is where r i will be common amongst large amounts of spectra, and thus contrast will be lost.
• Finally, if m is too large, then lim m→n − (s i ) = r i − n i and, then, we will only be amplifying noise: r e,i = W(r i − s i ) + r i → W(r i − r i + n i ) + r i = Wn i + r i .

Affinity-based color enhancement (ACE)
If we rearrange a hyperspectral image as a matrix A with its columns corresponding to hyperspectral pixels, the result obtained through the SVD is certainly dependent of the types of spectra that are present in the image. When working in a surgical environment, with constant artifacts and objects appearing and disappearing from the field of view, any enhancement method that exploits the SVD of data has the risk of either compromising image contrast, or producing unwanted enhancement results, depending on the types of spectra present in the image.
To overcome this problem, we must modify the response of the CIE CMF functions in a consistent and systematic way. The following method can produce the same results shown in state-of-the-art work, by separating diagnosis-related calculations from color enhancement. The only restriction is that the analytical calculation must highlight the same type of spectral responses, regardless of what is present in the image.
The proposed novel framework is summarized in Fig. 2. From now on, we will refer to references as vectors that resemble a specific spectral signature of interest, w ∈ R l . From a practical standpoint, for example, we could study oxy-and deoxyhaemoglobin, fat, or water extinction coefficients, sampled at l different wavelengths. Secondly, we will use the name spectral affinity or spectral similarity for any mapping that compares two vectors of the same type (a : R l × R l → R), or any mapping that provides some type of measure as a function of the type of spectrum and some internal parameters (a : (R l , θ) → R). When an affinity function outputs high values when comparing two spectra, we will consider those spectra as similar. A method that exploits this separation between affinity functions and spectral enhancement will be in effect a type of affinity-based color enhancement algorithm (ACE). An ACE method combines a case-specific affinity metric, with a fully-customizable color enhancement method. This adds flexibility as well as reliability to the procedure, since there may be a multitude of affinity metrics that are not context dependent, which can now be used. For the following examples, we will consider that there exists an affinity function that generates an affinity value a i = a(r i ) for every spectrum, thus providing an affinity map {a i }. For this manuscript, we propose the following spectral enhancement function: where r e,i is the enhanced output, r i is the original spectrum, K will be is the enhancement gain of the method, c e is the desired output color of the enhancement, tanh(.) is the hyperbolic tangent function, k is a contrast gain, b is a threshold value, andâ i is the affinity measure value of the spectrum when all the spectra are normalized in the range [0, 1], namelyâ i = a i −a min a max −a min . The values a min and a max should be known beforehand, by selecting an appropriate affinity metric.

Affinity metrics
The final enhancement operation should be performed with an appropriate affinity map containing the diagnostic and/or quantification information we wish to highlight. The following methods provide a bounded scalar result obtained from different types of input vector data. These methods are well known and already used in various specific classification tasks, and could be used to provide a useful affinity map for the ACE method.
Spectral Angle Mapper (SAM) Given a reference spectrum w ∈ R n , the affinity of any spectrum r i with w can be calculated by the dot product a i = wr T i . Since wr T i is the cosine of the angle between these two vectors, this function is bounded (a i ∈ [0, 1]) [32].
Nonparametric kernel density estimation (KDE). Kernel density estimation attempts to infer the probability density function (PDF) of an arbitrary multivariate distribution from a series of sample vectors w 1 , . . . , w N ∈ R n , which act as a Ref. [33].
Neural networks This will be our preferred method, since it is rather flexible when compared to other procedures. A typical neural network with a sigmoid output layer is typically the best for extracting a smooth probability map. Instead of working with binary classification, the response of each output neuron can be used to encode color at various wavelengths and intensities.
• For the vein enhancement example, a 6 × 100 ELU feedforward network is prepared, with a 281 × 1 input layer and a sigmoidal 3 × 1 output layer. The three classes to classify are Background, Skin and Veins. A total of 600 spectra were manually picked, using an 850-nm reflectance image as reference, and the network is tested for the rest of the data and other images.
• In the case of chromophore concentration estimations, another 6 × 100 ELU feedforward network is trained. This network has also a 281 × 1 input layer, but a 8 × 1 sigmoid output layer. The concentration c i for a given spectrum is easily interpolated from the output layer of the network via a simple expression, namely withŷ 0 , . . . ,ŷ 7 being each of the output neurons, which will be trained to fire to detect red ink concentrations of 0%, . . . , 70%, respectively. If we seek a specific objective concentration c obj , then an affinity metric for a concentration estimate can be where σ(.) is the sigmoid function σ(x) = 1/(1 + e −x ), and h ∈ R + serves as an affinity bandwidth, narrowing the allowed distances that can be considered proximal to the objective concentration c obj (the higher h is, the closer the concentration must be to c obj to be considered similar). This function is bounded (a i ∈ [0, 1]) and thus will be useful for concentration detection.

Results and discussion
The following experiments have been carried out to show the sensitivity of the SVD to changes in the input image, and its effect on typical color enhancement, as well as to showcase the enhancement capabilities of the ACE method. Once we show the context-dependent variability of using PCA/SVD for analysis, we provide some example uses of ACE that, unfortunately, cannot be implemented with merely enhancing the differences that remain past the first singular vectors.

Susceptibility of current methods to changes in the environment
To compare the performance of current methodology against ACE, we have chosen to replicate the results in vein enhancement that exploited PCA [14,16,28], and then force the method to fail by changing the background. Given the considerations in Section 2.5, we can hypothesize that, by changing the background color of an HSI image of a hand, spectral enhancement will be worsened when the background is most similar to the diffuse spectral response of veins, and amplified when it is as different to vein diffuse spectra as possible. Such susceptibility is exactly what was found in the experiments. Figure 3 shows the behavior of current enhancement methods for vein visualization and enhancement as a function of m, i.e. the number of left singular vectors that are ignored in the enhancement. This result was obtained with K = 30 and enhancing in the 600 − 620 nanometer wavelength range. As expected, the value of m that enhances the veins varies depending on the background color. Given a black background (first row), the first enhanced features are the shadows within the fingers; then, veins are enhanced as blue. Deep veins will appear blue due to the strong scattering properties of skin, and thus this feature is enhanced, as it is the least frequent of the four present (skin, background, shadows, and veins). With a blue background, blue spectra is not considered as rare, and is explained by the first left singular vectors, hindering vein contrast as m increases. Furthermore, areas that typically present more oxygenated hemoglobin content, such as the fingertips, are enhanced instead. Finally, given a red background, bluish spectra is the least frequent type of signature, and thus anything with properties akin to blue spectra will be enhanced, also losing contrast.
While this sort of behavior is not necessarily fundamentally flawed (this is the expected behavior of the algorithm), for in vivo imaging this implies that contrast will fluctuate as different sorts of spectra are presented to the camera in various proportions. For example, in the case of margin delineation, tumors may be accentuated if surrounded by adipose tissue, or darkened if surrounded by normal or connective tissue (adipose and normal tissue can present lower and higher scattering coefficients and average reflectance than malignant tissue, respectively) [15,34]. These inconsistencies may be problematic in a clinical setting, explaining the motivation behind this desired improvement, and providing an insight on how these techniques cannot be exploited for specific applications unless the dependency with the SVD is avoided.

Vein visualization and enhancement
Once we have observed how traditional methods are susceptible to changes unrelated to the task at hand, we must repeat the experiment with the proposed methodology. Figure 4 shows how ACE can be applied to vein visualization, showing its resilience against changes in context, background, and illumination. Note that this example is only shown for illustrative purposes but, to avoid overfitting, dropout with p = 0.1 probability was also introduced. In Fig. 4.(a), the points from the first image used to train the model are shown. The affinity function that produces each of the presented maps isŷ 2 −ŷ 1 , that is, subtracting the output unit value for skin from the output unit for vein spectra, for each of the spectra presented to the network. This forces the affinity map range to take values within [−1, 1], which is then normalized to [0, 1].
The network never sees the other two images (blue and red background) during training, yet is able to highlight the same veins that could be seen at 850 nm in the image with a black background. Although the background is slightly modified due to the enhancement process, the technique does not show variability on skin and/or vein regions. For the cases shown in Fig. 4(e) through (g), the parameter values were K = −5.0, k = 0.75, b = −0.75. Setting K = −5 implies reducing brightness to the veins, k = 0.75 was chosen to avoid a very abrupt change in color, and b = −0.75 signifies that approximately the upper quartile of the affinity map will be enhanced. These parameters were manually tuned to get the desired result. The selected enhancement color is a positive constant for the first 100 wavelengths (equal to one), thus producing a general darkening of the vein regions, replicating the images in the near infrared while still including color information. In order to test the flexibility of the presented method, various values of K, k, and b are also shown (Fig. 5), as well as the enhancement wavelength. Being able to change not only gain K, but also contrast gain k and thresholding value b, as well as the output enhancement wavelength, provides a rather simple 4-parameter method that can be modified in real time during surgery. Compared to other similar methods [11,12,16], our technique allows for vein visualization regardless of the background data, and with no motion artifacts due to capturing Vis and NIR images separately. The method can be deployed to any HSI system, no matter the configuration. Furthermore, the neural network that performs the vein detection method could be better trained to be resilient to noise, absorption and scattering-based artifacts, or skin pigmentation, without requiring any further changes in the algorithm or the imaging system.

Chromophore concentration estimation
Now that we have a method that is resilient to changes in the background, we can test out other applications that cannot be solved with unsupervised color enhancement. This example shows an application of ACE in the area of optical property and chromophore concentration estimation. The experiment shown in Figs. 6 and 7 consists of a series of liquid phantoms prepared with mixtures of 10% Intralipid and red ink. More specifically, 0%, 10%, 20%, 30%, 40%, 50%, 60%, and 70% ink-to-Intralipid concentration ratios were obtained. Two phantoms per concentration ratio were prepared for training the network (lowest two rows of phantoms), and a validation set of 8 phantoms was obtained as well (top row, one phantom per concentration).   6. Generating an affinity metric for precise chromophore quantification. A series of liquid phantoms with known concentrations are prepared (a); the dataset is divided into training (marked with a T) and validation (marked with a V) sets (b). The network outputs a complete concentration estimation map (c) which can be quantitatively evaluated (d). Once the concentration estimates are deemed accurate enough, the metrics devised in Section 2. allow for full control of the distance to a specific concentration (in this case, 40%) by varying the affinity bandwidth (e). This metric can now be used for ACE for any specific chromophore concentration.  Fig. 6(a) and (b) show a color reconstruction of the phantoms, and the manually selected circular regions of interest (ROIs), respectively. In Fig. 6(c), the concentration estimates given by the trained neural network are presented. Validation of the estimator is shown in 6(d).

Subplots in
Finally, (e) shows how affinity contrast can be controlled via Eq. (20). In this example, the tolerance of what can be considered a reflectance similar to 40% concentration is tuned, by varying h (the affinity bandwidth). The higher h is, the more stringent the affinity function becomes.
Once a functional affinity function is found, then hyperspectral enhancement can take place. Figure 7 shows the result of enhancing the 40% concentration estimates given by the affinity function. The first column shows a variation in enhancement gain K, and the second presents the response of the CMFs to enhancement contrast k. The third column shows how the output enhancement color can be selected at every specific value of the visible electromagnetic spectrum. If more than one fluorophore is utilized in guided surgery, for example, this tool may allow for the selection of the desired enhancement wavelengths and output colors, perhaps improving the existing contrast already provided by the fluorescent substances.
Diagnostic-based contrast control shows potential applicability with other optical methods, such as fluorescence-guided surgery, SFDI/SSOP or qF-SSOP, as long as the methods can provide an affinity metric that is specific to the problem at hand (e.g., tissue oxygenation, burn severity, vasculature functionality, optical properties, fluorophore concentration, and fluorophore bleaching, among others) [35,36]. This type of control can be adjusted as shown, depending on the type of surgery being performed. Ideally, with an adequate optical property estimation system, the color reconstruction could be enhanced in real time by ACE, depending on the exact information that we wished to observe.

Conclusion
In this work, the main concerns regarding the sensitivity to changes of current hyperspectral enhancement methods have been addressed, and a solution inspired in their original formulation is proposed. With a series of adequate affinity functions, the current state-of-the-art methods can be improved in terms of consistency and repeatability.
The method, herein termed affinity-based color enhancement, or ACE for short, separates the similarity metric from the enhancement process. Results shown in this manuscript only apply the method two particular examples, namely chromophore quantification or detection and vein enhancement, but the possible uses of ACE are only bounded by the affinity metrics that can be found for a specific problem, and by whether or not a color reconstruction is desired.
Separating analysis from representation achieves three different objectives. First, the affinity function can be chosen from a series of possible candidates, and the most optimal for the specific task can be used with no loss of applicability. Second, it enables the usage of hardware-accelerated software, providing a promising potential for real-time applications of hyperspectral enhancement techniques. Third, and final, it provides a framework that may allow clinicians and/or surgeons to control how visualization is carried out, and maybe help them improve their performance in the operating room.