Fabric defect fetection via weighted low-rank decomposition and Laplacian regularization

Low-rank decomposition models have potential for fabric defect detection, where a feature matrix is decomposed into a low-rank matrix that corresponding to repeated texture structure and a sparse matrix that represent defective regions. Two limitations, however, still exist. First, previous work might fail to detect some large homogeneous defective block. Second, when the background and defective regions are relatively coherent or the texture of fabric image is complex, it is difficult to use previous methods to separate them. To deal with these problems, a new weighted low-rank decomposition model with Laplace regularization (WLRL) is proposed in this paper: (1) a weighted low-rank decomposition model that can decompose the original image into background and defective regions, and (2) a Laplace regularization that can enlarge the distance between the background and the defective regions. The performance of the proposed method WLRL is evaluated on the box- and star-patterned fabric databases, and superior results are shown compared with state-of-the-art methods, that is, 98.70% ACC (accuracy) and 72.83% TPR (true positive rate) for box-patterned fabrics, 99.09% ACC (accuracy) and 83.63% TPR (true positive rate) for star-patterned fabrics.


Introduction
In the fabric industry, fabric production is usually done on weaving and knitting machines. 1 Therefore, this process always produces various defects, such as oil stain and knotting. Fabric defects are one of the main factors affecting the quality of fabrics. Considering that the loss of fabric profits caused by defects can reach 45%: 65%, 2 defect detection is a necessary step in fabric production. At present, defect detection mainly depends on experienced skilled workers, but this method is too subjective and inefficient. Automated visual inspection of fabrics can make up for these shortcomings. 3 Hence, the research on automatic fabric defect detection has far-reaching significance.
Generally, fabric defect detection can be classified into two main categories: automatic defect detection of unpatterned fabrics (e.g. plain and twill fabrics), and automatic Fabric defect fetection via weighted low-rank decomposition and Laplacian regularization defect detection of patterned fabrics (e.g. lattice fabric). There is a line of researches on un-patterned fabrics defect detection, mainly contain Fourier transforms, 4,5 Gabor filter, 6,7 Markov random field, 8,9 wavelet transform, 10,11 support vector machine, 12 and neural network. 13,14 Patterned fabrics refer to the images of texture units with periodic variations. In 2017, Ng et al. 15 defined the most basic unit of fabric texture as motif, and the combination of motifs can form a lattice which appears repetitively in patterned fabrics, as shown in Figure 1. Different types of fabrics (e.g. box-and star-patterned) have different sizes and shapes of the lattices. At present, there are many corresponding detection algorithms. For example, in 2005, Ngan et al. 16 proposed the wavelet preprocessed golden image subtraction (WGIS), but WGIS can only detect large defect blocks, which is invalid for small defects. Tang et al. 17 proposed the Elo Rating (ER) algorithm in 2016, which is a defect detection method based on the spirit of sportsmanship that is, fair matches between different image blocks. In 2017, Jia et al. 18 proposed a fabric defect detection method based on Gabor filter, which uses morphological component analysis (MCA) to segment the lattice automatically, and then transform the defect detection problem into lattice similarity problem. This method has achieved superior results, but for different types of defects, the adaptability needs to be further improved. In 2017, Yapi et al. 19 proposed a learning-based fabric detection method, and the experiment on the standard database showed that the method achieved good detection results. Wang et al. 20 proposed a method of fabric defect detection based on deep feature and low-rank recovery in 2018. The experiment shows that this method has a good detection effect. In 2018, Yi et al. 21 proposed a fabric defect detection model based on distance matching function and optimal Gabor filter bank. Experimental results show that the method has short learning time, good robustness, and can quickly and accurately detect fabric defects. In 2020, liu et al. 22 proposed a fabric defect detection method based on deep-feature and low-rank decomposition model. The experimental results show that the low-rank decomposition model can effectively separate defects from the background, and the method has a high detection accuracy.
The low-rank decomposition (LR) model can decompose the original image into low-rank components that represent the background of the image and sparse components that corresponding the defective regions. Gao et al. 23 combine GHOG (Gabor-HOG) with low-rank recovery to detect fabric defects. First, extract the GHOG feature of the image, and then use the low-rank recovery model to detect the defects. PN-RPCA 24 proposed a defect prior to guide the low-rank decomposition model and adds noise terms to reduce the influence of noise. Generally, these LR-based (low-rank decomposition model) defect detection methods assume that a fabric image can be represented as a combination of high visual redundancy part (e.g. background regions) and a sparse part (e.g. defective regions).
Although the previous defect detection methods have achieved promising results, there still exist several problems: (1) previous studies might fail to detect some large homogeneous defective block; and (2) when the background and defective regions are relatively coherent or the texture of fabric image is complex, the previous methods are difficult to separate them. In order to overcome these problems, a new weighted LR model with Laplacian regularization (WLRL) is proposed in this paper which is inspired by the LSG 18 and SMD. 25 We have enhanced the traditional low-rank decomposition model 26 with two important components.
First, we get more accurate defect prior by lattice segmentation, and construct weighted low-rank decomposition model by defect prior. Second, in order to enhance the detection efficiency, we add Laplacian regularization 25 to the weighted LR model, which is used to enlarge the distance between the background and the defective regions. The regularizer encourages blocks with similar pixels to share similar representations and eventually separates salient regions from the background as much as possible. These attributes enable the proposed WLRL method to exhibit excellent performance in defect detection. In summary, this paper makes the following contributions: 1. By combining the properties of the two techniques, a weighted low-rank decomposition with Laplacian regularization (WLRL) is proposed for latticebased fabric defect detection. 2. In constructing the weighed low-rank decomposition model the defect prior is introduced to obtain more accurate defects. 3. In the weighted low-rank decomposition model, a Laplacian regularization term is added to enlarge the distance between the background and the defective regions, which makes the proposed method more accurate and robust.

