1 Introduction

Retinal vessels are the only micro-vessels which can be observed in a noninvasive way. Its shape, curvature and width are reliable diagnosis indicators for diabetic retinopathy [1,2,3,4,5,6,7,8], glaucoma [9,10,11], hypertension [12, 13] and retinal artery occlusion [14, 15]. There are complex non-vascular structures in a retinal image as shown in Fig. 1, such as optic disk, retinal boundary and lesion area. Several factors make retinal vessel detection extremely difficult. One is that central reflex phenomenon leads to the problem that two vessels close to each other may be identified as one vessel. The other is that the vessel width which is an important indicator for disease diagnosis has a large variation. Besides, the fundus image is vulnerable to environmental noise. In summary, accurate extraction of vessels with different widths in retinal images with complex structure and uneven contrast is the bottleneck for retinal vessel extraction.

The most frequently used automatic retinal vessel extraction method can be classified into three categories. One is tracking-based method [17, 18]. In [17], some seed points were selected in accordance with the brightness. Then multi-scale line tracking was performed based on these seed points. In [18], a tracking algorithm which is not based on image intensity level was proposed. The tracking problem is transformed into the global inference problem in graphical models. In general, the tracking-based method can achieve more complete extraction of retinal vascular network compared with other methods. However, it requires manual search for seed points which leads to high computational complexity. In addition, it is difficult to deal with the bifurcation point of small vessels.

Classifier-based method [19,20,21,22,23,24,25] was also widely used. In [19], the broad blood vessels were extracted by adaptive local threshold and the narrow blood vessels submerged in debris noise were extracted by support vector machine. In [20], the dual-tree complex wavelet transform (DCWT) was employed to describe the local features of the image. Random forest was used as the classifier. In [21], a multi-scale and rotation invariant local binary pattern (LBP) operator was used to extract the feature vectors. The extracted feature vectors were then classified using adaptive neuron fuzzy inference system. In [22], Lattice Neural Network with Dendritic Processing (LNNDP) was used as feature classifier. In recent years, the deep neural network has been widely concerned [23, 24]. This method not only can effectively inhibit the phenomenon of central vessel reflex, but also has a satisfactory effect on the detection of fine blood vessels. In general, the classifier-based segmentation has high accuracy. But it needs some amount of a priori information of the retinal vessels to construct an appropriate classification model to map the pixels in the retinal image to different categories. Meanwhile, some classifier-based methods are very sensitive to noise.

Fig. 1
figure 1

Retinal image

Another typical approach is filtering-based method [25,26,27,28,29]. The two-dimensional Gaussian-shaped matched filter method was first used to extract blood vessels in [25]. The algorithm is rooted in the fact that the gray distribution of the cross section of the retinal blood vessels is similar with a Gaussian function. A Gaussian matched filter was used to match the vessels in different directions. When the scale of the filter is consistent with vascular width, the vessels with the width accordingly will be enhanced and a large convolution response is generated. Single scale was used; thus, it cannot make the vessels of various widths enhanced. In addition, the filter produces very strong response to both vascular structure and non-vascular structure, which results in misclassified pixels. To overcome the drawbacks, an extraction method using multi-scale matched filter with first-order derivative of Gaussian was proposed in [26]. More blood vessels with various widths were extracted. Besides, the frequency responses to vascular structure and non-vascular structure with step-edge were distinguished. Later, to get a better estimation to the vessel widths, multi-scale production of matched filter (MPMF) was proposed for segmentation in [27]. Blood vessel pixels can be extracted and fused in the scale production domain by multi-scale production of matched filter responses. In [28], local entropy threshold was used for narrow vessels and adaptive threshold was used for broad vessels. The final results was obtained by the logical OR operation on the extracted broad and narrow vessels. In [29], a 2D image was lifted to a 3D orientation score domain in which multi-scale filtering was done via the left-invariant rotating derivative (LID) and the locally adaptive derivative (LAD). In particular, the LAD filter on orientation scores is capable of dealing with some difficult cases, such as crossings and the phenomenon of the central arterial reflex.

Other approaches are also applied in vessel segmentation such as model-based segmentation and threshold-based segmentation, etc. For example, in [30], the infinite active contour model with hybrid region information of the image was used to achieve the segmentation. In [31], the extraction of blood vessel network was completed by iterating and updating the thresholds, which is very effective in abnormal retinal images. Currently, there are numerous algorithms for the segmentation of the retinal blood vessels; in this paper, we focus on the matched filtering approach.

