# An Improved Defect Detection Algorithm of Jean Fabric Based on Optimized Gabor Filter

Shuangbao Ma* , Wen Liu** , Changli You** , Shulin Jia** and Yurong Wua*

## Abstract

Abstract: Aiming at the defect detection quality of denim fabric, this paper designs an improved algorithm based on the optimized Gabor filter. Firstly, we propose an improved defect detection algorithm of jean fabric based on the maximum two-dimensional image entropy and the loss evaluation function. Secondly, 24 Gabor filter banks with 4 scales and 6 directions are created and the optimal filter is selected from the filter banks by the one-dimensional image entropy algorithm and the two-dimensional image entropy algorithm respectively. Thirdly, these two optimized Gabor filters are compared to realize the common defect detection of denim fabric, such as normal texture, miss of weft, hole and oil stain. The results show that the improved algorithm has better detection effect on common defects of denim fabrics and the average detection rate is more than 91.25%.

Keywords: Defect Detection , Denim Fabric , False Defect Removal , Gabor Filter , Iterative Segmentation

## 1. Introduction

Fabric defect detection is the most important key to control the fabric quality [1,2], however, the inspection process of most denim fabric manufacturers in China mainly relies on manual inspection, which requires heavy labor and may cause some physical or mental harm to the workers. More impor¬tantly, the efficiency of manual detection is very low, and the detection accuracy is only 60%–70% [3].

Usually, the jean fabric manufacturers use the white cotton yarn as the weft yarn to interwoven with the pure indigo-dyed cotton yarn as the warp yarn to produce the twill fabric. Therefore, the surface of the denim fabric has the exact same period, significant direction and uniform texture comparing to the traditional fabric [4]. Currently, these detection methods for fabric texture can be divided into four categories [5]. The statistical method mainly extracts the feature images of the fabric texture to detect defects, which includes gray-level co-occurrence matrix (GLCM) morphology. However, these based on structure methods have low detection rate for jean fabric according to the paper [6]. The modeling methods can obtain good effect such as pixel neighboring structure, statistical feature and different pixels linear structure feature, but these algorithms are very complex to realize [7]. The artificial neural networks with the ability of self-learning or self-organization are used to detect the fabric defects, which is not suit to detect the defects of jean fabric [8,9]. The frequency domain analysis such as power spectrum, multiresolution characteristic and spatial-frequency domain characteristic is utilized to extract the features of fabric texture, which commonly includes Fourier transform, wavelet transform and Gabor transform [10,11].

The paper presents an improved defect detection algorithm of jean fabric based on the optimized Gabor filter and selects the optimal Gabor filter from the Gabor filter banks utilizing the maximum two-dimensional image entropy and loss evaluation function. This paper is structured as follows. The Section 2 discusses the optimal Gabor filter. In Section 3, we propose the process of defects detection algorithm. In Section 4, we analyze and compare the optimal Gabor filter based on one-dimensional and two-dimensional gray image entropy in fabric defect detection. Section 5 concludes this paper.

## 2. Optimal Method of Gabor Filter

##### 2.1 Two-Dimensional Gabor Filter

The Gabor filter is widely used in image processing, computer vision and other fields because of its superior performance in extracting image local space and frequency domain information. The two-dimensional Gabor filter in the spatial domain can write as

##### (1)
[TeX:] $$\begin{array}{l} \mathrm{g}(x, y, \lambda, \theta, \psi, \sigma, \gamma)=\exp \left(-\frac{\hat{x}^{2}+\gamma^{2} \hat{y}^{2}}{2 \sigma^{2}}\right) \exp \left[\left(2 \pi \frac{\hat{x}}{\lambda}+\psi\right) i\right] \\ \text { where } \hat{x}=x \cos \theta+y \sin \theta, \hat{y}=-x \sin \theta+y \cos \theta \end{array}$$

and is the wavelength of Gabor filter, is the direction of the filter, is the phase offset, is the bandwidth of Gabor filter and is the spatial aspect ratio, which determines the shape of the filter.

##### 2.2 Optimal Gabor Filter

In image processing, the Gabor filter banks are usually designed as 4-scale 6-direction, which gives rise to large amount of data. Following consideration to the real-time problem in practical application and ensuring the accuracy rate of defects detection, an optimal Gabor filter based on the maximum two-dimensional imaging entropy and loss evaluation function is very necessary to discuss.

The two-dimensional image entropy can write as

