Fabric Defect Detection Based on Illumination Correction and Visual Salient Features

Aiming at the influence of uneven illumination on fabric feature extraction and the limitations of traditional frequency-based visual saliency algorithms, we propose a fabric defect detection method based on the combination of illumination correction and visual salient features—(1) Construct a multi-scale side window box (MS-BOX) filter to extract the illumination component of the image, then use the constructed two-dimensional gamma correction function to perform illumination correction on the image in the global angle, and finally enhance the local contrast of the image in the local angle; (2) Use the L0 gradient minimization method to remove the background texture of fabric images and highlight the defects; (3) Represent the fabric image as a quaternion image, where each pixel in the image is represented by a quaternion consisting of color, intensity and edge characteristics. The two-dimensional fractional Fourier transform (2D-FRFT) is used to obtain the saliency map of the quaternion image. Experiments show that our method has a higher overall recall rate for defect detection of star-patterned, box-patterned, and dot-patterned fabrics, and the overall recall-precision effect is better than other existing methods.


Introduction
In the process of fabric production, defect detection is very important to the quality control of fabrics. Nowadays, the defect detection of fabrics is mainly aimed at two kinds of fabrics-(1) those with no complex texture pattern, simple structure, mostly solid-color fabrics and (2) those with complex patterns, including pariodic fabrics.
For the first kind of fabric, the research methods have been mature. The main subtypes are-(1) statistical methods, such as the co-occurrence matrix method [1] and the morphological method [2]; (2) spectral methods, such as Fourier transform [3], wavelet transformation [4], Gabor filtering [5]; (3) model methods, such as Markov random field model [6]; (4) deep learning methods, which have been widely used in computer vision [7,8], many researchers have also begun to use deep networks to detect fabric defects, such as neural networks [9], Mobile-Unet [10]; statistical and spectral methods when the area is too large or defects are too small, caused by error. The model method needs to define the model in advance, and different models need to be defined for different types of defects, which is not universal. The deep learning method needs a large number of samples as the training set, and training parameters take a long time. When the defect is close to the texture backgroud, Mobile-Unet [10] cannot detect the details of the defect well. For the second kind of fabric, there are few mature and available methods, mainly including Wavelet Preprocessed Golden Image Subtraction (WGIS) [11], Bollinger Bands (BB) [12], Regular Bands (RB) [13], Elo Ranking (ER) [14], 1.
Different from traditional methods that only perform illumination correction locally or globally, our method performs illumination correction on the fabric image in both global and local angles.

2.
Different from the traditional method of constructing quaternion images, we choose a color space that is more suitable for fabric images, improve the robustness of the intensity feature channel, and replace the motion feature channel with edge feature channel.

3.
Different from the traditional frequency domain method using simple Fourier transform to obtain the saliency map, we use the two-dimensional fractional Fourier transform to obtain the saliency map of the quaternion image.
The remainder of this paper is organized as follows-in Section 2, the work related to illumination correction and visual salient feature are briefly described. In Section 3, we propose a fabric defect detection method based on the combination of illumination correction and visual salient features and discuss the implementation details. In Section 4, we evaluate the performance of our method on a standard data and compare it with existing representative methods WGIS, Mobile-Unet, SHF, ER, CDPA, and SR. Finally, Section 5 concludes the paper.

Illumination Correction
According to Retinex theory [23], an image q(x, y) can be divided into two different images: the reflected object image r(x, y) and the illumination image i(x, y) q(x, y) = r(x, y) · i(x, y).
The multi-scale rolling guidance filter (RGF) [24] is widely used to extract the illumination component of an image. Ying et al. introduced a Exposure Fusion Framework (EFF) [25] and a Bio-Inspired Multi-Exposure Fusion Framework (BIMEFF) [26] for low-light image enhancement, where the enhanced result is obtained by fusing the input image and the synthetic image according to the weight matrix. Ren et al. [27] proposed a Joint low-light Enhancement and Denoising (JED) strategy, where enforced the spatial smoothness on each component and skilfully made use of weight matrices to suppress the noise and improve the contrast. In order to solve the problem of low visibility, Guo et al. [28] proposed a simple yet effective low-light image enhancement (LIME) method. Lore et al. [29] proposed a deep autoencoder approach to low-light image enhancement (LLNet). But the illumination correction effect of these methods for fabric images needs to be improved.