Though multi-scale matched filtering has been applied into retinal vessel extraction, current studies process the image as a whole whether in the stage of scale allocation or threshold setting, which does not consider the local characteristics of the image. In this paper, we proposed a new dynamic multi-scale filtering method together with a dynamic threshold processing scheme. Gaussian function was used to fit the gray histogram of each sub-image. Based on the parameters obtained from Gaussian fitting, we determined the types of blood vessels and the contrast between medium and narrow blood vessels which are the key factors that influence the scales of filtering and the value of thresholds. The proposed method considered both the extraction of tiny blood vessels in the low-contrast regions and the inhibition of non-vascular structures. It also avoided the overestimation of the width of the vessels.

The rest of this paper is organized as follows. In Sect. 2, the proposed algorithm is generally described. In Sect. 3, the image preprocessing is introduced. In Sect. 4, the multi-scale matched filtering scheme based on dynamic scales allocation is proposed. In Sect. 5, the dynamic threshold processing is presented. In Sect. 6, the post-processing is briefly introduced. In Sect. 7, the experimental results are presented to illustrate the effectiveness of the proposed algorithm. Finally, conclusions are drawn in Sect. 8.

Fig. 2
figure 2

Flow chart of the proposed algorithm

2 Overview of the proposed algorithm

The proposed method is shown in Fig. 2, which includes the stages of preprocessing, dynamic-scales allocation, matched filtering, dynamic threshold segmentation and post-processing. In the preprocessing stage, the contrast of the image is enhanced. The green channel of the image is extracted followed by the multi-scale top-hat transformation which is used to extract the bright and dark region features of the image. Then the histogram transformation is applied to stretch the gray values to the entire gray level range. In the dynamic-scale allocation stage, the image is first divided into sub-blocks. Then Gaussian curve is used to fit the gray histogram of each block to determine the types of blood vessels in accordance with which we allocate the scales of the matched filter. In the matched filtering stage, both the Gaussian and first-order derivative of Gaussian filters are applied to the sub-block image. In the stage of dynamic threshold processing, blood vessel extraction is done based on the thresholds which are adjusted by both the gray distribution characteristics in the sub-block and the response of first-order derivative of Gaussian filter. In the stage of post-processing, the segmentation accuracy is further improved by eliminating the noise, smoothing vascular edges and connecting break points.

3 The preprocessing

Most retinal vessel extraction algorithms based on matched filtering have no preprocessing step because the Gaussian matched filters will not only make the blood vessels enhanced but also suppress noise effectively. In this paper, the proposed algorithm includes scales allocation and threshold setting based on gray distribution characteristics. It would be helpful for the judgment about the existence of vascular structures and the types of blood vessels if the distribution of the gray values has a large dynamic range. However, the distribution of the gray levels of the original image is usually concentrated. Therefore, before subsequent processing, the contrast of the image needs to be enhanced by a series of preprocessing steps.

3.1 Green channel extraction

The original color retinal image contains three channels: red, green and blue. Compared with the red and blue channel components, the green channel component usually has better contrast between blood vessels and background and has lower noise content. Thus the green channel component is selected as the processing object of the whole algorithm.

3.2 Multi-scale top-hat transform

The top-hat transform in [32] is used to extract the bright and dark region features of the image. The bright region features are extracted using the white top-hat transform, which is defined as

$$\begin{aligned} WT{H_i}\left( {x,y} \right) = f - f \circ {B_i} \end{aligned}$$
(1)

and the dark region features are extracted using the black top-hat transform, which is defined as

$$\begin{aligned} BT{H_i}\left( {x,y} \right) = f \bullet {B_i} - f \end{aligned}$$
(2)

where f is the gray image. The symbol “ \(\circ \)” denotes opening operation and the symbol “ \(\bullet \)” denotes closing operation. \({B_i}\) is the \({i_{th}}\) structure element for mathematical morphology operations. The top-hat transform is carried on ten times using disk shape structure elements with different sizes. The initial size is 3 and then the size is increased by 2 each time. The optimal bright and dark region features are obtained using Eqs. (3) and (4), where \( f_w^{op}\) represents the optimal bright region features, and \( f_b^{op}\) shows the optimal dark region features,

