# A Prostate MRI Segmentation Tool Based on Active Contour Models Using a Gradient Vector Flow
## 2 Materials and Methods
### Implementation of the Proposed Active Contour Model
#### 2.3.1 Region-Based Model Matching--Term \(J_{1}(\phi)\)  
The aim of this term is to split the image space \(\Omega\) into two regions that contain homogeneous pixels: the object and the background. Let's call them \(\Omega_{1}\) and \(\Omega_{2}\), respectively. These two regions are separated by the contour \(C\). An homogeneous region implies a region where all the pixels that are contained in it are described by the same stochastic model. The points that belong to the object have intensities \(u_{1}=\{u_{i,j}:(i,j)\in\Omega_{1}\}\), and they are described by the model \(M_{1}\), and the ones that belong to the background have values \(u_{2}=\{u_{i,j}:(i,j)\in\Omega_{2}\}\), and they are represented by the model \(M_{2}\).  
The idea of the model is as follows: let's consider the image \(u_{0}\) to be formed by two regions, of piecewise-constant intensities \(c_{1}\) and \(c_{2}\), and that the intensities of the object are represented by \(c_{1}\). The boundary of this region is \(C_{0}\). Then, the pixel values of the image \(u_{0}\) are \(c_{1}\) inside \(C_{0}\), and \(c_{2}\) outside of it. Given this, it is possible to build the following fitting term:  
\[F(C)=F_{1}(C)+F_{2}(C)=\int_{inside(C)}|u_{0}(x,y)-c_{1}|^{2}dxdy+\int_{outside (C)}|u_{0}(x,y)-c_{2}|^{2}dxdy \tag{4}\]  
where \(C\) is any variable curve, and \(c_{1}\) and \(c_{2}\) are two constants that depend on the contour \(C\). Based on the previous explanation, if \(C=C_{0}\), then \(F(C)\) is approximately zero, because each distance between the image value and the constant \(c_{i}\) are approximately zero for each region. If the curve \(C\) is outside \(C_{0}\), then its interior contains parts of the object and parts of the background, while the exterior of \(C\) contains only elements of the background. Because of this, \(F_{1}(C)>0\) and \(F_{2}(C)\approx 0\). In the backwards case, i.e., the contour \(C\) is smaller than \(C_{0}\), the outside contains parts of the object and the background, whilst the inside only contains parts of the object. It follows that \(F_{1}(C)\approx 0\) and \(F_{2}(C)>0\). Finally, this fitting function can be used to find the boundaries of the object, by minimizing its value such as  
\[\underset{C}{inf}\{F_{1}(C)+F_{2}(C)\}\approx 0\approx F_{1}(C_{0})+F_{2}(C_{0}) \tag{5}\]  
In order to achieve this boundary, the evolution of the curve \(C\) is done by moving pixels from the exterior to the interior of the contour, and vice-versa. The first estimation of the energy function for this prior is in Equation (6):  
\[J_{0}(C)=p(u|C,M_{1},M_{2}) \tag{6}\]  
where \(p\) is the probability density function of the image intensities \(u\), given the contour \(C\), and the models \(M_{1}\) and \(M_{2}\). Over these probabilities, it is assumed that each element, object and background, are statistically independent, and they have pdfs \(p_{1}\) and \(p_{2}\), respectively. Moreover, the pixel intensities are considered to be independent from each other. With these assumptions, and taking the negative of the logarithm of the pdfs, the Equation (6) becomes Equation (7).  
\[J_{1}(C)=\sum_{(i,j)\in\Omega_{1}}-\ln(p_{1}(u_{ij}))+\sum_{(i,j)\in\Omega_{2} }-\ln(p_{2}(u_{ij})) \tag{7}\]  
Assuming a continuous function, the contour embedded in the zero level-set function \(\phi\), and considering the Heaviside function in order to create a single integral over all the domain of the image, the Equation (7) can be generalized as shown in Equation (8).  
\[J_{1}(\phi)=\int_{\Omega}-\ln[p_{1}(u(x,y))]H(\phi(x,y))-\ln[p_{2}(u(x,y))](1- H(\phi(x,y)))dxdy \tag{8}\]  
It is assumed that both elements in the image follow a Gaussian distribution, with means \(m_{1}\) and \(m_{2}\), and variances \(\sigma_{1}^{2}\) and \(\sigma_{2}^{2  
\[I_{2}(\phi)=\int_{\Omega}Y(x,y)\delta(\phi(x,y))|\
abla\phi(x,y)|dxdy \tag{10}\]  
where \(\delta(\phi(x,y))\) will return non-zero values only for the pixels that are on the contour \(C\).