# Images Segmentation Based on Cutting the Graph into Communities
## 3 Method  
We mapped an undirected graph to the image. The graph node corresponds to each pixel of the image. \(V\) is the set of the graph nodes. We entered the correlation radius \(R\) between the pixels. The correlation radius indicates the maximum distance between pixels whose nodes are connected by an edge in the graph. If \(R=1\) then edges exist only between the nearest neighbors. In this case, the degree of the graph node is 8 if the pixel is not located on the image boundary. If \(R=2\) then each node is connected to the nearest neighbors and the next nearest neighbors. The degree of each node is 24 if the pixel is not located at the image boundary. The edge weight depends on the color coordinates of the pixels corresponding to the graph nodes. We use the RGB color model to encode the image. The three intensities of the base colors \((r(x,y),g(x,y),b(x,y))\) were mapped to the pixel with coordinates \((x,y)\). \(r(x,y)\) is the intensity of red. \(g(x,y)\) is the intensity of green. \(b(x,y)\) is the intensity of blue. The edge weight was calculated based on the distance between the pixels corresponding to the nodes of the graph. The five-dimensional space was used to initially represent the image. The point of this space \(p=(x,y,r(x,y),g(x,y),b(x,y))\) represents a pixel with coordinates \((x,y)\). The choice of a formula for calculating the distance \(d(p,p^{\prime})\) between points \(p\) and \(pt\) was determined by setting the segmentation problem. The image segment includes pixels close to each other in color and different in color from the remaining pixels. The function \(d(p,p^{\prime})\) should depend on the color difference of the pixels. The distance between pixels must increase as the color coordinate difference increases. Pixels of the same segment must be localized in the image. The function \(d(p,p^{\prime})\) should increase as the geometric distance between pixels increases. We used the function of the distance between pixels \(p=(x,y,r,g,b)\) and \(p^{\prime}=(x^{\prime},y^{\prime},r^{\prime},g^{\prime},b^{\prime})\) decreasing in exponential law. \[d(p,pt)=\sqrt{(x-x^{\prime})^{2}+(y-y^{\prime})^{2}}\left(exp\bigg{(}\sqrt{(r- r^{\prime})^{2}+(g-g^{\prime})^{2}+(b-b^{\prime})^{2}}\bigg{)}-1\right). \tag{1}\]  
The distance between pixels is zero if their colors match. The distance between pixels grows rapidly as the color coordinate difference increases. There are other metrics for measuring the distance between points. The Euclidean metric in five-dimensional space requires additional scaling over heterogeneous coordinates. \[d\big{(}p,p^{\prime}\big{)}=\sqrt{(x-x^{\prime})^{2}+(y-y^{\prime})^{2}+(r-r^{ \prime})^{2}+(g-g^{\prime})^{2}+(b-b^{\prime})^{2}}. \tag{2}\]  
This metric does not increase quickly enough when the color changes. A metric growing exponentially across all coordinates leads to the dominance of spatial coordinates over color coordinates. \[d(p,pt)=exp\bigg{(}\sqrt{(x-x^{\prime})^{2}+(y-y^{\prime})^{2}+(r-r^{\prime})^ {2}+(g-g^{\prime})^{2}+(b-b^{\prime})^{2}}\bigg{)}-1. \tag{3}\]  
Image segmentation is equivalent to cutting a graph into subgraphs in this model. Pixels of one segment must be close to each other in color characteristics and differ from another segment pixels. The formula for edge weight depends on the distance between pixels. \[w\big{(}p,p^{\prime}\big{)}=\frac{1}{1+d(p,p^{\prime})}. \tag{4}\]  
The edge weight is 1 if the pixel colors match. The edge weight decreases as the distance between the color coordinates increases. If the color coordinates are different, then the edge weight decreases as the difference between the geometric coordinates of the pixels increases. Nodes of one segment are strongly connected to each other and weakly connected to nodes outside the segment. Communities on graphs meet these requirements [19]. The segmentation problem boils down to the problem of finding a community on graphs. We entered the matrix of edge weights for the graph \(E\).