# CPDet: Circle-Permutation-Aware Object Detection for Heat Exchanger Cleaning
## 3 Materials and Methods
### Improvements in Circle Representation  
In object detection, objects are typically enclosed within rectangular bounding boxes, with their positions defined by the coordinates of opposite corners. However, for specialized datasets of heat exchangers, rectangular bounding boxes can be suboptimal, because rectangular bounding boxes introduce excess margins around circular objects, leading to imprecise localization and potentially false detections. This limitation was highlighted by [37], which studied medical cell detection, and their findings underscored the need for bounding shapes that match the geometry of the objects being detected. Inspired by these observations, this work proposed the representation of circle boxes for the detection of circle holes in heat exchanger datasets. This approach not only aligns more intuitively with the actual shape of the objects but also provides a more precise description of their location. Defining the circle box through its center and radius ensures that every point on the circumference of the object is accurately captured, minimizing the area of false inclusion or exclusion. This leads to a more accurate assessment of the position and size of circle holes, which is crucial for applications requiring high precision. Specifically, we calculated the center coordinates and the width and height of the bounding box based on the annotated top-left and bottom-right corner coordinates and chose the smaller value between the width and height to calculate the circle radius, which is shown in Equation (11). \[(c_{x},c_{y}) =\left(\frac{x_{1}+x_{2}}{2},\frac{y_{1}+y_{2}}{2}\right)\] \[r =\frac{\min(w,h)}{2}, \tag{11}\]  
where \((x_{1},y_{1})\), \((x_{2},y_{2})\), and \(w,h\) denote the top-left and bottom-right coordinates, as well as the width and height of the bounding box, respectively. In accordance with the computed center coordinates and radius, circle boxes were delineated upon the primitive image canvas. Employing the Bresenham algorithm completed the rendering of a circle box; this algorithm facilitates the identification of points proximate to the circumference on a lattice of discrete pixels. Leveraging the octagonal symmetry intrinsic to circles, it suffices to calculate points confined to the segment beneath the 45-degree line (the line defined by  
Figure 7: Details of the prior-guided sparse attention module. \(y=x\)) within the first quadrant of the coordinate system. Subsequently, the symmetry property was harnessed to extrapolate and complete the rendering of the entire circle. To this end, a pivotal decision variable, denoted as \(D\), was introduced to ascertain which pixel should be elected as the succeeding point at each iterative juncture. Initially, \(D\) was established as in Equation (12). The choice of this initial value is critical, as it enables the algorithm to utilize integer arithmetic solely during its iterative progression, thus enhancing both the speed and accuracy of computation concurrently, where the initial point is set as Equation (12)  
\[D=3-2r,\;(x,y)=(0,r), \tag{12}\]  
At each iterative step, the algorithm indicates to pixel \(p\) whether to move one pixel \(p_{e}\) in the \(x\) direction alone or to shift a pixel \(p_{s}\) simultaneously in both the \(x\) and \(y\) directions, as shown in Equation (13), which is contingent upon the current value of the decision variable \(D\). \[D= \begin{cases}D+2x+3&\text{if }D<0\\ D+2x-2y+5&\text{if }D\geq 0\end{cases}  \tag{13}\]  
And iterate the value of \(x\) and \(y\) shown in Equation (14) until \(x\geq y\). \[x_{new}=x+1,\;y_{new}= \begin{cases}y&\text{if }D<0\\ y-1&\text{if }D\geq 0\end{cases}  \tag{14}\]  
Finally, taking advantage of the symmetry of the circle, we found the corresponding points in the other seven quadrants and plot pixels at these locations to complete the drawing of the entire circle. The entire drawing process is illustrated below in the Pseudocode Algorithm 1.