##### (2)
[TeX:] $$H=-\sum_{i=0}^{255} \sum_{j=0}^{255} p_{i j} \log p_{i j}$$

where [TeX:] $$P_{j j}$$ represents the probability of occurrence of a spatial feature. The denim fabric texture image obtained is equally divided into [TeX:] $$N * N$$ blocks, the mean value of gray in each sub block D and the lose evaluation function L are defined as

##### (3)
[TeX:] $$D=\frac{1}{n * n} \sum_{i=1}^{n} \sum_{j=1}^{n} I(i, j), \quad L=\frac{D_{\max }-D_{\min }}{D_{\max }+D_{\min }}=-1+\frac{2}{1+\frac{D_{\min }}{D_{\max }}}$$

where [TeX:] $$I(i, j)$$ represents the mean value between the corresponding gray value and the neighboring gray value. It can be seen from formula (3) that the loss evaluation function increases with the increasing [TeX:] $$D_{\min } / D_{\max },$$ which means that the greater the difference between the pixel mean value [TeX:] $$D_{\max } \text { and } D_{\min }$$ of the sub image is, the more obvious the difference between the defect point and the normal texture, so it is easy to segment defects from the normal texture image.

## 3. Improved Defect Detection Algorithm

The steps of this improved defect detection algorithm based on optimized Gabor filter utilizing the maximum two-dimensional image entropy and loss evaluation function can be conceived as follows.

Step 1 (Preliminary training of jean fabric defects images): The main task of preliminary training defects image is converting color defects image into a grayscale image according to the amount of calculation in the processing. The transfer function is defined as

##### (4)
[TeX:] $$G 1=0.299 R+0.587 G+0.114 B$$

where G1 indicates the gray value of processed image.

Step 2 (Reconstructing Gabor filter): The 24 Gabor filter bank with 4 scales and 6 directions are constructed. Then according to formulas (1) and (2), the two-dimensional image entropy of 24 sub-graphs after filtering are calculated respectively to determine the optimal filtering direction.

Step 3 (Selecting the optimized Gabor filter and filtering): The defected images are separated into blocks and the loss evaluation function of each block are calculated, then the maximum loss evaluation function is selected as the optimized Gabor filter. Then the optimized Gabor filter is used to filter these denim defect images.

Step 4 (Locating these defects): In order to segment the defects from the defect images, defect texture image segmentation is needed. In this paper the iterative method is chosen to segment the sub-graphs and the flow of the algorithm is as follows.

(a) Traversing the defect texture image to obtain the maximum gray value [TeX:] $$G_{\max }$$ and the minimum gray value [TeX:] $$G_{\min },$$ then the initialization threshold is set as [TeX:] $$T=0.5\left(G_{\max }+G_{\min }\right);$$

(b) According to the initialization threshold T, the texture image is divided into two parts. One part is set as the average value [TeX:] $$V_{0}$$ of the gray, the other part is set as the average value [TeX:] $$V_{1}$$ of gray;

(c) Calculating the threshold by using [TeX:] $$T=0.5\left(V_{0}+V_{1}\right),$$ if T is not changed, then T is the optimal threshold. Otherwise, return to the step (b) to continue this calculation.

This step is used to iterate segment the common denim fabric defect image and the effect of the segmentation binary image of the defect textures image is shown in Fig. 1.

Iterative segmentation and false defect removal effect diagrams.

The effect of binary segmentation on weft missing, hole-breaking, and oil contamination are presented in sub-graphs (a1), (a2), and (a3), respectively in Fig. 1 and the sub-graphs (b1), (b2), and (b3) are the corresponding false defect removal diagram, respectively.

Step 5 (Eliminating false defect dots): As shown in Fig. 1, the iterative segmented binary image contains a large amount of isolated bright noises, which has an impact on the detection of defect dots, so it is necessary to eliminate these false defect dots. It is found that these false defect dot noises are not isolated pixels, but a small collection of pixels. There are many ways to obtain the largest connected region in the binary image.

This paper proposes a false defect dots algorithm based on the edge of the defects. Firstly, the edge detection operator is selected to perform edge detection on the binary image after the segmentation, so the edge image of the defect regions is obtained. Secondly, the image of the defects for detection and the segmented image are scanned and compared. When non-zero pixels are found in the segmented image, discriminate the same position of the image to be detected. If the corresponding position of the image to be detected is a non-zero pixel, it is a false defect and the pixel corresponding to the position in the binary image is set to zero. The false defects elimination effect diagram is illustrated in Fig. 1(b1–b3).

