Method for obtaining fabric standard image by combining neighborhood and global features
By using a weighted fusion screening mechanism of Mahalanobis distance and Euclidean distance, combined with global and neighborhood features, fabric datasets are automatically screened, solving the problems of time-consuming and poor adaptability of manual screening, and achieving efficient and accurate dataset screening and defect detection.
Patent Information
- Application Number
- CN202511681520.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-17
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2045-11-17
AI Technical Summary
In existing technologies for fabric defect detection, manual screening is time-consuming and labor-intensive, pixel threshold screening methods have poor adaptability, and cluster analysis is prone to confusion, resulting in low efficiency and insufficient detection accuracy in fabric dataset screening.
A weighted fusion screening mechanism of Mahalanobis distance and Euclidean distance is adopted, which combines global features and neighborhood features to automatically screen fabric datasets. Global scores and neighborhood scores are obtained by calculating Mahalanobis distance and Euclidean distance, and a comprehensive score is calculated. A screening threshold is set to select standard images.
It achieves efficient and automated fabric dataset screening, improves screening accuracy and robustness, shortens screening time, and enhances the quality of model training datasets and the reliability of defect detection.
Smart Images

Figure CN121616531A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention generally relate to the field of image processing technology, and more particularly to a method for obtaining standard images of fabrics by combining neighborhood and global features. Background Technology
[0002] In recent years, automated defect detection technology based on machine vision and artificial intelligence has received widespread attention. In the field of fabric defect detection, supervised learning methods face obstacles in obtaining sufficient labeled data due to the scarcity and difficulty in fully annotating defect samples; while unsupervised learning models can effectively identify defect regions by learning the feature distribution of normal fabric surfaces, and have become the mainstream method.
[0003] However, in practical applications, the input image sets for unsupervised learning often contain defective or abnormal images. This interference data reduces the accuracy of the generated detection templates, thus affecting the overall detection performance of the model. Currently, standard image screening for fabric datasets mainly employs methods such as manual screening, pixel threshold screening, and cluster analysis screening. However, manual screening is not only time-consuming and labor-intensive but also disrupts the production process, leading to decreased production continuity and efficiency. Pixel threshold screening relies on single pixel features, making it difficult to adapt to different fabric types. Cluster analysis screening requires manual setting of initial parameters, which can easily cause confusion between normal and abnormal images. Therefore, an efficient and automated method is needed to optimize the standard image screening process for fabric datasets. Summary of the Invention
[0004] To address the above issues, this invention employs a weighted fusion filtering mechanism based on Mahalanobis distance and Euclidean distance to automate the filtering of fabric datasets. This mechanism captures the statistical characteristics of global feature distribution while preserving the differences between adjacent features, resulting in more accurate standard image filtering.
[0005] According to an embodiment of the present invention, a method for obtaining a standard image of a fabric by combining neighborhood and global features is provided.
[0006] In a first aspect of the invention, a method for acquiring a standard image of a fabric by combining neighborhood and global features is provided. The method includes: Step S01: Obtain the original image of the fabric to be detected and perform preprocessing; Step S02: Calculate the Mahalanobis distance for each image and normalize it to obtain the global score; Step S03: Calculate the Euclidean distance for each image and obtain the neighborhood score; Step S04: Calculate the comprehensive score of each image based on the weighted fusion of the global score and the neighborhood score, set a filtering threshold score, and filter out images whose comprehensive score is less than the filtering threshold score.
[0007] Furthermore, the specific steps of step S01 are as follows: Step S011: Obtain the original image of the fabric to be detected. If the original image is a single large-size image, its size is height. ,Width Then the original image will be cropped into a window according to the set size. From each sub-image, we obtain a set of sub-images. If the original image is a single, small-sized image, then the image set is obtained from several sets of original images. ; Step S012: For the set or Each image in the process undergoes uniform preprocessing, is converted into a three-channel format, and scaled to a preset fixed resolution; Step S013: Perform normalization and standardization preprocessing on the resized image.
[0008] Furthermore, the specific steps of step S02 are as follows: Step S021: For the set or Each image in or Inputting the data into a pre-trained convolutional neural network model extracts the corresponding high-dimensional feature vectors. This yields the global feature vector set. ; Step S022: Calculate the global feature vector set mean ; Step S023: Based on the global feature vector set Calculate the covariance matrix ; Step S024: For the global feature vector set The feature vector corresponding to each image in the data The Mahalanobis distance is calculated based on the global mean and covariance matrix. The calculation formula is as follows: .
[0009] Step S025: Calculate the Mahalanobis distance for each image. and to The values are normalized to obtain the global score. .
[0010] Furthermore, the specific steps of step S03 are as follows: Step S031: Set or The neighborhood relationships of images are determined according to their index order. For any image or Its corresponding feature vector eigenvectors adjacent to the left and right and Perform consistency determination, that is, calculate the image or corresponding feature vector Euclidean distance between its left and right adjacent feature vectors , To measure the image or The degree of difference between the image and its neighboring images in the feature space: , , in, for The 1st dimension of the vector dimension; Step S032: Calculate the Euclidean distance between the obtained left and right adjacent feature vectors. , Perform an average calculation and divide by the set maximum distance value. Image obtained by numerical scaling or neighborhood score .
[0011] Furthermore, the aforementioned When =1, its eigenvector and , Perform consistency determination; the aforementioned When =N, its eigenvector and , Perform a consistency check.
[0012] Furthermore, the specific steps of step S04 are as follows: Step S041: For the set or Each image or Based on their global scores respectively neighborhood score Calculate the overall score The formula is as follows: , The weights for the global score and the neighborhood score are respectively... and ,and Greater than ; Step S042: Set the filtering threshold score Based on this, the images are classified, retaining those that meet the criteria. The images form a normal sample set. ; Step S043: Set up the normal sample set Image output in the process.
[0013] In a second aspect of the invention, an apparatus for acquiring a standard image of a fabric by combining neighborhood and global features is provided. The apparatus includes: Image preprocessing module: used to acquire the original image of the fabric to be detected and perform preprocessing; Global score calculation module: used to calculate the Mahalanobis distance of each image and normalize it to obtain the global score; Neighborhood score calculation module: used to calculate the Euclidean distance of each image and obtain the neighborhood score; Normal sample filtering module: It is used to calculate the comprehensive score of each image based on the weighted fusion of global score and neighborhood score, set the filtering threshold score, and filter out images with a comprehensive score less than the filtering threshold score.
[0014] In a third aspect of the invention, an electronic device is provided. The electronic device includes a memory and a processor, the memory storing a computer program, the processor executing the program to implement the method according to a first aspect of the invention.
[0015] In a fourth aspect of the invention, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method according to a first aspect of the invention.
[0016] This invention utilizes a weighted fusion filtering mechanism based on Mahalanobis distance and Euclidean distance to automate the filtering of fabric datasets. It captures the statistical characteristics of global feature distribution while retaining the difference information of adjacent features, thus achieving more accurate standard image filtering.
[0017] It should be understood that the description in the Summary of the Invention is not intended to limit the key or essential features of the embodiments of the present invention, nor is it intended to restrict the scope of the invention. Other features of the invention will become readily apparent from the following description.
[0018] The beneficial effects of this invention are: 1. No manual setting of initial parameters is required, effectively avoiding the risk of confusing normal and abnormal images due to improper parameter settings, ensuring the stability of the screening process and the reliability of the results; at the same time, by comprehensively considering the neighborhood features and global features of the image, it can more comprehensively capture the structure and overall characteristics of different fabric images, significantly improving the robustness and versatility of the screening method for different fabric types. 2. This invention possesses extremely high processing efficiency, for example, processing a large image (3000 pixels). (2000 pixels) It only takes about 1.2 seconds, which greatly shortens the time required for screening compared to the traditional manual screening method, and significantly improves the efficiency of creating datasets for model training; 3. This invention can effectively identify and remove abnormal images, which helps to generate more accurate defect detection templates, thereby optimizing the quality of the dataset used for training unsupervised learning models and ultimately ensuring the reliability and accuracy of subsequent defect detection models. Attached Figure Description
[0019] The above and other features, advantages, and aspects of the various embodiments of the present invention will become more apparent from the accompanying drawings and the following detailed description. Wherein: Figure 1 A flowchart illustrating a method for acquiring a standard fabric image by combining neighborhood and global features according to an embodiment of the present invention is shown. Figure 2 A schematic diagram of the original fabric image according to an embodiment of the present invention is shown; Figure 3 A schematic diagram of a cropped image according to an embodiment of the present invention is shown; Figure 4 A sub-example according to an embodiment of the present invention is shown. Figure 3 Result diagram; Figure 5 A sub-example according to an embodiment of the present invention is shown. Figure 9 Result diagram; Figure 6 A schematic diagram of the result of sub-Figure 15 according to an embodiment of the present invention is shown; Figure 7 A schematic diagram of the result of sub-Figure 19 according to an embodiment of the present invention is shown; Figure 8 A schematic diagram of the result of sub-Figure 21 according to an embodiment of the present invention is shown; Figure 9 A block diagram of an apparatus for acquiring a standard image of a fabric by combining neighborhood and global features according to an embodiment of the present invention is shown. Figure 10 A schematic diagram of a device for acquiring a standard image of a fabric by combining neighborhood and global features according to an embodiment of the present invention is shown. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0021] According to an embodiment of the present invention, a method for obtaining standard images of fabrics by combining neighborhood and global features is proposed. Based on a weighted fusion screening mechanism of Mahalanobis distance and Euclidean distance, the method realizes automated screening of fabric datasets, which can capture the statistical characteristics of global feature distribution and retain the difference information of adjacent features, thereby achieving more accurate standard image screening.
[0022] The principles and spirit of the present invention will be explained in detail below with reference to several representative embodiments.
[0023] Figure 1 This is a schematic flowchart illustrating a method for obtaining a standard fabric image by combining neighborhood and global features according to an embodiment of the present invention. The method includes: Step S01: Obtain the original image of the fabric to be detected and perform preprocessing; Step S02: Calculate the Mahalanobis distance for each image and normalize it to obtain the global score; Step S03: Calculate the Euclidean distance for each image and obtain the neighborhood score; Step S04: Calculate the comprehensive score of each image based on the weighted fusion of the global score and the neighborhood score, set a filtering threshold score, and filter out images whose comprehensive score is less than the filtering threshold score.
[0024] It should be noted that although the operation of the method of the present invention has been described in a specific order in the above embodiments and figures, this does not require or imply that the operations must be performed in that specific order, or that all the operations shown must be performed to achieve the desired result. Additionally or alternatively, certain steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps.
[0025] To provide a clearer explanation of the method for obtaining standard fabric images by combining neighborhood and global features, a specific embodiment will be described below. However, it is worth noting that this embodiment is only for better illustrating the present invention and does not constitute an improper limitation of the present invention.
[0026] The following example will further illustrate a method for obtaining standard fabric images by combining neighborhood and global features: Step S01: Obtain the original image of the fabric to be detected and perform preprocessing.
[0027] Step S011: Obtain the original image of the fabric to be detected. The original image is a single large-size image with a height of [missing information]. ,Width The original image is cropped into a window according to the set size. From each sub-image, we obtain a set of sub-images. If the original image is a single, small-sized image, then the image set is obtained from several sets of original images. .
[0028] In this embodiment, as Figure 2 As shown, the original image dimensions are: 3000 pixels high and 2000 pixels wide, and the image is set to 500 pixels wide. A 500-pixel window size will crop the original image, such as... Figure 3 As shown, the sub-image set is obtained. .
[0029] Step S012: For the set or Each image in the process undergoes uniform preprocessing, is converted into a three-channel format, and scaled to a preset fixed resolution to meet the input requirements of subsequent models.
[0030] In this embodiment, the preset fixed resolution is 224. 224.
[0031] Step S013: Perform normalization and standardization preprocessing on the resized image to conform to the input specifications of the detection model.
[0032] Step S02: Calculate the Mahalanobis distance for each image and normalize it to obtain the global score.
[0033] Step S021: For the set or Each image in or Inputting the data into a pre-trained convolutional neural network model extracts the corresponding high-dimensional feature vectors. This yields the global feature vector set. .
[0034] Step S022: Calculate the global feature vector set mean It is used to characterize the central distribution characteristics of normal regions.
[0035] Step S023: Based on the global feature vector set Calculate the covariance matrix , is used to describe the overall statistical distribution within the feature space.
[0036] Step S024: For the global feature vector set The feature vector corresponding to each image in the data The Mahalanobis distance is calculated based on the global mean and covariance matrix to measure the correlation and scaling differences of the feature across different dimensions. The Mahalanobis distance quantifies the deviation of the feature vector from the normal feature distribution. The formula for calculating the Mahalanobis distance is: .
[0037] Step S025: Calculate the Mahalanobis distance for each image. and to The values are normalized to obtain the global score. The higher the score, the greater the degree of deviation from the normal characteristic distribution, and the more likely it is to belong to an abnormal fabric area.
[0038] Step S03: Calculate the Euclidean distance for each image and obtain the neighborhood score.
[0039] Step S031: Set or The neighborhood relationships of images are determined according to their index order, with images at adjacent indices being neighbors. For any image or Its corresponding feature vector eigenvectors adjacent to the left and right and Perform a consistency check. Specifically, when... When =1, its eigenvector and , Perform a consistency check. When When =N, its eigenvector and , Perform a consistency check.
[0040] Consistency determination is mainly achieved by calculating the image or corresponding feature vector Euclidean distance between its left and right adjacent feature vectors , To measure the image or The degree of difference between the image and its neighboring images in the feature space: , , in, for The 1st dimension of the vector dimension.
[0041] Step S032: Calculate the Euclidean distance between the obtained left and right adjacent feature vectors. , Perform an average calculation and divide by the set maximum distance value. Image obtained by numerical scaling or neighborhood score The higher the score, the lower the consistency between it and its neighboring images.
[0042] Step S04: Calculate the comprehensive score of each image based on the weighted fusion of the global score and the neighborhood score, set a filtering threshold score, and filter out images whose comprehensive score is less than the filtering threshold score.
[0043] Step S041: For the set or Each image or Based on their global scores respectively neighborhood score Calculate the overall score The formula is as follows: , The weights for the global score and the neighborhood score are respectively... and ,and Greater than This ensures that global features take precedence over neighborhood consistency information.
[0044] Step S042: Set the filtering threshold score Based on this, the images are classified, retaining those that meet the criteria. The images form a normal sample set. .
[0045] Step S043: Set up the normal sample set The image output is used as a set of normal fabric images for subsequent template construction and model training.
[0046] In this embodiment, the global score of all images Neighborhood score and overall score As shown in Table 1: Table 1
[0047] Set the filter threshold score 0.8, removed Greater than Sub-images: sub Figure 3 ,son Figure 9 Subgraphs 15, 19, and 21 are retained, and the remaining subgraphs are used to form a normal sample set. .
[0048] In practice, the global score and neighborhood score of this invention are significantly higher in abnormal regions than in normal regions. Specifically, for larger abnormal regions, such as sub-regions... Figure 3 , 9 At scores of 15 and 21, the global score increases significantly; while for smaller abnormal regions, such as sub-image 19, the neighborhood score shows a significantly high value, thus further ensuring the distinguishing ability of small regions. By fusing the global score and the neighborhood score, this invention can effectively filter out image data with normal fabric surfaces. Figure 4-8 As shown, they are sub- Figure 3 ,son Figure 9 The results of subfigures 15, 19 and 21.
[0049] Based on the same inventive concept, this invention also proposes a device for acquiring standard fabric images by combining neighborhood and global features. The implementation of this device can be found in the implementation of the method described above, and repeated details will not be elaborated further. Figure 9 As shown, the device 100 includes: Image preprocessing module 101: used to acquire the original image of the fabric to be detected and perform preprocessing; Global score calculation module 102: used to calculate the Mahalanobis distance of each image and normalize it to obtain the global score; Neighborhood score calculation module 103: used to calculate the Euclidean distance of each image and obtain the neighborhood score; Normal sample screening module 104: It is used to calculate the comprehensive score of each image based on the weighted fusion of global score and neighborhood score, set the screening threshold score, and screen out images with a comprehensive score less than the screening threshold score.
[0050] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the described module can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0051] like Figure 10As shown, the device includes a central processing unit (CPU), which can perform various appropriate actions and processes based on computer program instructions stored in read-only memory (ROM) or loaded from storage units into random access memory (RAM). The RAM can also store various programs and data required for device operation. The CPU, ROM, and RAM are interconnected via a bus. Input / output (I / O) interfaces are also connected to the bus.
[0052] Multiple components in the device are connected to the I / O interface, including: input units such as keyboards and mice; output units such as various types of displays and speakers; storage units such as disks and optical discs; and communication units such as network interface cards (NICs), modems, and wireless transceivers. The communication unit allows the device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0053] The processing unit executes the various methods and processes described above, such as method steps S01 to S04. For example, in some embodiments, method steps S01 to S04 may be implemented as a computer software program tangibly contained in a machine-readable medium, such as a storage unit. In some embodiments, part or all of the computer program may be loaded and / or installed on the device via ROM and / or a communication unit. When the computer program is loaded into RAM and executed by the CPU, one or more steps of method steps S01 to S04 described above may be performed. Alternatively, in other embodiments, the CPU may be configured to execute method steps S01 to S04 by any other suitable means (e.g., by means of firmware).
[0054] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload programmable logic devices (CPLDs), and so on.
[0055] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0056] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0057] Furthermore, although the operations are described in a specific order, this should be understood as requiring that such operations be performed in the specific order shown or in sequential order, or requiring that all illustrated operations be performed to achieve the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the invention. Certain features described in the context of individual embodiments may also be implemented in combination in a single implementation. Conversely, various features described in the context of a single implementation may also be implemented individually or in any suitable sub-combination in multiple implementations.
[0058] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
Claims
1. A method for acquiring a standard image of a fabric combining local and global features, characterized in that, The method comprises: Step S01: obtaining original images of the fabric to be detected and performing pretreatment; Step S02: calculating Mahalanobis distance of each image and performing normalization to obtain global scores; Step S03: calculating Euclidean distance of each image and obtaining neighborhood scores; Step S04: calculating comprehensive scores of each image based on weighted fusion of the global scores and the neighborhood scores, setting a screening threshold score, and screening images with comprehensive scores less than the screening threshold score.
2. The method of claim 1, wherein the method further comprises: The specific steps of the step S01 are: Step S011: Obtain the original image of the fabric to be detected. If the original image is a single large-size image, its size is height. ,Width Then the original image will be cropped into a window according to the set size. From each sub-image, we obtain a set of sub-images. If the original image is a single, small-sized image, then the image set is obtained from several sets of original images. ; Step S012: uniform preprocessing is performed on each image in the set or , converted into a three-channel format, and scaled to a preset fixed resolution; Step S013: performing normalization and standardization pretreatment on the image after size adjustment.
3. The method of claim 1, wherein the acquiring a standard image of a fabric combining local and global features is characterized by, The specific steps of the step S02 are: Step S021: inputting each image in the set or to a pre-trained convolutional neural network model to extract a corresponding high-dimensional feature vector or , to obtain a set of global feature vectors ; Step S022: calculating the mean of the set of global feature vectors ; Step S023: generating the global feature vector set based on the local feature vector set Computing the covariance matrix ; Step S024: calculating Mahalanobis distance of each image in the global feature vector set based on the global mean and covariance matrix, the calculation formula is: . Step S025: Calculate the Mahalanobis distance corresponding to each image , and normalize the value to obtain the global score . 4. The method of claim 1, wherein the acquiring a standard image of a fabric combining local and global features is characterized by, The specific steps of the step S03 are: Step S031: Set or The neighborhood relationships of images are determined according to their index order. For any image or Its corresponding feature vector eigenvectors adjacent to the left and right and Perform consistency determination, that is, calculate the image or Corresponding feature vector Euclidean distance between its left and right adjacent feature vectors , To measure the image or The degree of difference between the image and its neighboring images in the feature space: , , wherein is the first dimension; Step S032: Calculate the Euclidean distance between the obtained left and right adjacent feature vectors , Perform average calculation and divide by the set maximum distance value Perform numerical scaling to obtain the image or neighborhood score .
5. The method of claim 4, wherein the method further comprises: The = 1, Eigen vector thereof With , Consistency determination; the =N, characteristic vector with , make a consistency determination.
6. The method of claim 1, wherein the method further comprises: obtaining a standard image of the fabric by combining the local features and the global features. The specific steps of the step S04 are: Step S041: For each image in the set or each image or based on its global score and neighborhood score a composite score is computed as follows: , wherein the weights of the global score and the neighborhood score are and , and greater than ; Step S042: set a screening threshold score , and classify each image based on the threshold, retain images satisfying , and form a normal sample set ; Step S043: outputting images in the normal sample set to the display.
7. An apparatus for acquiring a standard image of a fabric combining local and global features, characterized in that, The device comprises: An image pretreatment module: used for obtaining original images of the fabric to be detected and performing pretreatment; A global score calculation module: used for calculating Mahalanobis distance of each image and performing normalization to obtain global scores; A neighborhood score calculation module: used for calculating Euclidean distance of each image and obtaining neighborhood scores; A normal sample screening module: used for calculating comprehensive scores of each image based on weighted fusion of the global scores and the neighborhood scores, setting a screening threshold score, and screening images with comprehensive scores less than the screening threshold score.
8. An electronic device comprising a memory and a processor, said memory having stored thereon a computer program, characterized in that, The processor implements the method according to any one of claims 1-6 when executing the program.
9. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program is executed by the processor to implement the method according to any one of claims 1-6.
Citation Information
Patent Citations
PCB defect detection method based on coordinate attention mechanism
CN119107316A
Textile defect type identification method
CN119399187A
Fabric defect detection method based on deep convolutional neural network and visual saliency
WO2019104767A1