Visual Salient Feature
Visual saliency is a fundamental problem in image processing, pattern recognition, and computer vision. In recent years, many scholars have used visual salient features to detect fabric defects.
Li et al. [30] introduced a Saliency Histogram Features (SHF) method, in which they extrcted and selectd saliency histogram features to discriminate between the defective and defect-free fabric images. Zhang et al. [31] proposed a Color Dissimilarity and Positional Aggregation (CDPA) method, in which they measured the defect value based on the color difference and the position distance between similar color blocks. This kind of method has achieved certain effect, but its real-time performance is not good. The general residual analysis using Fourier transform is relatively simple and fast. On this basis, Guo et al. [32] used the phase spectrum instead of the original amplitude spectrum.

Methods
The steps of our method include illumination correction, texture background removal, saliency map generation and segmentation. Figure 1 is the framework of the proposed our method.

Illumination Correction in the Global Angle
The traditional method of extracting image illumination component by multi-scale rolling guidance filter [24] has some defects, for example, damaged image edge and illumination components appear halo phenomenon. The side window filter (SWF) [33] can preserve the edge of the image very well, so we use multi-scale side window box filter to extract the illumination components of fabric images. Considering that HSV color space is more consistent with the visual characteristics of human eyes, and the hue (H), saturation (S), and value (V) in HSV color space are independent of each other, the operation of V will not affect the color information of the image. So we choose to convert the image from RGB color space to HSV color space.
The definition of a side window is shown in Figure 2a. θ is the angle between horizontal line and the window, r represents the radius of the window, ρ ∈ {0, r}, and (x, y) is the position of the pixel i. By fixing (x, y) and changing θ, we are able to adjust the direction of the window and align its side with i. In order to simplify the process, we adopt the proposal of the paper [33], and define eight side windows only in the discrete cases, as shown in Figure 2b-d. These eight windows defined here correspond to θ = k × π 2 , k ∈ [0, 3]. By setting ρ = r, we can get the down(D), right(R), up(U) and le f t(L) side windows, named as ω D i , ω R i , ω U i and ω L i . They are aligned i with their sides. By setting ρ = 0, we can get the southwest(SW), southeast(SE), northeast(NE) and northwest(NW) side windows, named as and ω NW i . They are aligned i with their corners. By applying the filtering kernel F to each side window, we can get eight different outputs, where q i and I i are the intensities of the input image q and the output image I at location i, respectively. In order to preserve the edges, we want to minimize the distance between the input and the output at the edge. Consequently, we select the side window output with the minimum L 2 distance to the input intensity as the final output, where I SWF is the output of SWF.
In order to enhance the robustness of the original SWF, we build a multi-scale SWF by changing the window radius r, and introduce the box filter (BOX) into the multi-scale SWF. That is to say, F in Equation (2) is averaging and the resulting filter is called multi-scale side window box filter (MS-BOX), where I MS−BOX is the outout of MS-BOX. n is the number of scales. In this paper, n = 3. By convoluting the value component V(x, y) of the image with MS − BOX(x, y), the estimated value of the illumination component I(x, y) can be obtained. The results are as follows: After extracting the illumination component of the image, the gamma correction function can be constructed according to the distribution characteristics of the illumination component. The expression of the two-dimensional gamma correction function constructed in this paper is as follows: where O(x, y) is the brightness value of the output image after correction, λ is the index value used for brightness enhancement, which contains the characteristics of the illumination component of the image, m is the mean value of the estimated value of the illumination component I(x, y).

Enhance the Contrast in the Local Angle
Local Contrast Enhancement (LCE) algorithm [34] can effectively improve the visualization of detail features and keep the original details of the image as much as possible. The transformation equation of LCE algorithm is as follows: L(m, n) = 1 where Θ is a predefined threshold and L(m, n) is the gray value at the pixel (m, n). L(m, n) represents the local gray value of the pixel (m, n) in the domain. Y(m, n) represents the adjustment gray value of the pixel (m, n). In this experiment, we use the domain of 5 × 5, where N is the total number of pixels in the selected domain. Since the local value of Equation (7) can be positive or negative, it is necessary to normalize it: We combine the above two methods to achieve illumination correction of fabric images in both global and local angles.

