# Near Infrared Illumination Optimization for Vein Detection: Hardware and Software Approaches
## 2 Methodology
### Vein Image Processing and Morphological Process Enhancement
#### 2.3.4. Hessian and Median Filter  
Hessian segmentation uses eigenvalues to calculate the probability of the pixel being a vessel. According to [PERSON] and [PERSON] (2015), the quantitative estimation of the Hessian, \(\mathbf{H}\), at each pixel of the given image, I(x, y), is obtained.  
\[\mathbf{H}=\begin{bmatrix}\mathrm{L_{xx}}&\mathrm{L_{xy}}\\ \mathrm{L_{yx}}&\mathrm{L_{yy}}\end{bmatrix}=\begin{bmatrix}\frac{\partial^{2 }\mathrm{I}}{\partial x^{2}}&\frac{\partial^{2}\mathrm{I}}{\partial x\partial y }\\ \frac{\partial^{2}\mathrm{I}}{\partial y\partial x}&\frac{\partial^{2}\mathrm{I }}{\partial y^{2}}\end{bmatrix} \tag{1}\]  
The entries of \(\mathbf{H}\) can be obtained at multiple scales by convolving the image I(x, y) with the two-dimensional Gaussian kernel G(x, y; \(\sigma\)) of different scales \(\sigma\), which is defined as:  
\[\mathrm{G(x,y;\sigma)}=\frac{1}{2\pi\mathrm{\sigma^{2}}}\exp^{-\frac{x^{2}+y^ {2}}{2\sigma^{2}}} \tag{2}\]  
where  
\(\pi=3.142\ldots\)  
\(\sigma=\) standard deviation for Gaussian Operation  
\(x\) and \(y=\) relative coordinate of the center of kernel  
\[H_{xx}=\frac{\partial^{2}\mathrm{I}}{\partial\mathrm{x^{2}}}=I(x,y)\times \sigma^{2}G_{xx} \tag{3}\]  
\[H_{xy}=H_{yx}=\frac{\partial^{2}\mathrm{I}}{\partial\mathrm{xy}}=\frac{ \partial^{2}\mathrm{I}}{\partial\mathrm{yx}}=I(x,y)\times\sigma^{2}G_{xy} \tag{4}\]  
\[H_{yy}=\frac{\partial^{2}\mathrm{I}}{\partial\mathrm{y^{2}}}=I(x,y)\times \sigma^{2}G_{yy} \tag{5}\]  
The eigenvalues can be determined by using the formula below:  
\[\lambda_{1}=\frac{L_{xx}+L_{yy}-\alpha}{2} \tag{6}\]  
\[\lambda_{2}=\frac{L_{xx}+L_{yy}+\alpha}{2} \tag{7}\]where the local maxima, \(\alpha\), are obtained using the formula below:  
\[\alpha=\frac{\sqrt{\left(H_{xx}+H_{yy}\right)^{2}+4\left(H_{xy}\right)^{2}}}{2} \tag{8}\]  
\(H_{xx}=\) Second derivative in \(x-\) axis of the hessian matrix  
\(H_{yy}=\) Second derivative in \(y-\) axis of the hessian matrix  
\(H_{xy}=\) Second derivative in \(xy\) direction of the hessian matrix  
To better understand the process, Algorithm 2 has been used to apply the Hessian matrix to an image.  
```
IN: Grayscale image X of size \(M\times N\) OUT: Hessian-applied grayscale image Y of the same size of Image X
1 Convolve the image using Gaussian Kernel in the order of \(H_{xx},H_{yy}\) and \(H_{xy}\)
2 FOR every pixel in the image
3 Compute the covariance matrix
4 Calculate the local maxima and minima of the image using the eigenvalues from
5 the covariance matrix:
6 Local Maxima = (Hxx + Hyy)/2 + sqrt (4 * Hxy ** 2 + (Hxx - Hyy) ** 2)/2  Local Minima = (Hxx + Hyy)/2 - sqrt (4 * Hxy ** 2 + (Hxx - Hyy) ** 2)/2
```  
**Algorithm 2** Hessian Matrix  
Median filtering is carried out in such a way that, a window is relocated from one column to the next along the rows of the image and the pixel's median enclosed within the window at every position is computed. The median of the individual pixel is calculated by taking neighboring pixels based on window size and then sorting them in ascending or descending order. Then, the middle value is considered the median, and the original pixel values are substituted with the median value. The mathematical annotation can be defined as:  
\[y_{ij}=med\big{(}\{x_{uv}|x_{uv}\in N_{ij}\}\big{)} \tag{9}\]  
Hessian and Median Filter approaches came next in the processing line to produce overlay ridges features on the vein image while reducing unnecessary noise along the process. Then, the image's contrast was again increased to make the shadows darker and highlights brighter. The last process that lies in the row was to enhance the overall quality of the vein image. This involved the color mapping procedure which maps the inferno features on the targeted vein image.