Step 6 (Algorithm end).

## 4. Results and Analysis

In order to test the practicability of this proved algorithm, this paper selects a common denim fabric defect sample image, which including normal image, weft missing, hole-breaking and oil pollution respectively as shown in Fig. 2(a1–a4). The segmentation sub-images of these four test images are shown in Fig. 2(b1–b4) and it is very easy to find that these defects are very remarkably. The optimized Gabor filter is selected by one-dimensional entropy of image, which is named as algorithm 1, and the optimized Gabor filter is selected by two-dimensional image entropy and loss evaluation function, which is named as algorithm 2 in this paper.

(a1) to (a4) and (b1) to (b4) are the original defect images of denim fabric and the segmentation sub-images, respectively. (c1) to (c4) and (d1) to (d4) are the processing results by Algorithm 1 and Algorithm 2, respectively.

These two filters are utilized to process four denim fabric defect images, and the results of algorithm 1 and algorithm 2 are shown in Fig. 2(c1–c4) and Fig. 2(d1–d4), respectively. As shown in Fig. 2, by comparing the sub-graphs (c2)–(c4) and the sub-graphs (d2)–(d4), especially for the oil pollution images, Algorithm 2 can achieve higher accuracy than Algorithm 1.

In order to test the detection effect of this improved algorithm on the defect of denim fabric. This paper selects the normal texture of denim fabric production line and the four texture types of latitude, hole and oil stain, and the type of each defect is 100 sheets. There are 400 defect samples in the database. Using the algorithm proposed in this paper to detect the image of four types of denim fabric samples. The defect detection effect diagrams of the improved algorithm for different sizes are shown in Fig. 3. It is notable to find that the algorithm is suit to different size denim fabric defect images.

(a1) to (d1) and (a2) to (d2) are the original defect images of weft missing and these processing results by Algorithm 2, respectively. (a3) to (d3) and (a4) to (d4) are the original defect images of hole-breaking and the processing results by Algorithm 2, respectively. (a5) to (d5) and (a6) to (d6) are the original defect images of oil pollution and the processing results by Algorithm 2, respectively.
Processing results of Algorithm 1 (unit: piece)
Processing results of Algorithm 2 (unit: piece)

The detection results using Algorithms 1 and 2 are shown in Tables 1 and 2, respectively.

It can be seen from Table 1 that algorithm 1 can detect four defects of denim fabric defect, with an average detection rate of 86.75%, and the highest detection rate is 95% for normal texture. While the improved algorithm has better detection effects for defects of denim fabrics, with an average detection rate of 91.25%, and the highest detection rate is 99% for normal texture as shown in Table 2.

## 5. Conclusion

This paper proposes an improved algorithm for defect detection of jean fabric by using the optimized Gabor filter with the two-dimensional image entropy and the loss evaluation function. This improved algorithm can locate the defect and eliminate false defect dots. In order to verify the effectiveness of the improved algorithm, two algorithms are compared to process 400 defect images with four types of defects such as normal texture, weft missing, hole and oil stain in denim fabric in the experiment. The results show that the improved algorithm we proposed can achieve good detection results, and the average detection rate of common defects of denim is more than 91.25%. With the development of the deep learning, the emergence of deep learning detection models such as AlexNet, VGG, and RESNET, which will bring some new breakthroughs to the research of fabric defect detection and become a hot research spot for denim defect detection.

## Acknowledgement

This paper is supported by grants from Hubei Key Laboratory of Digital Textile Equipment in Wuhan Textile University (No. DTL2018023, DTL2019017).

## Biography

##### Shuangbao Ma
https://orcid.org/0000-0001-7101-423X

He received Ph.D. degree in control science and engineering from Huazhong University of Science and Technology in 2013. Since July 2014, he is an associate professor at Wuhan Textile University in Wuhan,China. His current research interests include control, image processing, and deep learning.

## Biography

##### Wen Liu
https://orcid.org/0000-0002-4090-1730

He is currently studying for a master's degree at Wuhan Textile University. His current research interests include face recognition and deep learning.

## Biography

##### Changli You
https://orcid.org/0000-0002-1432-1791

She is currently studying for a master's degree at Wuhan Textile University. Her current research interests include image processing and deep learning.

## Biography

##### Shulin Jia
https://orcid.org/0000-0001-5718-8970

