## 2 Methods
### Vein Extraction Module
#### 2.2.2 Image Enhancement  
This is an essential stage that comes ahead of other computer vision-based operations. It enhances the quality of the captured images duringaboratory examinations. Captured images usually have distortion because of the nearbyight source, leading to issues such as glare and uneven brightness. To enhance the image quality, three spatial filters are used. These Filters are the contrast-limited adaptive histogram equalization (CLAHE) filter, the median filter, and the Gaussianow-pass filter.  
Figure 3: Stage 1, image preparation: (**a**) original image; (**b**) cropped image in RGB color; (**c**) cropped image in grayscale.  
The CLAHE filter is considered the core operation for image enhancement as it improves the image contrast. Its algorithm is presented in Algorithm 1. It deploys adaptive histogram equalization (AHE)ocally where the image is partitioned into several blocks called tiles. Each tile has a size of \(8\times 8\) pixels and is processed independently by histogram equalization. Since histogram equalization is applied to small areas, the noise is increased in homogenous regions. Therefore, the contractility (CL) is applied toimit the contrast below a specificimit (set to 25) to reduce excessive saturation in these regions.  
```
Input: \(I\)--Original image of size \(M\times N\) \(B_{x}\times B_{y}\)--Tile size \(N_{clip}\)--Clip Limit (value between 0 and 1) Output: \(J\)--Contrast-Enhanced image of the same size as image \(I\) 1. Divide image \(I\) into non-overlapping tiles of size \(B_{x}\times B_{y}\) 2. Calculate the histogram for each tile 3. Clip histogram:  Let top = \(N_{clip}\) = clippingimit  Let bottom = 0 4. Normalize histogram: for\(t_{i}\in\) tiles of \(I\)do  Normalize the clipped histogram \(h^{\prime}_{i}\) such that \(\sum_{k=0}^{255}h^{\prime}_{i}(k)=B_{x}\times B_{y}\). endfor 5. Distribute normalized histogram: ;  Pad the image with a border of size \(B_{x}\)//2 and \(B_{y}\)//2 on all sides. for\(p\in\) pixels of original image \(I\)do  Locate the tile \(t_{i}\) that contains \(p\).  Define neighbor set \(N_{p}\) as all pixels within a radius of \(B_{x}\)/2 and \(B_{y}\)/2 around \(p\) (including pixels from neighboring tiles). for\(k=0\) to 255 do  Distribute the value \(h^{\prime}_{i}(k)\) proportionally among the pixels in \(N_{p}\) based on their original intensity values. endfor endfor 6. Bilinear interpolation: 7. Crop image by removing the padded border from the enhanced image \(J\)
```  
**Algorithm 1**CLAHE Algorithm  
CLAHE indeed improves the vein's visibility. However, it produces significant noise. Therefore, part of this noise is removed by applying median filtering with a kernel size of \(15\times 15\). Median filtering is used to eliminate random noise while maintaining the main features ofines and edges within the captured images. Median filters work by replacing each pixel's intensity with an intensityocated within the center of a set of values. These values correspond to a sorted intensity value of the neighboring pixels including the current pixel itself.  
The remaining noise is decreased by blurring the image by deploying a Gaussianow-pass filter. At this stage, the image is ready for vein segmentation. Figure 4 shows snapshots of the results when applying image enhancement processes on the grayscale image shown in Figure 3c.