# Skin Lesion Segmentation in Dermoscopic Images with Combination of YOLO and GrabCut Algorithm
## 3 Materials and Methods
### GrabCut Algorithm  
GrabCut is an iterative semiautomatic image segmentation technique [12]. In this technique, the image to be segmented is represented by a graph. This graph is built by using a minimum cost reduction function to produce the best segmentation of the image. The created graph nodes consist of the image pixels. In other words, each pixel in the image is symbolized by a node in the graph. In addition to these nodes, two extra nodes called sink and source, are added to the graph. Each pixel in the image, namely the nodes in graph, is connected to either of these two nodes. The source node represents the connection point of the foreground pixels while the sink node symbolizes the connection point of the background pixels. A cost function is used for the definition of the edge weights of the graph depending on the region and boundary information in the image. A Min-Cut/Max-Flow technique is used to segment the graph. The GrabCut technique uses Gaussian Mixture Models (GMMs) [68] obtaining the region information by using the color knowledge in the image. The mathematical expression of the algorithm is as follows. Given an RGB color image as \(I,p=(p_{1},p_{2},\cdots,p_{N})\) of \(N\) pixels where \(p_{i}=(R_{i},G_{i},B_{i})\), \(i\in[1,\cdots,N]\) in the RGB color space. The segmentation is described as an array as in \(s=(s_{1},s_{2},\cdots,s_{N})\), \(s_{i}\in\{0,1\}\) and a label is assigned for each pixel of image describing its relation to the background or foreground. Figure 9: DarkNet-53 architecture [13]. At the beginning of the algorithm, the user defines a rectangle \((R)\) semi-automatic including the area to be segmented. After the definition of the \(R\) by the user, the image is divided into three regions called \(R_{B}\), \(R_{F}\), and \(R_{U}\), representing the initial values of the background, the foreground, and the uncertain pixels. The pixels outside of the \(R\) are considered to be \(R_{B}\) while the pixels inside the rectangle are taken as \(R_{U}\). GrabCut finds out whether the \(R_{U}\) pixels belong to the background or the foreground. For this purpose, it utilizes the color information provided by GMMs. A full covariance GMMs of \(C\) components are defined for foreground pixels \((s_{i}=1)\), and another one for background pixels \((s_{i}=0)\), parametrized as the following formula:  
\[\theta=\{\pi(s,c),\omega(s,c),\Sigma(s,c),s\in\{0,1\},c=1,\cdots,C\} \tag{5}\]  
where \(\pi\) indicates the weights, \(\omega\) represents the means of the GMMs and \(\sum\) the covariance matrices of the model. The array \(c=(c_{1},\cdots,c_{i},\cdots c_{N})\), \(c_{i}\in(1,\cdots,C)\), \(i\in[1,\cdots,N]\) is also taken into account representing the component of the foreground or background GMMs (according to \(s_{i}\)) the pixel \(p_{i}\) belongs to. The energy function revealed for segmentation is as follows:  
\[E(s,c,\theta,p)=U(s,c,\theta,p)+V(s,p) \tag{6}\]  
where \(U\) is the likelihood potential, based on the probability distributions \(pr(\cdot)\) of the GMMs:  
\[U(s,c,\theta,p)=\sum\
olimits_{i}-\log pr(p_{i}\mid\mathrm{s}_{i},c_{i}, \theta)-\log\pi(s_{i},c_{i}) \tag{7}\]  
and \(V\) is a regularizing prior assuming that segmented regions should be coherent in terms of color, considering a neighborhood \(C\) around each pixel. \[V(s,p)=\gamma\sum\
olimits_{\{m,n\}\in C}[s_{n}\
eq s_{m}]\exp(-\beta\|p_{m}- p_{n}\|^{2}) \tag{8}\]  
This energy minimization scheme applies to the image with a given initial rectangle. Final segmentation obtained using a minimum cut operation is presented in Figure 10.  
Summary of the GrabCut algorithm:  
1. The initial step starts with a rectangle surrounding the object of interest that is drawn by the user manually. This step gives information about background and foreground of the interested area. The pixels inside of the rectangle considered as unknown while the pixels outside of the rectangle are considered as background.