Lattice segmentation
Lattice segmentation can be classified into two categories based on computational methods 27 : the local feature-based and the global structure-based methods. The former analyzes local features first and then global structure, while the latter is the opposite. Liu et al. 28 perform lattice segmentation based on local features, which has a better detection result for simple textures, but it is difficult to detect complex textures. Chang et al. 29 used the global variance minimization to perform lattice segmentation. First, an ideal lattice size is assumed, and then the sum of the variances of these lattices is calculated. When the sum is approaching the smallest, the optimal lattice size is obtained. Jia et al. 18 propose a new method, which can perform lattice segmentation without obtaining the corresponding lattice prior knowledge. This paper uses this method for lattice segmentation.

Low-rank decomposition
Candès et al. 26 first proposed the low-rank decomposition model (LR). According to different applications, the lowrank decomposition model can be called robust principal component analysis (RPCA) or robust subspace learning. 30 Bouwmans et al. 31 and Lin et al. 32 analyzed in detail the evolution process of LR model and the optimized solution method. Given a feature matrix F of the input image, the LR model can decompose it into a low-rank matrix B (representing the background part of the image) and a sparse matrix S (representing the significant foreground area of the image). Therefore, fabric defect detection can be described as the following questions: where the nuclear norm ⋅ * (sum of all singular values in the matrix) is the convex relaxation of the matrix rank function; ⋅ 1 represents the l 1 norm of the matrix, which is the maximal value in the sum of the matrix column vectors absolute values; λ > 0 represents the weighted factor, which is used to balance the degree of low-rank and sparsity. At present, the low-rank decomposition model has been successfully applied in signal processing, computer vision and industrial process. For instance, Pu et al. 33 designs a new structured matrix decomposition method, which decomposes the data matrix of each mode into the superposition of three terms for blind audio-visual location and separation. S. Javed et al. 34 propose a spatiotemporal structured sparse RPCA algorithm for moving objects detection. Li et al. 35 used the low-rank decomposition model to detect the defects of thin-walled structure. The experiment shows that the method has achieved satisfactory results.
The research on different norms and regularization terms in low-rank decomposition is a very active field and their selection is always driven by the application like in background/foreground separation. On the basis of RPCA, Sobral et al. 36 proposed a double-constrained RPCA model called SCM-RPCA, which is used to improve the target foreground detection in the marine scene. The experimental results show that the method has better detection results. Zhou et al. 37 proposed a new graph-regularized Laplace low-rank approximation detecting model (GRLA) for infrared dim target scene. The kernel norm was replaced by non convex Laplacian low-rank regularization, which improved the accuracy of non-uniform background estimation. Shijila et al. 38 used convergence convex optimization algorithm to regularize the total variation (TV) norm in the low-rank decomposition model, which reduced the computational complexity.

