Figure 1 shows the framework of KMMRC-INRG. It includes three main steps. preprocessing, candidate generation, and classification. KMMRC and INRG are novel algorithms proposed in this work. The details of the algorithms are provided in the later sections. The following describes the details of each step.

### A. Preprocessing

As the green channel of the image can help detect better dark components such as hemorrhages^{17:00}, we convert the image’s green channel to grayscale and use it as an input. Preprocessing includes two main tasks. First are the contrast enhancements, which are performed locally and globally. The second is noise removal.

Local contrast enhancement is first applied to improve local contrast because the background has areas with different lighting conditions, such as illumination and shadows. We proposed a: *K-means multiregion contrast enhancement* (KMMRC) algorithm to improve the uneven lighting background. The: *K:*–*means:* algorithm:^{18:00} is used to divide the background into: *K:* regions based on intensity. A linear edge enhancement algorithm then enhances the contrast of each region. The pseudoalgorithm is provided in Algorithm 1.

The functions used in the algorithm are defined as follows.

*IMG2HSV(I)* takes the input image *I:* and extracts and returns the hue (*H:*), saturation (*S:*), and brightness (*V:*) matrices of: *I:*.

*KMeanSegment:**(**V, K)* takes a brightness matrix *V:* and an integer: *K:* as inputs. Based on brightness values, it divides *V:* into: *K:* submatrices: *V:*_{1:}*V:*_{2:}*…, V:*_{K:} of which: *V:*_{1:}+: *V:*_{2:}+: *…*+: *V:*_{K:} =: *V:* .

*MeanMatrix:**(V)* takes a brightness matrix*V:* as an input. It finds the average values in a matrix*V:* and returns a matrix of the same dimension as:*V*of which all elements hold the value of the computed average.

*HSV2**IMG(**H, S, V)* takes the matrices hue ( *H:*), saturation ( *S:*), and brightness ( *V:* ) as inputs. It constructs and returns an image from the input matrices *H, S,* and: *V.*

Our empirical observations show that: *K:* = 5 and: (beta =1.5) give the best performance. We then apply contrast-limited adaptive histogram equalization (CLAHE)^{19:00} to the image to smooth the false edges resulting from local contrast enhancement. To remove the noise and smoothen the image, we apply average filtering^{20:00} to the resulting image.

### B. Candidate generation

We used the contrast-enhanced images from the previous step as input. In this step, the hemorrhage candidates from the contrast-enhanced images are created. To obtain the hemorrhage candidates, we performed blob segmentation and vessel removal. The blob segmentation is performed by using the proposed iterative NICK thresholding region growing (INRG) algorithm. The pseudoalgorithm of INRG is shown in Algorithm 2.

The INRG algorithm uses the following functions.

*NT:**(I)* takes an image: *I:* as an input and returns a set of: *(x, y)*coordinates of points that pass the NICK threshold in Eq. (1).

$$tau (x,y)=avgleft(x,yright)+kappa sqrt{frac{(sum left({V}^{2}left(x,yright )right) – av{g}^{2}left(x,yright))}{N}},$$

(1)

where: (avgleft(x,yright)) is a local average at: (left(x, yright)), (Vleft(x,yright)) is the intensity at: (left(x, yright)), *N:*is the number of points in the area, and: (kappa) is a parameter in the range [−0.2, −0.1]. From the experiment, we find that: (kappa) = −0.2 and N = 9025 yield the best result.

*replace(**I, A, c)* takes an image: *I:* a set of points *A:* and a value: *c:* as inputs. It replaces the values of points *A:* in: *I:* with c.

*AvgG:**(**I, A)* takes an image: *I:*and a set of points *A:* as inputs and returns the average green values of all points in: *A:*.

Note: (cup) is a union operator. Our empirical observations show that: *n:*= 3 and: (delta =0.1) give the best performance.

The algorithm first calculates the initial regions of the candidate blobs by searching for pixels that are salient compared to their local backgrounds using NICK thresholding (NT)^{21,22:}. To better extract a region with nonuniform intensity, the algorithm expands the region by replacing the intensity in the regions with its average. Then, the algorithm reapplies NICK thresholding. It repeats until the region’s growth rate is less than a convergence constant. The program repeats at most *n-1:* times to ensure a complete exit. Figure 2 shows the areas of hemorrhage candidates using the INRG algorithm at different iterations until it converges.

Long and thin blobs are usually vessels. The algorithm detects these blobs by considering the axis length ratio of the fitted ellipse’s major and minor axes. From an empirical experiment, the ratio of 6.4 gives the optimal solution; it is assumed to be a blood vessel and is removed.

### C. Feature extraction and classification

The hue-saturation-value (HSV) color space is used in the feature extraction process, as hemorrhages are usually rich in color, have low saturation, and have low brightness. Additionally, HSV is more resistant to external lighting than RGB. The:*H:*,*S:*and:*V:*values are used as features extracted from each candidate.

Blob’s feature data and correct class answers (hemorrhagic and nonhemorrhagic) are trained and tested using fivefold cross-validation. Figure 3 depicts all processes from the beginning until hemorrhages are obtained.