$$\begin{aligned} f_w^{op}= & {} \mathop {\max }\limits _{0 \le i \le 10} \left\{ {WT{H_i}} \right\} \end{aligned}$$
(3)
$$\begin{aligned} f_b^{op}= & {} \mathop {\max }\limits _{0 \le i \le 10} \left\{ {BT{H_i}} \right\} \end{aligned}$$
(4)

The optimal bright and dark region edges \( f_w^d \) and \( f_b^d \) are obtained using Eqs. (5) and (6),

$$\begin{aligned} f_w^d= & {} \mathop {\max }\limits _{0 \le i \le 10} \left\{ {WT{H_{i + 1}} - WT{H_i}} \right\} \end{aligned}$$
(5)
$$\begin{aligned} f_b^d= & {} \mathop {\max }\limits _{0 \le i \le 10} \left\{ {BT{H_{i + 1}} - BT{H_i}} \right\} \end{aligned}$$
(6)

After feature extraction by the above steps, the final multi-scale top-hat transform is defined as,

$$\begin{aligned} {f_{end}} = f + \left( {f_w^{op} + f_w^d} \right) - \left( {f_b^{op} + f_b^d} \right) \end{aligned}$$
(7)

3.3 Histogram specification

The contrast of the image has been improved after the green component extraction and multi-scale top-hat transform. Next we try to stretch the gray values to the entire gray level range. It has been shown that the gray values of the retinal image is approximately normal distribution [32]. Thus we can use Gaussian curve, shown in Eq. (8), to fit the gray histogram approximately,

$$\begin{aligned} P\left( x \right) = a{\text {e}^{ - \frac{{{{\left( {x - b} \right) }^2}}}{{{c^2}}}}} \end{aligned}$$
(8)

where a and b represent the peak value and the mean value of the Gaussian curve, respectively. c reflects the range of the gray level distribution. It is known that the area under the Gaussian curve within \([ {b - 3c,b + 3c}]\) accounts for almost 99% of the total area. Therefore, it is reasonable to take \({S_1} = b - 3c \) and \({S_2} = b + 3c\) as the minimum and the maximum of the gray level, respectively. Let \(f\left( {x,y} \right) \) represents input gray image. \({S_1}\) and \({S_2}\) are linearly mapped to 0 and 255, respectively. The final gray image \({f_s}\left( {x,y} \right) \) is obtained by,

$$\begin{aligned}&{f_s}\left( {x,y} \right) \nonumber \\&\quad = \left\{ {\begin{array}{ll} {0,}&{}\quad {f\left( {x,y} \right) \le {S_1}}\\ {\left( {\frac{{255}}{{{S_2} - {S_1}}}} \right) \left[ {f\left( {x,y} \right) - {S_1}} \right] ,}&{}\quad {{S_1} < f\left( {x,y} \right) \le {S_2}}\\ {255,}&{}\quad {f\left( {x,y} \right) > {S_2}} \end{array}} \right. \end{aligned}$$
(9)

An Example after preprocessing is shown in Fig. 3. It can be seen that the image contrast is improved effectively. Compared with the original retinal image, not only better visual effect is obtained but also more details are shown.

4 Dynamic multi-scale matched filtering

Since the scale allocation and the multi-scale matched filtering are closely related to each other. We present these two stages together.

4.1 Image sub-blocking

Although the contrast of the image after the preprocessing has been improved, the heterogeneity of blood vessels and the heterogeneity of background is still a problem, which makes it difficult to set the appropriate matching filter scales. In fact, if we use a matched filter with one scale for the entire large retinal image, some vessels whose widths do not consist with the scale of the matched filter will not be extracted properly. Considering that heterogeneity in local area is relatively small, the whole image is divided into 20 sub-images with equal size, as shown in Fig. 4. These blocks are numbered from top to bottom and from left to right. Then the gray distribution characteristics of each sub-image are analyzed to determine whether there is vascular structures in the sub-image and the types of blood vessels, based on which the scales of the matched filter are adjusted dynamically.

Fig. 3
figure 3

Retinal vascular enhancement: a the original image (image19 in the DRIVE database); b the green channel image; c image after multi-scale top-hat transform; d image after gray stretching

Fig. 4
figure 4

Division of retinal image

4.2 Determination of blood vessels types

In accordance with the location of the 20 sub images, they are divided into three categories.

Type one: The blocks are located in the four corners of the original image, numbered 1, 4, 17 and 20.

Type two: The blocks are located in the center of the original image, numbered 6, 7,10,11,14 and 15.

Type three: The blocks are located in the edge of the original image, numbered 2, 3, 5, 8, 9, 12, 13, 16, 18 and 19.

Two examples of type one are shown in Fig. 5. Figure 5 (a) contains high-contrast vessels but the number of pixels belonging to the blood vessels is extremely small portion of the total number of pixels in the whole sub-image. A more general case is shown in Fig. 5b in which almost no blood vessels exist. In summary, for type one blocks, the number of blood vessel pixels is quiet small. In order to simplify the processing, no further analysis is done and medium-size scale is given to the sub-images of type one.

Fig. 5
figure 5

Examples of the blocks located in the corners

For sub-images of type two, the width of the blood vessels was classified into three categories: broad, medium and narrow. The type of the vessels is determined as follows.

1) Broad blood vessels

