# 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
Priority is given to hemorrhages with larger areas because they are more important than smaller ones in the diagnostic process. All objects are removed except larger ones. This maneuver is performed so that the dark shade will not mislead the segmentation, and the actual hemorrhage may not be eliminated. This rationale is adopted because a seed point may belong to a hemorrhage as well as to the intensity variations around the dark shades. Furthermore, objects closer to the center of the window are retained because of the higher probability that they are hemorrhages. The probability criterion is proposed because the window emerges from the seed point. The seed point is more likely to belong to a hemorrhage because its intensity profile analogous to the matched filter. The distance \(d_{i}\) between the centers \((C(x)_{2},C(y)_{2})\) of the window \(C_{2}\)\((x,y)\) to the \(i_{th}\) object computed using the Euclidean distance is given by:  
\[d_{i}=min\Bigg{[}\sqrt{+\Big{(}(C(x)_{2}-I_{i}(x))^{2}+(C(y)_{2}-I_{i}(y))^{2} \ \Big{)}}\ \Bigg{]} \tag{13}\]  
where \(I_{i}(x)\) denotes the \(x\) spatial locations of pixels in the \(i_{th}\) object while \(I_{i}(y)\) denotes the \(y\) spatial locations of pixels in the \(i_{th}\) object. \(i\) is part of the set \(\{1,2\}\), and \(d\) is a vector having two distances belong to two different objects. From the vector \(d\), the object with the longest distance from the center is eliminated. The pixels at the border of the window guarantee either to stop or to keep growing. If the hemorrhage is smaller than the window, then SWAT stops because the pixels are not found at the border of the window. The size of the window increases when it is bigger than the window. This task is accomplished by checking the border pixels of the window. For every instance of iteration, the size of the window is increased by updating the vertices in \(V\) with the equation below:  
\[V=\left\{ \begin{array}{cc}v_{1}\to v_{1}-5,&\text{if }q_{1}=1\text{ AND }v_{1}\cap S\\ v_{2}\to v_{2}-5,&\text{if }q_{2}=1\text{ AND }v_{2}\cap S\\ v_{3}\to v_{3}+10,&\text{if }q_{3}=1\text{ AND }v_{3}\cap S\\ v_{4}\to v_{4}+10,&\text{if }q_{4}=1\text{ AND }v_{4}\cap S\end{array} \right. \tag{14}\]  
\(Q\) is a vector that contains the information of border pixels. The binary variables \(q_{1}\), \(q_{2}\), \(q_{3}\), and \(q_{4}\) represent the left, top, right, and bottom border pixels. Once all the variables in \(Q\) are 0, then it shows that the SWAT has segmented the object (no further iteration is required to grow the size of the window). Any variable in \(Q\) has a value of 1, which represents that the border is not empty, and the object is bigger towards a specific direction. The size of the window is increased, and the hand-crafted image is cropped using an updated vector \(V\). In addition, the white region is characterized as the search region (see Figure 5d). The vector \(S\) represents the indices of the white region. If the window forms the seed point relevant to dark shade, the window may keep increasing and can go beyond the image range. To achieve the automation, the conditions (Equation (14)) check whether the vertices of the vector are in the search space or not. The segmentation process is implemented iteratively until all conditions are met (conditions: the vertices of vector \(Q\) become zero or the vector \(V\)\(S\)).