# Efficient and Accurate Hemorrhages Detection in Retinal Fundus Images Using Smart Window Features
## 2 Materials and Methods
### Brightness and Contrast Enhancement
#### 2.2.2 Segmentation Stage
The SWAT initiates the segmentation process from the seed points that emerge from the blood vessels and hemorrhages. A seed is used to estimate retinal structures from the hand-crafted image (Figure 5c). The SWAT originates from each seed to capture the hemorrhages in the window. The window size increases after every iteration. [PERSON]'s method [33] finds the threshold value successively and maximizes the inter-region variance using an image histogram. This method utilizes the complete gray range and chooses the best range that provides maximum inter-region variance. The normalized histogram of an image is given by:  
\[p_{j}=\frac{n_{j}}{X\times Y},\ j\ =\ \{0,1,2,\ldots L-1\} \tag{7}\]  
where \(n_{j}\) is the frequency of \(j_{th}\) intensity occurring in the image. In our experiment, the number of threshold levels starts from one and goes up to twenty. Optimum threshold value \(\tau^{*}\) is computed by taking the weighted variance between regions. \[\sigma_{B}^{2}(j)\ =\ \sum_{z=1}^{R}\omega_{z}(\mu_{z}-\mu_{T})^{2}, \tag{8}\]  
\[\sigma_{B}^{2}(\tau^{*})=\max_{1\leq j\leq L}\sigma_{B}^{2}(j) \tag{9}\]  
where \(\omega_{z}\) is the total probability, \(\mu_{z}\) the mean value, and \(\sigma_{B}^{2}\) is the weighted variance of the individual region in the total number of regions \(R\). The threshold levels split the image into \(R\) regions. For instance, if \(N\) is equal to one and the threshold value is \(i\), then the intensities are divided into two regions as \(R_{1}=\{0,1,2,\ldots,i\}\) and \(R_{2}\ =\ \{i+1,i+2,\ i+3,\ldots,\ L-1\}\). It can be observed that the mean \(\mu_{T}\) does not depend upon the threshold value \(i\). The effectiveness value \(\eta\) is used to control the degree of thresholding. It provides information about how well the threshold value can distinguish the specified region from the rest of the regions in a window. It is computed by:  
\[\eta=\frac{\sigma_{B}^{2}(\tau^{*})}{\sigma_{T}^{2}} \tag{10}\]  
The proposed SWAT employs the optimum threshold \(\tau^{*}\), the effectiveness value \(\eta\), the seed points of the morphological opened image, and the hand-crafted image for segmentation and feature extraction. The search process starts by computing the bounding box from a seed point. Let the vertices \(v_{1},v_{2},v_{3},v_{4}\) of a bounding box be represented by a vector \(V\ =\ [v_{1},\ v_{2},\ v_{3},v_{4}]\). The vector \(V\) is determined by the minimum box that can contain a seed point. The hand-crafted image is cropped using the vector \(V\) to obtain a window. Let the cropped window \(C_{1}\ (x,y)\) become thresholded iteratively using [PERSON]'s method. To obtain appropriate \(N\), the window \(C_{1}\ (x,y)\) was thresholded until the iteration stops by using criteria in Equation (11):  
\[\vartheta=\left\{ \begin{array}{rl}N\to N+1,&\text{if }\eta<0.8,\text{ AND }N\leq 20\\ &\text{stop},\text{ otherwise}\end{array} \right. \tag{11}\]  
where \(\vartheta\) is a vector that comprises \(N\) threshold levels. The maximum length of the \(\vartheta\) and the number of iterations can be 20. Equation (11) assumes that the intensities of the hemorrhage are lower than the minimum threshold value of the vector \(\vartheta\), while the rest of them belong to the non-hemorrhage regions. After the selection of \(\eta\), the window \(C_{1}\)\((x,y)\) is binarized using the minimum threshold of the vector \(\theta\) given by:  
\[C_{2}\)\((x,y)=\left\{ \begin{array}{cc}0,&\text{if }C_{1}\ (x,y)>\min(\theta)\\ &1,\text{ else}\end{array} \right. \tag{12}\]  
The conditions in Equation (11) adapt the regional diversity between the hemorrhages and foregrounds. When a bright foreground encompasses hemorrhage, the iterative process approaches the specified effectiveness value (\(\eta\) is equal to 0.8) in fewer iterations and a smaller number \(N\) of threshold levels. When a dark region surrounds a hemorrhage, it reaches the effectiveness value \(\eta\) comparatively in more iterations and threshold levels. A window can have more than one hemorrhage.