Background Texture Smooth by the L 0 Gradient Minimization(LGM)
Because of the diversity of pattern and texture, it usually brings great difficulties to fabric defect detection. In recent years, due to the fast and effective of the LGM algorithm [35], LGM has been used by many scholars to remove texture. The LGM can not only smooth the background texture, but also retain the key information of the image. In brief, the LGM preserves the important edge parts of the image by adding the steepness of the transition part of the image while removing low-amplitude parts. Let I be the input image, the result of the LGM is S. The partial derivatives of the smoothed image at p in the x and y directions are defined as ∂ x S p and ∂ y S p respectively. Therefore, the gradient of smoothed output S at pixel p can be expressed as: So the image L 0 gradient specific objective function can be expressed as: where λ is non-negative parameter, which affects the degree of image smoothing. h is auxiliary variable and β is an adaptive parameter. By alternatively computing h and S, we can get the smoothed output result. As shown in Figure 3a, the input image has a complex texture structure, and its mesh diagram is shown in Figure 4a. After the LGM algorithm, the complex texture information of input image is smoothed, and the output result is shown in Figure 3b. It is noted that the important edges of the defect are preserved, and the defect is more visible, and the mesh diagram is shown in Figure 4b.

Creation of a Quaternion Image
Saliency detection method based on quaternion [32] represents each pixel with a quaternion consisting of color, intensity, and motion features. Compared with RGB color space, CIE Luv color space is more suitable for fabric defect detection with single color. L represents brightness, and u and v represent chroma. Therefore, we change the input image I from RGB color space to CIE Luv color space. Let l, u and v represent different channels of image I in CIE Luv color space. Equations (12)- (15) create four broadly-tuned color channels: In human brain, there exists a 'color opponent-component' system [36]. In the center of receptive fields, neurons are excited by one color or chroma. The opposite chroma channels are obtained by Equations (16) and (17).
In order to further reduce the non-saliency of the color and strengthen its biological rationality, we adjusted the intensity channel F, F = (l +ū +v)/3, and v m are the mean value of l, u, and v respectively. Since we are dealing with static images without motion features, we use Canny operator to extract edge features E instead of motion features, According to the above four feature channels, the quaternion image q is defined as follows: where µ i , i = 1, 2 satisfies µ 2 i = −1, µ 1 ⊥µ 2 .

Using 2-D Fractional Fourier Transform to Obtain Saliency Map
The fractional Fourier transform (FRFT) is a generalized form of the traditional Fourier transform. The result of the transform contains the information of signal time and frequency domains. For an input signal x(t), the FRFT is as follows: where α is the rotation angle when the signal rotates to the frequency axis, α = p · π/2, and p is the transformation order of fractional Fourier transform. It can be seen from Equations (22) and (23) that when p = 1, the rotation angle is π/2, and the fractional Fourier transform degenerates into the traditional Fourier transform; when p = 4n, the rotation angle is an integral multiple of 0 or 2, and the result of the fractional Fourier transform is the signal itself; when p is a fraction, the rotation angle is between 0 and π/2, and the signal is rotated between the time axis and the frequency axis, In this case, the results of FRFT can describe the signal characteristics from both the time and the frequency domain. Figure 5 shows the transform domain of fractional Fourier transform, where axis t represents the time axis and axis ε represents the frequency axis. For a two-dimensional signal x(s, t), its two-dimensional fractional Fourier transform (2D-FRFT) is defined as: where α and β represent two independent fractional rotation angles in two-dimensional space, and the two-dimensional transformation result of signal x(s, t) is equal to two successive fractional Fourier transforms of the signal with parameters α and β respectively. In this work, we set both α and β to 0.9. The transform kernel of two-dimensional fractional Fourier transform can be defined as follows: where α and β are discrete forms of kernel functions of fractional Fourier transform. For a discrete two-dimensional signal f (m, n), the discrete two-dimensional fractional Fourier transform at point (m, n) is as follows: The inverse discrete two-dimensional fractional Fourier transform at point (m, n) is as follows:

Generation of Saliency Map
The 2D-FRFT of Equation (19) can be written as: where X i (u, v), i = 1, 2 is the two-dimensional fractional Fourier transform of f i . Q(u, v) can be represented in polar form as: where • is the amplitude spectrum, φ is the phase spectrum and µ is a unit pure quaternion. Calculate the inverse two-dimensional fractional Fourier transform of Q(u, v) using Equation (27), the result is written asQ(u, v).
The final saliency map is obtained by Equation (30), where g is a 2D gaussian filter (σ = 2.5) We use the region growing method to segment the saliency map and separate the defect from the background. Finally, the morphological treatment of the saliency map is carried out to remove the noise points that are easily caused by misdetection.