The proposed WLRL method
The proposed WLRL method consists of two parts: the acquisition of defect prior and the low-rank decomposition model. First, the defect prior (approximate defective regions) is obtained by lattice segmentation and added into the low-rank decomposition model to construct the weighted low-rank decomposition model. Second, adding Laplacian regularization to enlarge the distance between the backgrounds and defective regions. Last, using the optimal threshold algorithm to segment the saliency map generated by the sparse matrix to locate the defective regions. Figure 2 shows the specific steps.

Acquisition of defect prior
One disadvantage of LR model is that it may fail to detect some large homogeneous defective block. In order to avoid this error and improve the detection effect of LR, the defect prior will be introduced in the paper. Defect prior is a penalty matrix used to guide LR, which can improve the detection probability of defects and reduce the detection probability of defect-free regions. The acquisition of defect prior is generally divided into two stages: training stage and testing stage.
Training stage: First, the defect-free fabrics is segmented by lattice segmentation 18 according to the period size. Then each lattice covers a rectangular area of the original image, and each lattice is a sub-image of the original fabric image. Therefore, some traditional feature extraction 39,40 methods can be used for lattice feature extraction. Here Gabor filter is used for feature extraction. The predefined Gabor filter banks of 2D Gabor transform function are as follows.
x y cos sin sin cos The parameters σ x and σ y represent the shape factor of the Gauss surface; θ denotes directions and g 0 denotes center frequency. The values of these parameters determine the quality of the filter. In addition, these values are predefined 40 and optimized 41 in fabric defect detection. In this paper, the parameters θ are defined as 0, π/4, π/2, and 3π/4.Then the Chebychev distance between different lattices is calculated, and a distance matrix D is constructed. The average distance d is calculated and put into the testing stage as a parameter. Specific details can refer to. 18 Testing stage: In the training phase, the distance between feature blocks are used to represent the similarity between lattices. Repeat the steps mentioned above to get a feature distance matrix. When the distance is greater than d, it is marked as a defective lattice. Otherwise, it is a defect-free lattice. The steps are summarized in Figure 3.

Weighted LR and laplacian regularization
In order to improve the detection accuracy of the LR model for different defect types, based on LR, a weight matrix is added to guide the decomposition process, which makes the model more accurate and robust. Meanwhile, it can avoid failure when the previous studies might fail to detect some large homogeneous defective block. In addition, in order to make the model adapt to different types of defects, we add Laplacian regularization to enlarge the distance between the backgrounds and the defects.

WLR model
Considering that LR may fail to detect some large homogeneous defective block. Therefore, a valid weighting matrix W is constructed and introduced into LR to guide low-rank decomposition. A weighted low-rank decomposition model (WLR) is described as follows: where the weight matrix W = exp(-P ) and P represents the defect prior. A larger P( , ) i j value indicates F ( , ) i j has a high probability to be a defective pixel. The augmented Lagrange function is defined as follows: where Y is the Lagrange multiplier; Tr ( ) ⋅ represents the trace of the matrix; µ > 0 is a constant, which is the penalty for the violation of the linear constraint; and ⋅ F denotes the Frobenius norm of a matrix.

Laplacian regularization
When the difference between the backgrounds and defects is not obvious or the texture of fabric image is complex, the backgrounds will be highly correlated with the defects. Therefore, the previous WLR-based method will be difficult to work facing this situation. To solve this problem, a Laplacian regularization 25 is introduced to enlarge the distance between the backgrounds and the defects, so as to distinguish the defective regions from the background. We define Laplacian regularization as follows: where Θ( , ) B S denotes the interactive regularization term used to increase the distance between subspaces B and S; S i denotes the i -th column of matrix S ; a i j , denotes the ( , ) i j )-th entry of an affinity matrix A a i j N N = ( ) , ∈ ×  , which represents the feature similarity of image patches; and M F N N ∈ ×  denotes a Laplacian matrix. The affinity matrix A is defined as follows: where  represents the set of adjacent block pairs which are either neighbors (first-order) or "neighbors of neighbors" (second-order reachable) on the image. The ( ( , ) i j )-th entry of the Laplacian matrix M F is defined as: Essentially, Laplacian regularization enlarges the distance between feature subspaces by smoothing the vectors in S, which is according to the local neighborhood derived from the feature matrix F . This method encourages blocks with similar pixels to be represented in the same way and blocks with different pixels to be represented in different ways.