This kind of sub-images does not contain black background outside the retina. Therefore, a peak in the low gray range in the histogram is not caused by background but by the existence of broad blood vessels. Based on DRIVE database, the frequency of pixel points in the range of 0–50 gray level in gray histogram, denoted as gb, is counted. If it is greater than a threshold \(gb\_thr\) the block contain broad blood vessels; otherwise, there are no broad vessels. This can be illustrated by Fig. 6a.

2) Medium or/and narrow blood vessel

Two examples of type two are shown in Fig. 6b, c. We can see that the gray histograms are quite different for sub-image mainly with medium and narrow blood vessels and sub-image mainly with narrow blood vessels. To quantitatively analyze the difference, the gray histogram is fitted to a Gaussian curve as shown in Eq. (8). The peak a and the variance c of the Gaussian function is used to distinguish the types of the vessels. To determine the existence of medium or/and narrow blood vessels, two facts should be noted.

  1. a)

    The existence of narrow blood vessels will make the peak a larger since the difference of the gray values between narrow blood vessels and the background is very small.

  2. b)

    The existence of medium blood vessels will make the variance c larger since the gray values of medium blood vessels are quite different with that of the background and narrow blood vessels.

Based on the above two understandings, the decision method was proposed as shown in Fig. 7. Two thresholds for the peak and variance are found, denoted as \(a\_thr\) and \(c\_thr\), respectively. After fitting, the types of the blood vessels are determined as follows,

  1. a)

    contains narrow vessels when

    \(a > a\_thr\) and \(c \le c\_thr\).

  2. b)

    contains medium vessels when

    \(a \le a\_thr\) and \(c > c\_thr\).

  3. c)

    contains narrow and medium vessels when

    \(a > a\_thr\) and \(c > c\_thr\).

  4. d)

    No narrow or medium vessels when

    \(a \le a\_thr\) and \(c \le c\_thr\).

Fig. 6
figure 6

Central sub-images and its gray histogram a sub-image mainly with broad vessels; b sub-image mainly with medium and narrow vessels; c sub-image mainly with narrow vessels

Fig. 7
figure 7

Different values of a and c and the four categories

For sub-images of type three, the types of the blood vessels are determined similarly as type two. It should be noted that because of black background in the sub-images of type two, the threshold for determining the broad vessel is larger than the one for the sub-images of type two, as shown in Fig. 8a.

The parameters \(gb\_thr\), \(a\_thr\) and \(c\_thr\) could influence the whole performance of the algorithm. Improper values of \(gb\_thr\), \(a\_thr\) and \(c\_thr\) result in misclassification of vessel types. The sub-images with misclassified vessel types will not be matched by match filters with proper scales, which will reduce the accuracy of vessel segementation. We determine these parameters using grid-searching method. Let us use \(gb\_thr\) as an example. First DRIVE dataset is partitioned into two parts, a training set with true value label and a testing set. Then for the image in the training set, the histogram of each sub-image is analyzed to get the gb value. Among these values, the maximum and minimum values of gb can be obtained. Next, grid-searching method is used to determine the \(gb\_thr\) according to the accuracy of the classification obtained by comparing the experimental results with the true value label. The selected \(gb\_thr\) is then evaluated and fine adjusted by applying it to the testing set. In the similar way, \(a\_thr\) and \(c\_thr\) are determined.

Fig. 8
figure 8

Edge sub-image and its gray histogram