Computation Cost Analysis
The computational cost of our method is mainly affected by the following work: illumination correction, use LGM to remove texture background, construct a quaternion image and saliency map generation.
Let N = M × N, M and N are the width and height of the input image respectively, the illumination correction process is a linear calculation process, so its computational complexity is O(N ); the computational complexity of LGM is mainly determined by Equation (11), so its computational complexity is O(N log N ); the process of constructing a quaternion image is also a linear calculation process, so its computational complexity is O(N ); the computational complexity of saliency map generation is mainly determined by Equation (28), so its computational complexity is O (N log N ). Therefore, the computation complexity of our method is as follows: Besides, the space complexity of our method is O(C × N ), where C is a constant.

Experiments and Performance Evaluation
In this section, our work is performed by using in total of 50 images provided by the automation laboratory fabric database of Hong Kong University. More specifically, 15 defect images of size 256 × 256 are from the box-patterned fabric database, 15 defect images from the star-patterned fabric database and 20 defect images from the dot-patterned fabric database. In addition, all defect images have corresponding binary ground truth images, with a value of 1 for defective objects and 0 for defect-free objects. WGIS [11] (2005), Mobile-Unet [10] (2020), SHF [30] (2019), ER [14] (2016), CDPA [31] (2018) and SR [15] (2017) are implemented for comparison. The experiments are performed on a personal computer with an Intel Core i5-8300H processor and 8 GB memory. The testing codes are implemented in Matlab 2019a.

Analysis of Experimental Results of Different Illumination Correction Methods
Different illumination correction methods have different correction effects on fabric images, and comparison experiments of different methods are carried out for this problem. The scale factors r of the multi-scale MS-BOX are 3, 5, and 7, respectively. Figure 6 shows the illumination component extraction effect comparison of multi-scale RGF [24] (2014) and multi-scale MS-BOX. Figure 7 shows the illumination correction effect comparison of BIMEFF [26] (2017), JED [27] (2018), LIME [28] (2017), EFF [25] (2017), LLNet [29] (2017) and Ours.
As the Figure 6 shows, compared with the multi-scale RGF, the multi-scale MS-BOX can eliminate the halo phenomenon in the illumination component image to a certain extent. This is because in the multi-scale MS-BOX, the edge information of the image is preserved in the filtering process. The illumination component extracted by the multi-scale MS-BOX can effectively describe the illumination change information, which meets the feature requirements of the illumination component extraction.

Star-pattern
Box-pattern Dot-pattern As the Figure 7 shows, our method is better than other methods in illumination correction of fabric images, and can effectively improve the visualization of detail features. BIMEFF, JED, EFF and LLNet can basically eliminate the influence of illumination, but there are still some regions where the brightness is too dark to extract the details effectively. The LIME makes the image over enhanced, which is not conducive to the extraction of detailed features, and reduces the contrast between the defect and the background.

Parameter Selection of the L 0 Gradient Minimization Method
We use the L 0 gradient minimization method to remove the background of dot-patterned fabric images. In the L 0 gradient minimization method, parameter λ affect the effect of defect detection. We explore the most appropriate parameter λ, and the results are shown in Figure 8.
As the Figure 8 shows, for dot-patterned fabric images, if the parameter λ is set too small, the background texture is hardly removed. Conversely, if the parameter λ is set too large, the defects are removed out.
In order to compare the impact of parameter λ on all kinds of dot-patterned fabric types, the parameter λ is 0.005, 0.01, 0.015, 0.02, 0.03, 0.04, and 0.05 respectively. Figure 9 shows the detection accuracy of four fabric types. It is proved by experiments that the selected number of λ is set between 0.005 and 0.05, which can meet the needs of four fabric types. As the Figure 9a shows, when λ = 0.05, the broken end fabric will be mistakenly smoothed out. As the Figure 9d shows, when λ is set to 0.04 or 0.05, the thin bar fabric will be mistakenly smoothed out, and the accuracy rate cannot be calculated. When λ = 0.02, the detection accuracy rate of the four types of defects is the best, so we set the parameter λ = 0.02.

Generation of the Saliency Map
The saliency map of star-patterned fabric defect detection is shown in Figure 10. The saliency map of box-patterned fabric defect detection is shown in Figure 11. The saliency map of dot-patterned fabric defect detection is shown in Figure 12. As the Figures 10-12 show, we can see that our method can effectively highlight the defect regions with saliency features, and it has strong adaptability and robustness to different types of defects.

