1 Introduction

Most previous medical diagnosis models are developed based on machine learning methods (Chen et al. 2014), like image segmentation. It is an important basis for medical experts to diagnose the disease, like the cancer, for it is one of the leading causes of human death (Doctor et al. 2014). Numerous segmentation methods have been proposed but none is universally applicable. Recently, active contour methods have been intensively studied and widely used in image segmentation. And some of these methods have been widely used in medical field. The segmentation of medical images helps doctors to diagnose diseases, and related methods have already been done by many people (Tomczyk et al. 2013; Kashyap and Gautam 2017).

Generally, the existing image segmentation models which based on level set methods can be grouped into two categories: edge-based models (Kass et al. 1988; Li et al. 2005; Caselles et al. 1997) and region-based models (Rad et al. 2017; Chan and Vese 2001; Li et al. 2008, 2010; Gelas et al. 2007). The snake model (Kass et al. 1988), geodesic active contour (GAC) model (Caselles et al. 1997) and the new level set method without re-initialization (LSWR) (Li et al. 2005) are typical edge-based models. They have some drawbacks: firstly, these methods are not applicable to images with weak boundaries because they only use edge information. Secondly, they are very sensitive to the noise and highly dependent on the location of initial curve (Caselles et al. 1997; Zhou et al. 2015). Chan–Vese (CV) model (Chan and Vese 2001), region-scalable fitting energy (RSF) (Li et al. 2008), distance regularized level set (DRLSE) (Li et al. 2010), compactly supported radial basis functions (CSRBFs) (Gelas et al. 2007)and CV model combined graph cuts (ACBGC) (Lan and Liu 2012) are all region-based active contour methods. Region-based models are not sensitive to objects with poorly defined boundaries but are sensitive to intensity inhomogeneity of image. Also, they are sensitive to parameter tuning (Cai and Sowmya 2009; Mylona et al. 2014) which are not desirable in practical use.

To address the mentioned problems above, Yang proposed a new level set method for image segmentation (Yang et al. 2015). A Markov random field (MRF) energy function is embedded to the conventional level set energy function. This MRF energy function builds the correlation of a pixel with its neighbors and encourages them to fall into the same region. This method can obtain robust segmentation results in a very short time, but there are several parameters affecting the segmentation performance greatly.

To overcome the mentioned problems above, in this paper, we propose a boundary constraint factor embedded localizing active contour model based on graph cuts optimization. In our method, a constraint factor is added to the energy function in CV model and graph cuts method is used to optimize the energy function of active contour in local regions.

The main contributions of our method are as follows: (1) To solve the problem of traditional region-based active contour method which is non-convergent on the boundaries of the objects in an image, the constant regularizing parameter in the energy function of CV model is replaced by a constraint factor K, which is a function relevant to the location of the pixels in an image. (2) To overcome the drawback of traditional region-based active contour method that it is not applicable to those images with intensity inhomogeneity, the local information of image is added to the energy function of CV model. (3) The active contour methods available always need to adjust several parameters, which have great influence on the segmentation results. By contrast, the proposed method just needs to adjust only one parameter.

The remainder of this paper is organized as follows. Section 2 introduces the details of the proposed method, including the construction of energy function and selection of its local fields. Section 3 validates the proposed method through experimental results compared with different segmentation models on not only medical images but also other image datasets. The conclusion of the whole paper is in Sect. 4.

2 The proposed method

To overcome the aforementioned shortcomings, we present a novel medical image segmentation method by designing a new energy function added with a constraint factor in CV model. Graph cuts method is used to optimize the energy function in local fields to improve the segmentation performance on images with intensity inhomogeneity in our method. This section will introduce the details of the proposed method.

2.1 Local information

