# Images Segmentation Based on Cutting the Graph into Communities
## 6 Calculating the Width of a Road  
We considered rays in the optical system to determine the real width of the road. Parameter \(D\) is the real width of the road. Parameter \(d\) is the width of the road in the image. The width of the road in the image depends on the measurement point due to the perspective effect. Parameter \(y_{1}\) is the height from the top edge of the image at which the road width \(d\) is measured. This point in the image corresponds to a point at a distance \(S\) from the camera. Parameter \(h\) is the height of the camera above the road. Parameter \(r\) is the distance from the lens to the matrix in the camera. The optical system parameters are shown in Figure 9.  
The height of the point in the image and the distance to the point on the road are related by the formula (Figure 9a). \[\frac{h}{S}=\frac{y_{1}}{r}. \tag{15}\]  
We write down the formula for a thin lens. \[\frac{1}{S}+\frac{1}{r}=\frac{1}{f}. \tag{16}\]  
Parameter \(f\) is the focal length of the lens. \[r=\frac{fS}{S-f}. \tag{17}\]  
This expression is substituted in formula (13). \[S=f\bigg{(}1+\frac{h}{y_{1}}\bigg{)}. \tag{18}\]  
The selection of fixed values \(h\) and \(y_{1}\) results in measuring the width of the road at the same distance from the camera. If the shooting is performed on a fixed hardware platform, then \(h\) remains the same. Value \(y_{1}\) is a parameter of the algorithm. This parameter is fixed in the program. We write down the formula for the width of the road (Figure 9b). \[\frac{D}{S}=\frac{d}{r}. \tag{19}\]  
Figure 9: The optical system parameters. (**a**) Imaging the road in the lens, (**b**) parameters in the image. The expression (15) is substituted into this formula. \[D=d\frac{S-f}{f}. \tag{20}\]  
The formula (16) is used for \(S\). \[D=d\frac{h}{y_{0}}. \tag{21}\]  
\(d\) is measured in meters in this formula. The algorithm measures \(d\) in pixels in the image. The coefficient \(t\) converts the distance in pixels into meters. \(t\) depends on the resolution of the camera. \[D=d\frac{th}{y_{1}}. \tag{22}\]  
The new factor \(k\) is introduced for ease of calculation. \[\frac{h}{S}=\frac{y_{1}}{r}. \tag{15}\]0  
This factor defines the specifications for image acquisition. It depends on the camera used and its position. \[\frac{h}{S}=\frac{y_{1}}{r}. \tag{15}\]1  
Parameter \(k\) can be obtained by calibration the system. Several photos of roads with a known width are necessary for calibration. The algorithm determines the width \(d\) for these shots. Coefficient k is calculated from known values \(D\), \(d\) and \(y_{1}\). The average value \(k\) is used in further system operation. The width of the road in the photo is calculated based on the straight equations for the road boundaries. The value \(y_{1}\) is substituted in Equation (9). \[ \begin{array}{l}y_{1}=a_{1}x_{1}+b_{1},\\ y_{1}=a_{2}x_{2}+b_{2}.\end{array}  \tag{25}\]  
The coordinate values \(x_{1}\) and \(x_{2}\) are calculated from these equations. The width of the road is defined as the difference between the two values. \[d=x_{2}-x_{1}. \tag{26}\]  
The width of the road in the image is expressed through the equation's coefficients for lines. \[d=y_{1}\bigg{(}\frac{1}{a_{2}}-\frac{1}{a_{1}}\bigg{)}+\bigg{(}\frac{b_{1}}{a _{1}}-\frac{b_{2}}{a_{2}}\bigg{)}. \tag{27}\]  
The width of the real road is calculated by substituting formula (27) into formula (25). \[D=k\bigg{(}\frac{1}{a_{2}}-\frac{1}{a_{1}}+y_{1}\bigg{(}\frac{b_{1}}{a_{1}}- \frac{b_{2}}{a_{2}}\bigg{)}\bigg{)}. \tag{28}\]  
We used a value of \(y_{1}=3M/4\). \(M\) is the height of the image in pixels. These formulas apply only to the horizontal road. If the road is on the rise, then the formula gives an increased value for the width of the road. If the road slopes, then the formula gives an underestimated value. The presence of a road slope or rise is determined by the position of the horizon line in the image. For a horizontal road, the horizon line is located in the middle of the image. The horizon line is above the middle of the image for rising.