4.3 Dynamic-scale allocation

To determine the proper scale for the matched filter, it is important to find the relationship between the filter scale and the blood vessel width. The gray distribution of the vascular cross section is approximately a Gaussian curve. The width of the vascular is usually defined as the length of the projection of the curve on the horizontal axis. As we have mentioned in Sect. 3, the area under the Gaussian curve within \([ {b - 3c,b + 3c}]\) accounts for almost 99% of the total area. Therefore the width of the vascular d can be considered approximately equal to 6c. Since the filter scale is the variance of Gaussian function and had better be close to the vascular width, we have

$$\begin{aligned} \sigma = c \approx {d / 6} \end{aligned}$$
(10)

We first determine a series of reference scales, based on which the actual scales can be obtained. Suppose the range of vascular length is \(\left[ {{d_1},{d_2}} \right] \), in accordance with (10), we have the minimum and the maximum reference scales \({\sigma _{\min }} = {d_1}/6\) and \({\sigma _{\max }} = {d_2}/6\) , respectively. Then we have \(\left( {{\sigma _{\min }} + {\sigma _{\max }}} \right) /2\) as the medium reference scale. Since the gray ranges of narrow vascular and medium vascular are partly overlapped, to increase the extraction performance, we added one more reference scale for both narrow and medium vascular, which also allows more blood vessels to be extracted. The reference scales are shown in Eq. (11),

$$\begin{aligned}&{\sigma _{broad}} = {\sigma _{\max }} = {d_2}/6 \nonumber \\&{\sigma _{medium\_1}}= \left( {{\sigma _{\min }} + {\sigma _{\max }}} \right) /2\nonumber \\&{\sigma _{medium\_2}} = {\sigma _{medium}} - \left( {{\sigma _{medium}} - {\sigma _{\min }}} \right) /3\nonumber \\&{\sigma _{narrow\_1}} = {\sigma _{\min }} = {d_1}/6\nonumber \\&{\sigma _{narrow\_2}} = {\sigma _{\min }} + \left( {{\sigma _{medium}} - {\sigma _{\min }}} \right) /3 \end{aligned}$$
(11)
Table 1 Scale selection criteria

The actual scales are found around the reference scales. For example, it is shown in [25] that the range of vascular width is [2, 10] for DRIVE database. The actual scales used are 0.2 and 0.5 for narrow vascular, 0.7 and 1 for medium vascular, and 2 for broad vascular. In accordance with Eq. (11) and the determination of the blood vessel types, the scales selection criteria is shown in Table 1. For example, if we have \(gb > gb\_thr\) and \(c > c\_thr\), the scales \({\sigma _{broad}}\) \({\sigma _{medium\_1}}\), and \({\sigma _{medium\_2}}\) should be used.

4.4 Matched filtering

When the Gaussian matched filter is used, the filter response has high amplitude if there is a vascular structure with Gaussian gray distribution or a non-vascular structure with step edge, as shown in Fig. 9. Using threshold segmentation to determine whether a pixel belongs to the blood vessel will inevitably lead to the situation that some non-vascular structures are wrongly judged as vascular structures. Therefore, two matched filter templates, Gaussian matched filter template and Gaussian first derivative matched filter are adopted, as shown in Eqs. (12) and (13)

$$\begin{aligned} f\left( {x,y} \right)= & {} \frac{1}{{\sqrt{2\pi } \sigma }}\exp \left( { -\, \frac{{{x^2}}}{{2{\sigma ^2}}}} \right) - m,\quad \left| x \right| \le 3\sigma ,\left| y \right| \le L/2\nonumber \\ \end{aligned}$$
(12)
$$\begin{aligned} g\left( {x,y} \right)= & {} \frac{x}{{\sqrt{2\pi } {\sigma ^3}}}\exp \left( { -\, \frac{{{x^2}}}{{2{\sigma ^2}}}} \right) ,\quad \left| x \right| \le 3\sigma ,\left| y \right| \le L/2\nonumber \\ \end{aligned}$$
(13)

where L is the length of the segment for which the vessel is assumed to have a fixed orientation [26]. m represents the mean of coefficients in the Gaussian filter template, defined in Eq. (14)

$$\begin{aligned} m = \sum \limits _{\overline{{p_i}} \in N} {{{f\left( {x,y} \right) } / Q}} \end{aligned}$$
(14)

