## 2 Urban Pipeline Gas Leak Sensor Placement Method
### Urban Pipeline Image Processing  
In image processing, color filtering and morphological operations are essential techniques for extracting target areas and eliminating noise. This study proposes an image processing method combining color filtering and morphological opening to extract pipeline information and remove noise from urban pipeline images.  
Initially, the pipeline sections are extracted from the image using a color filtering method in the RGB color space. Each pixel's color value in the RGB space is represented as follows:  
\[I(x,y)=[R(x,y),G(x,y),B(x,y)] \tag{4}\]  
where \(R\), \(G\), and \(B\) represent the intensities of the red, green, and blue channels, respectively. To extract the green parts, the following color filtering conditions are defined:  
\[Mask(x,y)=\left\{\begin{array}{ll}1&L_{R}\leq R(x,y)\leq U_{R}\cap L_{G} \leq G(x,y)\leq U_{G}\cap L_{B}\leq B(x,y)\leq U_{B}\\ 0&\text{otherwise}\end{array}\right. \tag{5}\]  
where \(L_{R}=0\), \(U_{R}=128\), \(L_{G}=128\), \(U_{G}=255\), \(L_{B}=0\), and \(U_{B}=153\). This mask filters out the green parts of the image, resulting in a binary mask image of the green pipelines.  
To further eliminate noise, a morphological opening operation is performed on the binary mask of the green pipelines. The opening operation consists of an erosion followed by a dilation, represented by the following:  
\[I_{\text{open}}=(I\ominus B)\oplus B \tag{6}\]  
where \(\ominus\) represents the erosion operation, \(\oplus\) represents the dilation operation, and \(B\) is the structuring element. In this method, a disk-shaped structuring element with a radius of 1 is used to perform the opening operation, aiming to remove small noise areas without compromising the connectivity of the pipelines.  
After noise removal, the mask is used to redraw the pipeline sections in the original image. Specifically, the portions marked as green pipelines in the mask are replaced with black to enhance the visualization of the pipelines. The final result sets all pixels that meet the mask conditions to black:  
\[I(x,y)=[0,0,0,255]\text{ if Mask}(x,y)=1 \tag{7}\]  
To accurately detect pipeline intersections, this paper first applies skeletonization to the extracted pipeline sections. Skeletonization is an image processing technique used to simplify the shape of an object into a thin, line-like structure while preserving its topological structure. In pipeline images, skeletonization reduces the width of the lines, making it easier to detect intersections.  
The skeletonization operation can be represented as follows:  
\[I_{\text{skeleton}}=Skeleton\ (I_{line}) \tag{8}\]  
where \(I_{line}\) is the extracted pipeline image, and \(I_{\text{skeleton}}\) is the result after skeletonization.  
After skeletonization is completed, a corner detection algorithm (such as Harris corner detection) is used to identify pipeline intersections. Corner detection is used to identify points in the image where there are significant changes in brightness, typically applied to extract corners or intersections of objects. The mathematical representation of corner detection is as follows:  
\[C(x,y)=\det(H(x,y))-\alpha\times(trace(H(x,y))) \tag{9}\]where \(H(x,y)\) is the Harris matrix, \(C(x,y)\) is the corner response value, and \(\alpha\) is a constant. The corner detection will output the positions of the intersections, which will be used to mark the nodes.  
After detecting the intersections, circles are drawn at these points to mark key nodes. The radius of the circles can be set based on the specific needs of the image. The operation of drawing a circle is achieved by setting the center \((x_{i},y_{i})\) and the radius \(r\), and the formula is as follows:  
\[(x-x_{i})^{2}+(y-y_{i})^{2}=r^{2} \tag{10}\]  
where \((x_{i},y_{i})\) are the coordinates of the intersection points, and \(r\) is the radius of the circle. In this study, red circles are used to mark these important nodes.