WLRL model
Based on the WLR, Laplacian regularization is added to construct the WLRL model. The model is defined as follows: where the first term is a low-rank restriction, which is used to represent the background of fabrics. The second term is a sparse restriction, which is used to indicate the defective regions of fabrics. The third term is Laplacian regularization to enlarge the distance between the lowrank part and the sparse part, and λ, β are positive trade-off parameters represent the degree of sparsity and Laplacian interactive regularization terms, respectively. Θ( ) ⋅ represents the Laplacian interactive regularization term.
In order to facilitate the solution, the auxiliary variable H is introduced to separate the objective function. Equation 9 can be described as follows:

Optimization
Considering the efficiency and accuracy of the algorithm, the ADM 42 is used to solve the convex optimization model WLRL, and the minimum augmented Lagrange function is: where Y 1 and Y 2 are the Lagrange multipliers, µ > 0 is a constant, which is the penalty for the violation of the linear constraint. In order to solve the Eq. 11, the optimal B, S and H are searched in the paper iteratively. The solution process is summarized as Alg. 1 and is termed as ADM-WLRL. Details of the iteration are as follows.
Note that T[ ] ⋅ presents Singular Value Thresholding (SVT) 43 operator and Σ is the singular value of the matrix of X S .
Updating H : fix the others and update by solving the following problem: where The closed solution of S k +1 is: where shrink( ⋅ ) is a soft threshold operator, expressed as: Updating Y 1

WLRL-based fabric defect detection
By explaining the optimization process in the previous section, the WLRL-based defect detection method can be defined now. The framework for patterned fabric defect detection consists of four steps: image representation, defect prior, low-rank decomposition and generating a saliency map and its segmentation.
Step 1: Image representation. First, Gabor filter is used to preprocess the pattern fabric image to generate Gabor maps. Then the image is segmented into N blocks by using the simple liner iterative clustering (SLIC) 44 algorithm, which is expressed as P P P P N = { , , , } 1 2  . If each feature block P i is represented by the feature vector f i , the original image can be represented as a feature matrix , M is the dimension of the features (here M = 53).
Step 2: Defect prior. First, the fabric image is segmented according to the period size by using lattice segmentation. Then, Gabor features of each lattice are extracted, and the Chebyshev distance between each lattice is calculated. By comparing the lattices, the defect prior is obtained, as shown in Figure 3. By adding defect prior, the model has a higher detection rate and robustness.
Step 3: Low-rank decomposition. When W is ready, we use the MATLAB syntax repmat (W,2,M) to perform a dimension transformation to make it consistent with the dimension of F. Then the WLRL model (Eq.(10)) is used to decompose F into a low-rank matrix B and a sparse matrix S. The specific steps are shown in Figure 2.
Step 4: Generating a saliency map and its segmentation. The feature matrix F of fabric image is decomposed into lowrank matrix B corresponding to fabric background and sparse matrix S corresponding to defective regions by the WLRL model. The saliency of each image block is expressed by calculating the l 1 norm of each column S i in S, It can be expressed as Sal( ) = 1 I S i i . The obtained largest Sal( I i ) indicates that this block is most likely to contain defects. Then denoting S to produce a new saliency map S  , S = *( ) g S S , where g denotes the Gauss smoothing filter, "  " denotes Hadamard inner product operator, and " * " denotes the convolution operation.
Then the saliency map S  is transformed into gray image G: Finally, the improved adaptive threshold segmentation algorithm 45 is used to segment G, and the final binary detection results are obtained.