where Q denotes the number of points in the filter template. N is a neighborhood. \(\overline{{p_i}}\) is the point in corresponding rotated coordinate system. In addition, the matched filter template needs to be rotated accordingly to detect the vessel of different orientations.

Fig. 9
figure 9

Simulation of the response of vascular and non-vascular signals with Gaussian filter. Both a, d represent Gaussian filters; b the vascular structure modeled by Gaussian function; e non-vascular structure modeled using step-edge; c, f are the convolution response of vascular and non-vascular structures with Gaussian filter, respectively

5 Threshold processing

The contrast and the information of non-vascular structures included in the gray histogram are used to guide the selection of the thresholds. Compared with the single threshold selection formula in [27], the proposed method considers both the extraction of tiny blood vessels in the low-contrast regions and the inhibition of non-vascular structures. In the following discussion, let us use A to represent the convolution response of the Gaussian matched filter and the retinal image and using B to represent the convolution response of the Gauss first derivative matched filter and the retinal image. \(\overline{\mathbf{A }}\) and \(\overline{\mathbf{B }}\) denotes the local mean of A and B.

5.1 Distinguish contrast between medium and narrow vessels

In order to accurately extract more blood vessels, it is necessary to consider the contrast between medium and narrow vessels. When the contrast is low (the gray levels of narrow and medium vessels are quite similar), we get one Gaussian curve after Gaussian fitting. When the contrast is high (the gray levels of narrow and medium vessels are quite different), we get two Gaussian curves (the gray values of medium vessels form one and the gray values of narrow vessels form one) with smaller variances than that of the low contrast case after Gaussian fitting. Therefore, the variance c of Gaussian fitting can indicate the contrast between medium and narrow vessels. For the high-contrast case \(c > {c_{th}}\) and the low-contrast case \(c \le {c_{th}}\) , different sets of thresholds are used.

If the contrast between the two types of vessels is low, we further try to separate the narrow and medium vessels into two sections in the gray histogram as much as possible. In general, there is a peak value in the gray area coincident with the overlap of gray distribution of narrow and medium vessels. Therefore, the whole gray range is divided into two sections using the peak value in 50–250 gray scale range, denoted as \({g_{th}}\), as the threshold. After this treatment, the vascular types of each section are relatively simple. In low-contrast case, for points belonging to different sections, different thresholds are used.

5.2 Distinguish whether there is a step edge

There are some other non-structures, such as optic disk, bright spots, retinal exudate, retinal boundary, etc. The brightness of these non-structures is significantly higher than other adjacent structures. Thus, their gray distribution is characterized by the step edge. To distinguish the existence of step edge, the frequency of pixel points in the range of 200–255 gray level in the histogram is added up and then compared with a threshold \({s_{th}}\).

$$\begin{aligned} s = \sum \limits _{k = 200}^{255} {gray\_frequeny(k)} \end{aligned}$$
(15)

Next the position of a non-vascular structure with a step edge needs to be determined. Traversing all points in local mean response \(\overline{\mathbf{B }}\) , if amplitude of a point is greater than a certain threshold \({b_{th}}\), it is believed that there are pixels of non-vascular structures with step edges in the neighborhood. Otherwise, there are vascular pixels near the point. For different types of vascular, the value of \({b_{th}}\) is different.

5.3 Threshold selection

The calculation of threshold value includes two steps. First, the reference threshold matrix \(\widehat{\mathbf{T }}_{}^{(n,\sigma )}\) is determined. n is the serial number of the sub-image, and \(\sigma \) is the scale of the matched filter. We use \(\widehat{\mathbf{T }}_{i,j}^{(n,\sigma )}\) to denote the reference threshold for the pixel at position (ij) in the sub-image. \(\widehat{\mathbf{T }}_{i,j}^{(n,\sigma )}\) can be obtained by Eq. (16),

$$\begin{aligned} \widehat{\mathbf{T }}_{i,j}^{(n,\sigma )} = \left( {1 + \overline{\mathbf{B }} _{i,j}^{(n,\sigma )}} \right) \overline{\mathbf{A }} _{i,j}^{(n,\sigma )} \end{aligned}$$
(16)

