# Detection of Defects in Warp Knitted Fabrics Based on Local Feature Scale Adaptive Comparison
## 2 Scale Adaptive Contrast Method  
### Adaptive Window  
In order to determine whether an image pixel is a normal pixel (background area pixel) or a defective pixel, it is necessary to determine an area centered on this pixel. All pixels in this area are locally similar to the central pixel. In the existing small target detection methods, for each pixel in an image, the corresponding similar region is a rectangular region of fixed size, such as 3 \(\times\) 3, 5 \(\times\) 5, 5 \(\times\) 7, etc. During detection, a rectangular region of fixed size adapted to these small targets (defects) is artificially determined in advance according to the specific conditions of small targets (defects) of different sizes. In an image, there are relatively flat areas, such as the background, and some edge detail areas, such as patterns or defects. That is to say, for the pixels of different regions in the image, the size of similar regions centered on the pixel cannot be the same. If it is a background area pixel, there will be more pixels around the pixel that are similar to the pixel, then the corresponding similar area should be large. If it is an edge detail or defect pixel, the number of similar pixels around the pixel should be relatively small, and the correspondingly similar area should be small. Therefore, it is unreasonable to specify a similar area of the same size for all pixels in an image. Therefore, in this method, based on the idea of scale, an adaptive method to determine the size of this similar region is proposed, that is, for each pixel in the image, the corresponding size is calculated according to the region in the image and the similarity between its surrounding pixels, and the region where the scale is located is taken as the similar region of this pixel. Suppose a digital image can be defined as \(\mathbf{C}=(c,f)\), \(c\) is the rectangular arrangement of pixels, which is called the field on \(C\), \(f\) is the image gray intensity function, and its definition field is [L, H], and L and H are the minimum and maximum values of the pixel gray value, respectively. When the image gray value is represented by 8-bit binary, L is 0 and H is 255. For any element \(c\in C\), the plane \(D_{r}(c)\) with \(c\) as the center and \(r\) as the radius can be expressed as:  
\[D_{r}(c)=\{d\in C|\|c-d\|\leq r\}, \tag{1}\]  
The plane \(D_{r}(c)\) with \(c\) as the center and \(r\) as the radius in the plane can be represented as Figure 1a,b. When \(r=1\), the pixels of the disc are \(\{c,di\}\), where \(i=1\), 2, 3, 4, as shown in Figure 1a. When \(r=2\), the pixels of the disc have \(\{c,di\}\), where \(i=1\), 2, 12, as shown in Figure 1b. To calculate the scale corresponding to each pixel in the image, let \(FO_{r}(c)\) be:  
\[FO_{r}(c)=\frac{\sum_{d\in D_{r}(c)-D_{r-1}(c)}W_{h}(f(c)-f(d))}{|D_{r}(c)-D_{ r-1}(c)|}, \tag{2}\]  
Figure 1: Pixels within the radius of plane \(D_{r}(c)\) scale. (**a**) r = 1, (**b**) r = 2.  
where \(|D_{r}(c)-D_{r-1}(c)|\) represents the number of all pixels in region \(D_{r}(c)-D_{r-1}(c)\), \(f(c)\) and \(f(d)\) represent the gray value of pixels \(c\) and \(d\), respectively, and the \(W_{h}\) function should meet the requirements: (I) the value range is [0, 1]; (II) \(W_{h}(0)=1\); (III) the function is a monotone non-increasing function. In fuzzy space, many functions can meet these requirements. Here, we can take a typical function \(W_{h}(x)=e^{-\frac{x^{2}}{2\tau}}\). This function can satisfy that when pixel \(c\) and pixel \(d\) have similar gray values, that is, when the gray difference tends to 0, the function value tends to 1; when the gray value difference between pixel \(c\) and pixel \(d\) is large, that is, when the gray value difference tends to 255, the function value tends to 0. According to the \(FO_{r}(c)\) calculation, the sphere scale corresponding to each pixel in the image can be obtained. For any pixel \(c\), take \(c\) as the center of the circle, and gradually increase the circle radius from \(r=1\).