To overcome the problem that CV model only consider global information of an image and could not segment images with intensity inhomogeneity efficiently, the local information \({\bar {c}_1}\) and \({\bar {c}_2}\) are introduced into the energy function of CV model. \({\bar {c}_1}\) and \({\bar {c}_2}\) are the average gray value of object and background in local fields \({A_i}\) of an image respectively. In our model, the square region is selected as local field \({A_i}\), as shown in Fig. 1. The center of the square region is the point on the initial curve and the length of square’s sides is r.

Fig. 1
figure 1

Illustration of the local region

2.2 The novel energy function construction

The CV model utilize the gradient decent method to optimize the energy function, which not only lead to local minimum of the energy function, but also need to solve the partial differential equation and do multiple iterations. Based on the problems, Lan et al. proposed a novel active contour model optimizing the energy function via graph cuts (ACBGC) (Lan and Liu 2012), which not only solve the problem that CV model falls into the local minimum easily, but also improve the efficiency of segmentation greatly. The discrete energy function of this model is as following,

$$\begin{aligned} F\left( {{x_1}, \ldots ,{x_{m \times n}}} \right) & =\mu \mathop \sum \limits_{{\left( {p,q} \right) \in {e_k}}} {w_k}\left( {{x_p}\left( {1 - {x_q}} \right)+{x_q}\left( {1 - {x_p}} \right)} \right) \\ & \quad +{\lambda _1}\sum\nolimits_{p} {{{\left| {I\left( p \right) - {c_1}} \right|}^2}} {x_p}+{\lambda _2}\sum\nolimits_{p} {{{\left| {I\left( p \right) - {c_2}} \right|}^2}} \left( {1 - {x_p}} \right) \\ \end{aligned}$$
(1)

where