where \(\overline{\mathbf{A }}_{i,j}^{(n,\sigma )}\) and \(\overline{\mathbf{B }} _{i,j}^{(n,\sigma )}\) are the local means of responses of the Gaussian filter and Gaussian first derivative matched filter for pixel at position (ij), respectively. Then element of the threshold matrix \(\mathbf{T }_{i,j}^{(n,\sigma )}\) is calculated by multiplying the reference value with an adjusting parameter \(h_{i,j}^{(n,\sigma )}\), as shown in Eq. (17)

$$\begin{aligned} \mathbf{T }_{i,j}^{(n,\sigma )} = \widehat{\mathbf{T }}_{i,j}^{(n,\sigma )} \times h_{i,j}^{(n,\sigma )}(c,g,s) \end{aligned}$$
(17)

where \(h_{i,j}^{(n,\sigma )}\) is influenced by the contrast indicator c , the gray level g and the step edge indicator s. The selection of the adjusting parameter \(h_{i,j}^{(n,\sigma )}(c,g,s)\) is shown in Table 2.

The threshold matrix of the whole image is \(\mathbf{T }_{}^{(\sigma )} = \bigcup \nolimits _n {\mathbf{T }_{}^{(n,\sigma )}} \). Then comparing the threshold matrix with the response of the image to Gaussian filter point by point, the judgment can be made to extract the blood vessel network, as shown in Eq. (18)

$$\begin{aligned} \mathbf{V ^{(\sigma )}} = \left\{ {\begin{array}{ll} 1&{}\quad {\mathbf{A ^{(\sigma )}} \ge \mathbf T _{}^{(\sigma )}}\\ 0&{}\quad {\mathbf{A ^{(\sigma )}} < \mathbf T _{}^{(\sigma )}} \end{array}} \right. \end{aligned}$$
(18)

Since multi-scale matched filtering is used, the final extraction result is obtained by an operation of logical OR, as shown in Eq. (19),

$$\begin{aligned} \mathbf V = \bigcup \limits _\sigma {\mathbf{V ^{(\sigma )}}} \end{aligned}$$
(19)
Table 2 Selection of adjusting parameter \(h_{i,j}^{(n,\sigma )}(c,g,s)\)

6 Post-processing

The post-processing operations can further improve the accuracy of blood vessel segmentation. First is by the use of connected domain-processing method for noise removal. Secondly is by the use of mathematical morphology operation to smooth burr on the edge of the blood vessels. Next, the mask images provided in DRIVE database are used to find the locations of the pixels on the FOV boundary and then to eliminate it, as shown in Fig. 10. Finally, some discontinuous small blood vessels are connected to the breakpoints in the binary image using closing operation in mathematical morphology.

7 Experimental results

The retinal images in the open DRIVE database are used to test the effectiveness of the proposed algorithm. The database contains a training set and a test set. Each of them contains 20 images. These retinal images are digitized at 24 bits with a spatial resolution of 565\(\times \)584 pixels. Hand-labeled images are also available in this database. The first expert manual segmentation results are used to evaluate the performance of the algorithm (ground truth). Three indexes are adopted for performance comparison, accuracy (ACC), true-positive rate (TPR) and false-positive rate (FPR). They are defined as follows:

$$\begin{aligned} ACC= & {} \frac{{TN + BN}}{{Nvp + Nuvp}} \end{aligned}$$
(20)
$$\begin{aligned} TPR= & {} \frac{{TN}}{{Nvp}} \end{aligned}$$
(21)
$$\begin{aligned} FPR= & {} \frac{{FN}}{{Nuvp}} \end{aligned}$$
(22)

where TN is the number of correctly detected vessel pixels inside FOV and BN is the number of correctly classified non-vessel pixels inside FOV (FOV: the part of within the retinal image boundary). Nvp is the number of vessel pixels inside FOV, and Nuvp is the number of non-vessel pixels inside FOV. FN is the number of misclassified non-vessel pixels inside FOV. ACC is the average accuracy rate for retinal vessel segmentation. TPR is defined as the ratio of correctly classified vessel pixels inside FOV. FPR is defined as the ratio of misclassified non-vessel pixels inside FOV.

A number of experiments were carried out. The extraction performances of blood vessel network in three cases, maximizing TPR, maximizing ACC and balancing TPR and ACC were considered. These experiments are realized by adjusting the segmentation thresholds. The range of the adjustable parameter \(h_{i,j}^{(n,\sigma )}({c_t},g,s)\) is from 1 to 10 in the experiments.

Fig. 10
figure 10

a Mask image of the retinal image, b retinal boundary

1) Maximizing TPR

