# Infrared Image Superpixel Segmentation Based on Seed Strategy of Contour Encoding
## 3 Methodology
### Contour Encoding  
Most superpixel segmentation algorithms perform an undifferentiated segmentation operation on each part of the image while ignoring the image structure. In general, pixels around edges are the focus of segmentation. Image contours, which represent the boundaries between different regions, provide an efficient global clue. The homogeneous region map \(\psi\) can be initially generated by the contour map, and its guiding principle is that pixels surrounded by the same edge have a high similarity measure and a higher probability of belonging to the same objective region. An example is shown in Figure 2, where \(p_{i}\), \(p_{j}\), and \(p_{s}\) are three pixels. The pixels \(p_{i}\) and \(p_{j}\) are surrounded by the same contour, implying that their path \(l_{ij}\) is not crossed by edge \(e\), such that they have higher similarity. To the contrary, the pixels \(p_{j}\) and \(p_{s}\) are separated by edge \(e\), which means that their path \(l_{js}\) is discontinuous, such that low similarity should be assigned. Therefore, \(p_{i}\) and \(p_{j}\) belong to the same superpixel, while \(p_{s}\) belongs to another.  
Figure 1: Block diagram of the proposed methodology.  
Based on the above analysis, the similarity between pixel pairs can be described by their surrounding relationships with edges; that is, pixels surrounded by the same edge can form an initial homogeneous region. However, executing this idea in practice is difficult, as existing edge extraction algorithms, such as the Canny algorithm [35] with a bilateral filter used in this paper, fail to achieve complete closure (especially for weak boundary regions), which may lead to misjudgment of the relationship between pixels at edge breaks.  
To quickly describe the relationship between pixel pairs and edges, the binary edge map \(E\) is scanned by rays. A set of parallel rays is drawn across \(E\) at an angle \(\theta_{i}\) from an image reference axis, each ray will be cut into several segments by the edges. Pixels that are covered by the same ray interval should be grouped into the same region, as these pixels strictly satisfy the condition of not being split by edges. The corresponding intervals of all rays can jointly form the initial homogeneous region.  
Based on the above analysis, we propose a contour encoding method to quickly generate initial homogenous regions. Both vertical and horizontal rays are used to scan the entire image, and we illustrate this in detail in the vertical direction. An example to clearly illustrate this process is shown in Figure 3, where black and white pixels belong to the edge and background, respectively. First, the initial value of each scan line \(r(p_{0})\) is encoded as 0, and each column of the binary edge map \(E\) is scanned from top to bottom. Then, when the scan line \(r(p_{i})\) reaches an edge pixel, the encoded value of the scan line is increased as follows:  
\[r(p_{i})=\left\{\begin{array}{ll}r(p_{i-1})+1&\text{if}p_{i}=-1\text{and}p_{ i-1}\
eq-1\\ r(p_{i-1})&\text{Otherwise}\end{array}\right., \tag{1}\]  
where \(p_{i}=-1\) and \(p_{i-1}\
eq-1\) mean that the current pixel \(p_{i}\) and the previous pixel \(p_{i-1}\) are an edge pixel and a background pixel, respectively. The encoded value changes only when a scan line faces an edge pixel, and then the encoded value is assigned to corresponding non-edge pixel that is scanned by the ray. Finally, after scanning the whole image, a connected domain with the same encoded value is considered to belong to the same homogeneous region, as shown in Figure 3b. After contour encoding, it is guaranteed that each connected domain is surrounded by the same edge.  
Figure 2: An example of edge-based relationships between pixels. Pixels surrounded by the same edge, such as \(p_{i}\) and \(p_{j}\), are likely to be similar. Correspondingly, pixels separated by edges, such as \(p_{j}\) and \(p_{s}\), are likely to belong to different homogeneous regions.