He is currently studying for a master's degree at Wuhan Textile University. His current research interests include control and image processing.

## Biography

##### Yurong Wu
https://orcid.org/0000-0002-4510-0385

She received a M.A. degree in measurement technology and instruments from Wuhan University in 2003. Since March 2019, she is an associate professor at Wuhan Textile University in Wuhan, China. Her current research interests include modeling and analysis of power, image processing, and deep learning.

## References

• 1 K. Yang, X. Feng, J. Zhou, "Fabric defects detection based on the optimal Gabor filters," Journal of Zhangzhou Teachers College (Natural Science Edition), vol. 2016, no. 1, pp. 39-45, 2016.custom:[[[-]]]
• 2 T. Xue, X. Liu, K. Zhang, Z. Wang, Y. Yan, H. Yan, "Learning-based Gabor filter in multi-style fabric defect detection," Journal of Xi'an Polytechnic University, vol. 31, no. 6, pp. 775-780, 2017.custom:[[[-]]]
• 3 M. Yu, Y. Li, G. Jiang, H. Cong, "Warp knit fabric defect detection method based on optimal Gabor filter," Journal of Textile Research, vol. 37, no. 11, pp. 48-54, 2016.custom:[[[-]]]
• 4 W. Li, L. Cheng, "New progress of fabric defect detection based on computer vision and image processing," Journal of Textile Research, vol. 35, no. 3, pp. 158-164, 2016.custom:[[[-]]]
• 5 X. Min, Q. Lin, Y. Zhu, "Fabric defect detection based on gray level co-occurrence matrix using image block processing," Information Technology, vol. 2018, no. 5, pp. 90-93, 2015.custom:[[[-]]]
• 6 Z. Li, J. Zhou, R. Pan, J. Liu, W. Gao, "Fabric defect detection using monogenic wavelet analysis," Journal of Textile Research, vol. 37, no. 9, pp. 59-64, 2016.custom:[[[-]]]
• 7 G. Hu, "Markov random field image segmentation method combined with edge constraints," Computer Knowledge and Technology, vol. 2018, no. 20 pp.174-178, pp. no.20 174-178, 2018.custom:[[[-]]]
• 8 Z. Cao, J Jing, Z. Su, H. Zhang, "Study on the defect detection of Yarn-dyed fabric with deep learning based on Raspberry Pi," Cotton Textile Technology, vol. 47, no. 1, pp. 11-15, 2019.custom:[[[-]]]
• 9 W. Ouyang, B. Xu, J. Hou, X. Yuan, "Fabric defect detection using activation layer embedded convolutional neural network," IEEE Access, vol. 7, pp. 70130-70140, 2019.custom:[[[-]]]
• 10 M. Wang, Y Li, S. Du, G. Jiang, H. Luo, "Fabric defect detection based on gray-level gradient co-occurrence matrix and SVDD," Silk Monthly, vol. 55, no. 12, pp. 50-56, 2018.custom:[[[-]]]
• 11 J. L. Raheja, S. Kumar, A. Chaudhary, "Fabric defect detection based on GLCM and Gabor filter: a comparison," Optik, vol. 124, no. 23, pp. 6469-6474, 2013.custom:[[[-]]]

Table 1.

Processing results of Algorithm 1 (unit: piece)
Test sample Sample amount Detection amount Detection error amount Detection rate (%)
Normal texture 100 95 5 95
Weft missing 100 79 21 79
Hole 100 92 8 92
Oil stain 100 81 19 81

Table 2.

Processing results of Algorithm 2 (unit: piece)
Test sample Sample amount Detection amount Detection error amount Detection rate (%)
Normal texture 100 99 1 99
Weft missing 100 86 14 86
Hole 100 93 7 93
Oil stain 100 87 13 87
Iterative segmentation and false defect removal effect diagrams.
(a1) to (a4) and (b1) to (b4) are the original defect images of denim fabric and the segmentation sub-images, respectively. (c1) to (c4) and (d1) to (d4) are the processing results by Algorithm 1 and Algorithm 2, respectively.
(a1) to (d1) and (a2) to (d2) are the original defect images of weft missing and these processing results by Algorithm 2, respectively. (a3) to (d3) and (a4) to (d4) are the original defect images of hole-breaking and the processing results by Algorithm 2, respectively. (a5) to (d5) and (a6) to (d6) are the original defect images of oil pollution and the processing results by Algorithm 2, respectively.