Experiments and performance evaluation
To fully evaluate the proposed method, a series of experiments are conducted by using standard datasets, including four state-of-the-art solutions for comparison. In particular, the dataset is provided by the Industrial Automation Research Laboratory from Dept. of Electrical and Electronic Engineering of Hong Kong University, which includes 106 standard datasets of box-and star-patterned, with a size of 256-by-256 in 24-bit depth. The box-patterned database has 30 defect-free images and 26 defective images. The star-patterned database has 25 defect-free images and 25 defective images. There are five types of defects in all the defective images, including Broken end, Hole, Netting multiple, Thick bar and Thin bar. All defective images have corresponding binary ground-truth images (manually labeled images) which has value 1 and 0 corresponding to the defects and background, respectively. The comparison methods in this paper include ER 17  In order to further evaluate the effectiveness and applicability of the proposed method, some evaluation indexes are defined, accuracy (ACC), true positive rate (TPR), false positive rate (FPR), positive predictive value (PPV) and negative predictive value (NPV). These five indicators are used as the standard for the evaluation of the detection algorithm. The details of these metrics are provided in. 17 All the experiments are conducted on a notebook computer with an Intel Core i5-3320 processor and 6GB memory. The algorithm runs in the environment of MATLAB 2016a.

Experimental results and analysis
Component analysis in the proposed model. In order to further analyze the role of the various components of the WLRL model, we compared LR, WLR and WLRL on the same data set.The corresponding objective functions are shown in Table 1. Figure 4 shows the test results of some LR, WLR and WLRL. The 1st row displays original defective images; the 2nd row is corresponding ground-truth (GT) images; the 3rd row displays the results of the LR method; the 4th row exhibits the results of the WLR method; the 5th row shows the WLRL detection results.
It can be seen from Figure 4 that WLR increases the detection rate of large homogeneous defects, indicating that the defect prior plays an important role in ensuring the detection of large homogeneous defects. Compared with WLR, the detection effect of WLRL is further improved, and the detection results of small defects are increased, which confirms the effect of Laplace regular term. Compared with LR, WLRL has a significant improvement in detection results. For the fabric images whose foreground and background share similar appearance, WLRL successfully separates the defects from the background, while LR often fail. These results illustrate the robustness of the WLRL model, and confirm the effectiveness of the proposed weighted low-rank decomposition with Laplacian regularization. From the figure we can conclude that (1) through the defect prior, the detection rate of large homogeneous defect regions can be increased, and (2) after adding the Laplace regular term, the experimental results show that the detection results Significant improvement. Tables 2 and 3 are the comparison table of LR and WLRL test results on box-and star-patterned fabrics. It can be seen from Table 2 that WLRL has the best detection effect, that is, with overall highest ACC and highest TPR. And the total TPR increased by more than 20%, but at the same time, the FPR is inevitably slightly improved. It can be seen from Table 3 that the detection effect of WLRL has been greatly improved, especially for Thin Bar defect type, because WLRL has higher sensitivity to small and fine  defects. In particular, the experimental results show that the WLRL can make up for the lack of LR and improve the detection accuracy.
Adjusting the parameters of WLRL method. WLRL uses the weight parameter λ to adjust the degree of low rank and sparsity. Figure 5 illustrates the detection result of the weight parameter λ effect on the box-and star-patterned fabrics. The box-and star-patterned fabrics have undergone the same evaluation processes with the parameter of 0.02:0.1. Figure 5 clearly indicates that λ = 0.06 offers the best detection results among the five choices. When the parameters are too large or too small, it will cause false or missed detection. Tables 4 and 5 show the TPR and FPR detection results of box-and star-patterned fabrics with different parameter λ . For box-patterned fabrics, when λ = 0.06 Hole, Netting Multiple and Thick Bar defect types achieve the highest TPR. Although the λ = 0.04, Thin Bar achieves the highest TPR, but lower TPR for other types of defects. The average TPR increases from 61.55% to 72.83% when λ rises from 0.02 to 0.06. Therefore, λ = 0.06 is an optimal choice for box-patterned fabrics because all TPRs and FPRs begin to stable at the levels of 72.83% and 1.68%. For star-patterned fabrics, when λ = 0.06, the highest TPR is obtained for Netting Multiple, Thick Bar and Thin Bar defect types, and the lowest FPR is obtained for Thick Bar. When λ = 0.04, Broken End and Hole defect types achieve the highest TPR. Although λ = 0.1 generates the lowest average FPR 1.63%, it actually misses many defective regions. In contrast, the metric TPR reveals the performance more accurately: λ = 0.06 provides an average TPR of 83.63% for star-patterned fabrics, which is the highest among all parameters.
Comparison with state-of-the-arts. In this section, we test the WLRL on two categories of defective images: box-and star-patterned fabrics. In order to perform an intensive evaluation and clearly understand how accurate detection of the WLRL, we now compare the WLRL with other comparison methods in all respects (ER, PN-RPCA, GHOG-LR, and LSG).
Experimental results. For each defect type in the fabric image database, a defect image is randomly selected. The results of ER, PN-RPCA, GHOG-LR, LSG, and WLRL  Figure 6 depicts the detection results of defective images chosen from boxpatterned fabric database. LSG and WLRL detection results are significantly higher than other methods. PN-RPCA has a good detection result for Thick Bar, but the detection result of Hole is not ideal. In detail, GHOG-LR can detect the defective regions roughly but causes a large number of false detection. The main reason is that GHOG feature is not sensitive to box-patterned fabrics. In contrast, WLRL has strong adaptability to different types of defects and can accurately locate the defective regions. Figure 7 depicts the detection results of defective images chosen from the star-patterned fabric database. All methods except ER show relatively accurate detection results, especially WLRL. Although GHOG-LR cannot accurately detect defects of Thin Bar type, it can roughly locate defects of other types, and its performance on starpatterned fabrics is better than box-patterned fabrics. Generally, WLRL shows accurate detection results compared with other methods.
Tables 6 and 7 tabulate the numerical results of each defect type in box-and star-patterned fabrics. The results of the recent fabric detection method ER, PN-RPCA, GHOG-LR, and LSG are compared with the WLRL.
The WLRL obtains overall results of 98.70% ACC, 72.83% TPR, 1.67% FPR, 36.78% PPV, and 99.63% NPV for the box-patterned fabrics ( Table 6). The overall detection effect of WLRL is the best among all methods, that, with overall highest TPR and highest NPV. In all methods, the overall TPR (7.8%) of ER is the lowest, which indicates that it was less adaptable to the box-patterned fabrics. LSG achieves the highest overall PPV (75.8%) and the lowest overall FPR (1.06%), but its overall TPR (60.67%) is lower than WLRL (72.83%). GHOG-LR achieves the highest overall TPR (54.41%) for Thin Bar defect type, but the defect detection results for other types are poor. The ACC of several detection methods is more than 95%. In general, the results show that WLRL has stronger discriminative power to detect defects for boxpatterned fabrics.
The WLRL obtains overall results of 99.09% ACC, 83.63% TPR, 1.75% FPR, 39.12% PPV, and 99.56% NPV for the star-patterned fabrics ( Table 7). The overall detection effect of WLRL is the best among all methods, that is,   Running time comparison. The real-time property of fabric algorithm is very important in industrial application. Therefore, the efficiency of the method is tested by using 50 fabric images and the running time is shown in Figure 8 Here x-coordinate represents the index of the fabric images and y-coordinate represents the running time of the method. The comparison methods used here include ER, PN-RPCA, GHOG-LR, and LSG, all of which run on the same device. In order to evaluate the method fairly, the running time does not include the training time. LSG is the most time-consuming of all methods because it needs to acquire cartoon components through morphological component analysis (MAC). Compared with PN-RPCA and GHOG-LR, WLRL is the most time-consuming, because WLRL consumes time in acquiring defect prior. Therefore, the performance of WLRL is better than other methods when considering accuracy.

Conclusion
This paper presents a novel method for patterned fabric detection called WLRL, which combines weighted lowrank decomposition with Laplace regularization. A defect prior is added to the low-rank decomposition model to construct the weighted low-rank decomposition model, then add the Laplacian regularization to increase the distance between backgrounds and defects. Experiments show that WLRL can efficiently pinpoint the locations of defective objects in patterned fabric images with sharp edges. The average ACC and TPR of box-and star-patterned fabrics are 99.1% and 79.73%, respectively.
The database employed in this research is kindly provided by Industrial Automation Research Laboratory from Department of Electrical and Electronic of Hong Kong University

Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research, authorship, and/or publication of this article.