For the regions with low contrast, the gray distribution ranges of the blood vessels and the background are very close. It is difficult to extract the blood vessels completely out of the background. Adjusting the \(h_{i,j}^{(n,\sigma )}\) in Eq. (17) to lower the threshold in such regions will lead to a better extraction of narrow blood vessels. Therefore, TPR will be improved. However, it is inevitable that some of the background pixels are segmented by mistake. These error points will lead to a decline of ACC. The average segmentation results of 20 retinal images are TPR: 0.7526, FPR: 0.0331, ACC: 0.9393.

Fig. 11
figure 11

a The original image 18 in the DRIVE database; b the ground truth vessel map; (\({c_1}\)) the results of maximizing TPR; (\({c_2}\)) the results of the maximizing ACC; (\({c_3}\)) the results of balancing TPR and ACC

Table 3 Comparison of segmentation results (with FOV)

2) Maximizing ACC

There are some regions in which the narrow blood vessels are submerged by the background noise. Adjusting \(h_{i,j}^{(n,\sigma )}\) in Eq. (17) to increase the threshold in such regions will lead to a better suppression of background noise. Therefore, ACC will be improved. However, some tiny vessels cannot be extracted which leads to a decreased TPR. The average segmentation results of 20 retinal images are TPR: 0.74690 FPR: 0.03175, ACC: 0.93989.

3) Balancing TPR and ACC

We can find this balance by observing the blood vessel network obtained after threshold adjustment. This is the trade-off between the performance index TPR and ACC. The average simulation results are TPR: 0.74841 FPR: 0.03231, ACC: 0.93958.

The experimental results of the three cases are presented in Fig. 11. From Fig. 11, we can see that the details of the red rectangular box marked in \(({c_1})\) are not accurately extracted in \(({c_2})\) and \(({c_3})\). However, there are background noise points segmented wrongly in \(({c_1})\). It is found that TPR is more sensitive to the change of threshold compared with ACC. Therefore, in the regions with low contrast we can obtain an obvious increase of TPR by reducing the threshold only slightly while keeping the decrease of ACC within the acceptable range.

All 20 images of the test set in DRIVE database were used to evaluate the performance of the proposed algorithm. In Table 3, current studies on blood vessel segmentation were listed in groups according to the approaches used. It can be seen that the performance of the proposed algorithm is very competitive compared with other algorithms. For filtering approach, the LAD-OS method performs best. However, it needs to lift the 2D image to 3D orientation scores which increase the complexity. The proposed algorithm does not need domain transformation and performs better than the current matched filtering methods such as MF-FDOG in [26], MPMF in [27], the method in [28] and LID-OS in [29].

It is especially meaningful to compare the proposed algorithm with the algorithm in [26] since the two studies use the same matched filter templates. The difference of these two studies is that the proposed one used dynamic-scale allocation and dynamic threshold processing. The experimental results are shown in Fig. 12. It can be seen that the accuracy of the blood vessel segmentation using the proposed algorithm shown in Fig. 12c is improved obviously compared with the algorithm in [26] shown in Fig. 12b. More narrow blood vessels are extracted. The enhancement of the performance comes from using dynamic multi-scale matched filtering and dynamic threshold processing based on histogram fitting.

Experiments on DRIVE database showed that the proposed method has a good inhibitory effect on the noise and non-vascular structure in the image. However, its performance deteriorates obviously for images with poor lighting conditions, which is worth further investigation.

We recorded the time consumption of the proposed approach on DRIVE dataset. All the experiments were conducted on an Intel Core I7 3.2 GHz CPU. For a single 565584 image, the proposed approach takes 32.63 s in a MATLAB 2014 software, which could be further reduced after code optimization for the actual scene.

Fig. 12
figure 12

a The original image 3 in the DRIVE database; b MF-FDOG; c the proposed algorithm; d the ground truth vessel map

8 Conclusion

In this paper, a new retinal blood vessel extraction method using dynamic multi-scales allocation and dynamic threshold processing based on histogram fitting was proposed. The method can not only effectively inhibit the non-vascular structures with step edges but also can extract more tiny blood vessels which are submerged by noise under the premise of the correct estimation of the blood vessel width. More importantly, the method has a low complexity and is easy to implement. The effectiveness of this algorithm has been proved by experiments.