Result Comparison
For each defect type of the fabric image database, an exemplar is randomly selected. The results of WGIS [11], Mobile-Unet [10], SHF [30], ER [14], CDPA [31], SR [15], and Ours are shown in Figures 13-15. For star-patterned exemplars shown in Figure 13, the detection accuracy of Ours on star-patterned fabrics are better than the rest in vision, the location and shape of defects are closest to the ground truth. WGIS and ER are basically unable to detect. For box-patterned exemplars shown in Figure 14, Mobile-Unet, SHF, CDPA, SR, and Ours can detect defects, but Ours is more closest to ground truth in the shape of defects. WGIS and ER cause a lot of false detection of defect-free points. For dot-patterned exemplars shown in Figure 14, all methods can detect defects, but the detection effect of Ours is more prominent.

Quantitative Comparison
In order to test the effectiveness of the method, we also made quantitative and qualitative comparisons. A number of metrics are used to evaluate the effectiveness of the method. That is,  FN). Additionally, we also used the f value to evaluate the performance correctly.
where γ = 1 in [37]. That is to say, Equation (32) can be rewritten as The above Equations show that when the FN and FP increase, the value of f decreases, when FN and FP decrease, the value of f increases gradually and tends to 1. The f value only depands on TPR and PPV, which avoids the problem of incorrect evaluation and false inspection caused by the small defect regions. Consequently, we choose the f value as an important index to evaluate the performance correct of the method. Tables 1-3 compare the quantitative results of the different algorithms (WGIS [11], Mobile-Unet [10], SHF [30], ER [14], CDPA [31], SR [15], and Ours) on star-, box-and dot-patterned fabrics. Besides, we marked the best results with black bold. The first to sixth columns are defect type name, TPR, FPR, PPV, NPV, and f value respectively. It should be noted that each row of the table is the average test result of a method, and the test results of all rows are classified according to the types of fabric defects. For numeric star-patterned results in Table 1, our method get the highest overall TPR and PPV, while the overall f value is the highest, indicating that our method has achieved better overall recall and precision, and the detection accuracy rate is the best. For numeric box-patterned results in Table 2, our method get the highest overall TPR, NPV, and f value, indicating that the our method has the highest detection accuracy. Although Mobile-Unet achieves the lowest overall FPR and highest overall PPV, the overall TPR is only 60.75% and the f value is not the best, which is not conducive to actual detect. For numeric dot-patterned results in Table 3, our method get the highest overall TPR, NPV, and f value, indicating that the detection effect of our method is similar to box-patterned fabric. Although Mobile-Unet achieves the highest overall PPV, the overall TPR is only 64.88%. In summary, our method significantly improves the TPR and f value of star-, box-and dot-patterned fabric defect detection. Figure 16 shows the TPR-PPV scatter plots of star-, box-and dot-patterned fabrics by seven methods, in which the same type of scatter plots represent different types of defects at different locations. In the scatter diagram, the closer the value of TPR and PPV is to 1 (100%), which indicates that the better the comprehensive detection effect of the method. The more centralized the scatter value distribution, the more robust and universal the performance of the method. As Figure 16 shows, in the scatter diagrams, our method is closest to the upper right corner of the diagrams, that is to say, the comprehensive TPR-PPV effect of our method is better. Besides, the scatter value of our method is the most aggregated, which shows that our method is more robust and adaptable to the detection of different patterns of fabrics.
As the Table 4 shows, compared with other methods based on image processing (WGIS, ER, SR, SHF and CDPA), our running time is significantly shorter. Mobile-Unet has the best real-time performance. However, Mobile-Unet needs to prepare a large number of defect images as training data in advance, and the training process also needs a lot of time.

Conclusions
This paper proposes a method of fabric defect detection based on illumination correction and visual salient features. In view of the limitations of traditional illumination correction methods, we propose a new method of illumination correction, which adjusts the brightness according to the illumination component in the global angle and enhances the contrast in the local angle. In order to eliminate the interference of background to the detection, the L 0 gradient minimization method is used to remove the texture background and highlight the defects. The traditional frequency domain based visual saliency detection algorithm only considers the saliency of the defects in the frequency domain. In this paper, the image is represented by quaternion image, and the two-dimensional fractional Fourier transform is used to enhance the saliency of the defects in the frequency domain and time domain. Finally, we use the region growing method and morphological processing to segment the saliency map and complete the defect detection. Experimental results on a standard database show that our method has better robustness and better detection effect than other methods. But it should be noted that our method has a high FPR for dot-patterned fabric defects, which needs to be improved in the future.