$${x_t}=\left\{ {\begin{array}{*{20}{c}} {1,}&{\varphi \left( t \right)<0} \\ {0,}&{\varphi \left( t \right) \geq 0} \end{array}} \right.,\quad ~t \in \left\{ {p,q} \right\}$$
(2)
$${c_1}={{\left( {\mathop \sum \nolimits_{p} I\left( p \right){x_p}} \right)} \mathord{\left/ {\vphantom {{\left( {\mathop \sum \nolimits_{p} I\left( p \right){x_p}} \right)} {\left( {\mathop \sum \nolimits_{p} {x_p}} \right)}}} \right. \kern-0pt} {\left( {\mathop \sum \nolimits_{p} {x_p}} \right)}}$$
(3)
$${c_2}={{\left( {\mathop \sum \nolimits_{p} I\left( p \right)\left( {1{\text{-}}{x_p}} \right)} \right)} \mathord{\left/ {\vphantom {{\left( {\mathop \sum \nolimits_{p} I\left( p \right)\left( {1{\text{-}}{x_p}} \right)} \right)} {\left( {\mathop \sum \nolimits_{p} \left( {1{\text{-}}{x_p}} \right)} \right)}}} \right. \kern-0pt} {\left( {\mathop \sum \nolimits_{p} \left( {1{\text{-}}{x_p}} \right)} \right)}}$$
(4)

where \(m\) and \(n\) are the number of rows and columns in an image respectively. \({w_k}\) is the weight of edges which connect one pixel with its 4 neighboring pixels. \({e_k}\) is the edge that connect two adjacent pixels p and q in the image, \(I\left( p \right)\) is the gray value of the pixel p in an image. \({x_p}\) and \({x_q}\) are labels of two adjacent pixels \(p\) and \(q\). \({c_1}~\) and \({c_2}\) represent the mean gray value of pixels which in the inside and outside of the contour curve in the whole image.

The ACBGC model has solved the problem that CV model falls into local minimum easily, however it only consider the global information of an image, which has limitations on segmenting intensity inhomogeneity images, such as medical images. Besides, the regularizing parameter \(\mu\)of energy function F in (1), which is used to trade off the edge and region terms, often influences the segmentation results greatly. Furthermore, it is difficult to determine the optimal regularizing parameter \(\mu\) for different image sets.

As we know, the evolution curve is driven by the minimum energy function in active contour method. When the initial curve is approaching to the object boundaries, the curve will not evolve and the energy function will be zero. Generally, the energy function is usually not zero when the evolution curve is approaching to the object boundaries in many real situations. To solve the aforementioned two problems, we introduce the local information of boundaries and a constraint factor K into the energy function F. The discrete energy function of our model can be expressed as following,

$$\begin{aligned} F({l_1}, \ldots ,{l_{{m_0} \times {n_0}}}) & =K \times \left\{ {\sum\limits_{{\left( {p,q} \right) \in {e_k}}} {{w_k}\left( {{l_p}\left( {1 - {l_q}} \right)+{l_q}\left( {1 - {l_p}} \right)} \right)} } \right\} \\ \,&\quad +{\lambda _1}{\sum\nolimits_{p} {\left| {{I_i}\left( p \right) - \overline {{{c_1}}} } \right|} ^2}{l_p}+{\lambda _2}{\sum\nolimits_{p} {\left| {{I_i}\left( p \right) - \overline {{{c_2}}} } \right|} ^2}\left( {1 - {l_p}} \right) \\ & \quad s.t.p \in {A_i},q \in {N_i} \\ \end{aligned}$$
(5)

where \({m_0}\) and \({n_0}\) are the number of rows and columns in the local field \({A_i}\) respectively. \({e_k}\) is the edge which connect two adjacent pixels p and q in local field \({A_i}\), \({N_i}\) is the neighborhood of the pixel p. The constraint factor \(K\) can be expressed as,

$$K=\sum\nolimits_{p} {\hbox{max} \left( {\left( {K1+K2} \right),0} \right)}$$
(6)

where,

$$K1={\left( {{I_i}\left( p \right) - {{\bar {c}}_1}} \right)^2} \times {\left( {{I_i}\left( q \right) - {{\bar {c}}_1}} \right)^2}$$
(7)
$$K2={\left( {{I_i}\left( p \right) - {{\bar {c}}_2}} \right)^2} \times {\left( {{I_i}\left( q \right) - {{\bar {c}}_2}} \right)^2}.$$
(8)

And \({\bar {c}_1}=\frac{{\mathop \sum \nolimits_{p} {I_i}\left( p \right){l_p}}}{{\mathop \sum \nolimits_{p} {l_p}}}\), \({\bar {c}_2}=\frac{{\mathop \sum \nolimits_{p} {I_i}\left( p \right)\left( {1 - {l_p}} \right)}}{{\mathop \sum \nolimits_{p} \left( {1-{l_p}} \right)}}\), where \({\bar {c}_1}\) and \({\bar {c}_2}\) are the average gray value of object and background in the local field \({A_i}\) of an image respectively. \({l_p}\) and \({l_q}\) are the labels of two adjacent pixels p and q in the local field \({A_i}\). \({I_i}\left( p \right)\) is the gray value of pixel p in local fields \({A_i}\) defined in Sect. 2.1.

2.3 Optimization of the energy function

Since Boykov first applied Graph Cuts to the foreground segmentation (Boykov and Jolly 2001), Graph Cuts is becoming more and more popular in the field of image segmentation. The image is firstly regarded as a weighted graph. The vertexes of this graph are pixels of the image and the weights of the edges are given by the energy function F in our method. Then a minimum cut which separates the background and object can thus be computed very efficiently by mix cut/max flow algorithm (Boykov and Kolmogorov 2004). At the same time, the energy function is minimum. Namely, the energy function is optimal when the minimum cut is found.

2.4 Flexibility analysis of our proposed method

As we know, in active contour method, when the initial curve is approaching to the object boundaries, the curve will not evolve and the energy function will be zero. But generally, the energy function is usually not zero when the evolution curve is approaching to the object boundaries in most CV or other active contour methods based CV.

In order to overcome the drawback of traditional CV model, a constraint factor \(K\) is added into the energy function, which ensures that the energy function reaches zero at the object boundaries. As aforementioned, the pixel p which is adjacent to the object boundary has different label with the pixel q which is in the 4-neighbourhoods of the pixel p. The cases are shown in the Fig. 2.

Fig. 2
figure 2

The 4-neighbourhoods system

In the energy function of CV model, the first term \(\left\{ {\sum {\left( {{x_p}\left( {1 - {x_q}} \right)+{x_q}\left( {1 - {x_p}} \right)} \right)} } \right\}\) is not 0 when the initial curve is approaching to the object boundaries. While in our proposed energy function, if the labels \({l_p}\) and \({l_q}\) of the pixel p and pixel q are 1 and 0 respectively, which indicate that the gray value \({I_i}\left( p \right)\) of the pixel p is more similar to the average gray value \({\bar {c}_1}\) of an object and the gray value \({I_i}\left( q \right)\) of the pixel q is more approximated to the average gray value of the background \({\bar {c}_2}\). Thus, \(K1={\left( {{I_i}\left( p \right) - {{\bar {c}}_1}} \right)^2} \times {\left( {{I_i}\left( q \right) - {{\bar {c}}_1}} \right)^2}\) is equal to zero and \(K2={\left( {{I_i}\left( p \right) - {{\bar {c}}_2}} \right)^2} \times {\left( {{I_i}\left( q \right) - {{\bar {c}}_2}} \right)^2}\) is also equal to zero. That is, the constraint factor \(K=\hbox{max} \left( {\left( {K1+K2} \right),0} \right)\) is equal to zero, which implies that the energy function is equal to zero too. Therefore, it guarantees our proposed energy function is 0 by adding a constraint factor \(K\) when the evolution curve is approaching to the object boundary. Then the problems and the difficulties in segmenting medical images have been overcome.

3 Experimental results and analysis

Note that our method is based on CV model and take local information into consideration. We compare the proposed method with CV and ACBGC which are CV based. We also compare the proposed method with RSF who also consider the image information in local regions. Besides, we compare our proposed method with the state-of-the-art edge-based method, LSWR and region-based method, MELS. All experiments conducted in this paper are carried out on Matlab2011b installed on PC with a 2.93 GHz Intel Core Processor and 4 GB of RAM.

Our experiments are divided into two parts. The first part illustrates the accuracy and the effectiveness of the proposed method compared with other six methods on medical images, including the GAC, CV, LSWR, RSF, ACBGC and MELS. In this part, we conduct experiments on three types of medical images including blood vessel images, mammograms masses and knee MRI and CT images to validate the performance of our proposed method. The second part of this section demonstrates the robustness and extendibility of the proposed method on a wide variety of image datasets, including synthetic images with intensity inhomogeneity, images with multiple objects and images with complex background.

3.1 Comparison on medical images

Blood pressure is one of the significant vital signs of health (Lee et al. 2018). The segmentation of the blood vessel images is important since the blood vessel is closely related to blood pressure. In experiment 1 of this section, we compare the proposed method with six methods on blood vessel images. The blood vessel images are obtained from (Li et al. 2008). The results are shown in Fig. 3. Figure 3a shows the blood vessel images with initial contour. Figure 3b–h shows the binary segmentation results by the six models mentioned above and our proposed model. The results in Fig. 3b–d, f, g show that GAC, CV, ACBGC, LSWR and MELS fail to detect the object boundaries because there are illumination changes and shadows in images. As shown in Fig. 3e′, e″, we can conclude that when the optimal parameters are selected, the better results can be obtained by RSF. But the method is influenced by several parameters and these optimal parameters cannot be determined easily for it is difficult and troublesome for people to adjust parameters. As shown in Fig. 3h, the proposed model achieves the satisfied and desired results not only in pretty smooth edges, but also in some details because of the introduction of the local fields and a constraint factor into energy function. The execution time of GCA, CV, ACBGC, LSWR, RSF, MELS and the proposed method are given in Table 1. As shown in Table 1, our proposed method keeps the faster segmentation speed than GCA, CV, LSWR, RSF, MELS. While ACBGC achieves the least execution time on image segmentation due to its fast implementations. However, ACBGC fails to segment the blood vessel accurately, shown in Fig. 3d.

Fig. 3
figure 3

The results on blood vessel images: a initial contour, b GAC, c CV, d ACBGC, e′ RSF with optimal parameters, e″ RSF with different parameters, f LSWR, g MELS, and h our proposed method

Table 1 The execution time of different methods

Besides, the number of parameters of different methods is shown in Table 2. There is only one parameter needs to be adjusted in ACBGC and our proposed method.

Table 2 The number of parameters of different methods

Image segmentation is vital in computer-aided diagnosis, such as the segmentation of mammograms masses, which is widely used in clinical diagnosis. However, masses segmentation is a challenging task since masses may usually connect with some surrounding tissues which have the similar intensity with masses and the intensity in mammograms is not symmetrical (Domínguez and Nandi 2007).

In experiment 2 of this section, several classical and latest methods whose basic ideas are similar to our method are performed on MIAS dataset. The dataset is digitized at 8-bits per pixel with size about pixels. The whole database consists of 161 cases with 322 mammograms, which is divided into 3 categories, 208 images with no masses, 63 images with benign masses and 51 images with malignant masses. From the samples show in Fig. 4, we find these mammograms contain a mass with different types of outlines (smooth, ambiguous and complex) or more in vague background. The results suggest that the proposed method is more insensitive to intensity inhomogeneity than other methods. Additionally, the other methods segment more tissues because these tissues have similar intensity with the true mass.

Fig. 4
figure 4

The results on mammograms masses of MIAS dataset: a initial contour, b GAC, c CV, d ACBGC, e LSWR, f RSF, g MELS, and h our proposed method

Since the MIAS dataset is so small and the case is a little simple, another medical dataset is applied to test our proposed method. The same experiments are conducted on DDMS dataset which is provided by University of South Florida (Heath et al. 2000). The mammograms of this dataset are digitized with a LUMISYS and HOWTEK laser scanner at a pixel size of 0.5 or 0.45 mm and 12-bits or 16-bit per pixel. All the masses are marked by radiologists, while only the approximate peripheries of masses are described (Wang et al. 2011). The results are shown in Fig. 5. As we can see, the proposed method detects the desired boundaries of the mass correctly.

Fig. 5
figure 5

The results on mammograms masses of DDMS dataset: a initial contour, b GCA, c CV, d ACBGC, e LSWR, f RSF, g MELS, h our proposed method, and i ground truth

In experiment 3 of this section, we compare the proposed method with six methods on knee magnetic resonance imaging (MRI) and computed tomography (CT) images. The comparison results are shown in Fig. 6. From Fig. 6, we can see that only the proposed method can segment the femur and tibia correctly. And the other methods segment more tissues which have similar intensity with the femur and tibia.

Fig. 6
figure 6

The results on knee MRI and CT images: a initial contour, b GCA, c CV, d ACBGC, e LSWR, f RSF, g MELS, and h our proposed method

3.2 Comparison on other images

To verify the extensibility and robustness of the proposed method against other database, including synthetic images with intensity inhomogeneity, images with multi real objects, and natural images with complex background, three experiments are conducted and the proposed method is compared with six state-of-the-art segmentation methods, GAC, CV, LSWR, RSF, ACBGC and MELS. In order to demonstrate that our method is insensitive to the position of initial contour, we select the initial evolution curve randomly in this section.

In experiment 1 of this section, we compare the proposed method with six state-of-the-art methods on images with intensity inhomogeneity. The luminance of background or foreground in these images is different and there are shadows of the object in these images, which both effect the segmentation performance heavily. Figure 7a shows examples with intensity inhomogeneity. Figure 7b shows the initial contour randomly, Fig. 7c–i show the segmentation results by the six models mentioned above and our proposed model. The results of Fig. 7c–f show that GCA, CV, ACBGC and LSWR fail to detect the object boundaries because there are illumination changes and shadows in images obviously. The RSF method may obtain better results when the optimal parameters are found. While these optimal parameters cannot be determined easily. The results obtained by MELS method, shown in Fig. 7h, are not satisfied. The proposed model achieves the satisfied and desired results, shown in Fig. 7i.

Fig. 7
figure 7

The results on synthetic images with intensity inhomogeneity: a original images, b initial contour, c GAC, d CV, e ACBGC, f LSWR, g RSF, h MELS, and i our proposed method

Experiment 2 is conducted on the images with multiple real objects, different gray values, different object sizes and different object shapes, as shown in Fig. 8. The first six rows illustrate the initial contour marked on one object in images. When we give the initial evolution on an object, which means we just need segment one object only. From Fig. 8, we can see when we give the initial evolution on an object, CV, ACBGC, and RSF model get two objects while MELS and our method detect the marked object only (the first six rows). However, when the parameter r is increased, two objects are achieved in our method, such as r = 60 shown in last column in Fig. 8h″. The seventh to ninth rows give the evolution curve containing both two objects in sample images. Almost all methods can achieve the good results expect LSWR and GCA because the initial curve will be evolved in one direction, dilating outward or constricting inward. So the LSWR can obtain the better results when the initial curve covers the object to be segmented or the initial curve is involved in the object. During the comparison among all of classical methods, we can see our model is more flexible and robust.

Fig. 8
figure 8

The results on images with multiple objects: a original images with initial contour, b GAC, c CV, d ACBGC, e LSWR, f RSF, g MELS, h′ our proposed method (r = 6), and h″ our proposed method (r = 60)

In experiment 3, GCA, CV, ACBGC, LSWR, RSF and MELS are applied on natural images with very complex background taken from BSDS500 dataset (Arbelaez et al. 2011), as shown in Fig. 9. It is obviously that our method can detect the object boundary from the complex background more completely and accurately. The details are shown in the Fig. 9i.

Fig. 9
figure 9

The results on natural images with very complex background: a original images, b initial contour, c GAC, d CV, e ACBGC, f LSWR, g RSF, h MELS, and i our proposed method

In order to evaluate our proposed model objectively, the accuracy of target region segmentation can also be assessed quantitatively and objectively by IOU (Kihara et al. 2016),

$$IOU=\frac{{GT \cap D}}{{GT \cup D}}$$
(9)

where \(GT\) is the ground truth, \(D\) is the segmentation result obtained by the models mentioned above. Table 3 gives the IOU values of different methods shown in Figs. 5 and 8.

Table 3 The IOU of different methods

As show in Table 3, the bold values are the highest values compared with other values in Table 3. As we known, the higher score on IOU means that the method is more accurate. So, our proposed method obtains the more accurate results on medical images and natural images.

4 Conclusion

In this paper, a boundary constraint factor embedded localizing active contour model based on graph cuts optimization is proposed for medical images and nature images segmentation. A new energy function is constructed by adding a constraint factor into the energy function of CV model, which ensures that the energy function is always zero at the object boundary. And more accurate boundary can be obtained by our method. The local information of images is added into the energy function, which overcome the drawbacks of traditional CV based methods that they cannot segment images with intensity inhomogeneity. Last but not least, our method has only one parameter which need not take much time to find optimal parameters and the human burden can be reduced. Experimental results also demonstrate that the proposed method not only can obtain relatively better results on medical images, but also have satisfied results on other types of datasets, such as synthetic images with intensity inhomogeneity, images with multiple objects and images with complex background. However, the run efficiency of our algorithm is slow. So, future works can be an implementation of the proposed method using a parallel device such as the GPU (Engel et al. 2015; Wu et al. 2018) in order to accelerate real-time images segmentation or introducing the ranking metric mechanism (Zou et al. 2016) for candidate pixels.