# Infrared Image Superpixel Segmentation Based on Seed Strategy of Contour Encoding
## 3 Methodology
### Seed Sampling Strategy  
Gradient-based superpixel generation algorithms usually begin with initial points to gradually form initial closed regions; for example, the watershed algorithm injects water from a local minimum point, while the superpixel growth of Turbopixels, SLIC, and SNIC start with a set of uniformly distributed seed points sampled from a regular grid. However, regular grid seed sampling is only related to the number of superpixels expected by the user, and ignores image structure information. Generally, the grid scattering strategy of seed points does not work well for different images or different regions of the same image, as it is independent of the variation in the input image content. Regions containing two small objects are difficult to be labelled separately by superpixels with large, expected sizes, while superpixels with small expected sizes may lead to severe over-segmentation. In order to efficiently adapt the seed distribution to the image structure, we designed a novel seed scattering strategy using the initial homogeneous region formed by contour encoding. With the contour encoding method described in Section 3.1, we can obtain the initial homogeneous region, which is scanned from top to bottom, as shown in Figure 4. A region surrounded by the same contour should be considered as a rational independent region, and arranging a seed point inside it is more conducive to generate superpixels with better boundary adherence, especially for small regions. In Figure 4, each initial homogenous region completely satisfies the property that each pixel within it is surrounded by the same contour. Since the encoded value of each ray starts from 0, the region labeled by 0 at the beginning is usually large, such as the pink region in Figure 4. Internal consistency is more difficult to ensure in large regions, as it is difficult to identify edges in weak boundary regions. Therefore, a set of rays in the reverse direction is applied to rescan the image and sub-divide the large region, as shown in Figure 4. Then, two scan maps in opposite directions, \(\vartheta_{i}\) and \(\pi+\vartheta_{i}\), are combined to form the joint initial vertical regions, as shown in Figure 4. In the process of merging, the small region is dominant when two directional regions are overlapping. Figure 3: An example of the scan process in the vertical direction. (**a**) Binary edge map; and (**b**) the encoded result of (**a**). The black region is the edges, and each color represents a homogeneous region. However, each column is scanned by one ray, which may cause the ideal homogeneous region to be over-segmented after merging, such as the pink regions in Figure 4a,b which are over-segmented, as shown in corresponding position in Figure 4c. Therefore, further merging is needed for similar initial regions that are surrounded by the same contour, in order to reduce the number of seed points and, thus, reduce the over-segmentation phenomenon. At the same time, a merging strategy can also reduce the impact of edge detection anomalies occurring in the grayscale gradual region. Since the generation of the edge binary map depends on the degree of image gradient change, contour information cannot be effectively extracted in the progressive region. In the merging process of the contour encoding map, similarity metrics \(M\) are computed for adjacent regions which are not crossed by edges, represented as:  
\[M_{v_{i}v_{j}}=\left(\overline{v_{i}}-\overline{v_{j}}\right)^{2}, \tag{2}\]  
where \(\overline{v_{i}}\) is the grayscale average of the initial region \(v_{i}\). When \(M_{v_{i}v_{j}}\) is less than the threshold value \(M_{T}\), \(v_{j}\) merges into \(v_{i}\), and \(\overline{v_{i}}\) is updated. For a scan map in direction \(\theta_{i}\), only merging regions in orthogonal direction is required. Additionally, when the region faces more than one adjacent region on a side, only the most similar adjacent region is selected for merging into the region.