Hairiness detection method based on affinity characteristics and path reconnection
Through the hair feather detection method based on affinity characteristics and path reconnection, the problems of incomplete hair feather detection information and poor repeatability are solved, and more efficient and accurate hair feather detection is achieved to meet the production needs of the textile industry.
Patent Information
- Application Number
- CN202411090413.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-11-22
AI Technical Summary
In the existing hair feather detection technology, the hair feather quantity and quality index detection information is not comprehensive enough, and the repeatability of the test results is poor, which cannot meet the production needs of the textile industry.
Using a feather detection method based on affinity features and path reconnection, yarn images are collected through the Basler acA2500-60uc industrial camera, a multi-directional bar convolution module and information entropy feature selection module are constructed to learn the affinity relationship of adjacent pixels. Combined with an effective refinement algorithm, accurate segmentation and quantity statistics of hair feathers are achieved.
It improves the accuracy and efficiency of hair feather detection, reduces the workload of manual inspection, avoids waste of raw materials, improves the working environment of workers, and can detect hair feather quantity more efficiently and accurately.
Smart Images

Figure CN119006909A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of image recognition, and in particular relates to a hairiness detection method based on affinity features and path reconnection. Background Art
[0002] China is a major textile country in the world, and the total fiber processing volume has accounted for more than 50% of the global fiber processing market. As the world's leading exporter of yarn and textile products, my country's textile product trade has maintained a leading position in the world for many years. Yarn, as an indispensable raw material for all textiles, plays an important role in textiles and clothing, medical care, aerospace and other fields. Hairiness is an inevitable product in the yarn production process and one of the indicators for measuring yarn quality. Hairiness has an important impact on the production efficiency of the subsequent textile processes and the performance and appearance quality of textiles. Too much long hairiness will increase the difficulty of weaving and lead to defects such as color difference, pilling and coarse weft. It may also reduce the effective height of the loom channel, thereby reducing production efficiency, so the detection of hairiness is very important for the production of the textile industry.
[0003] At present, textile enterprises mainly use photoelectric method to detect hairiness, but the photoelectric equipment is expensive, the detection information of hairiness quantity and quality index is not comprehensive, and the repeatability of the detection results is poor, so it cannot meet the detection needs well. In recent years, machine vision technology has developed rapidly. Due to its advantages such as high precision and low cost, it has provided a new way for hairiness detection and analysis. By using high-resolution cameras and advanced image processing algorithms, hairiness detection can be performed on yarns of various materials and specifications, and the efficiency and accuracy of detection are greatly improved. Therefore, the hairiness detection system based on visual signals and machine learning algorithms has received more and more attention. Summary of the invention
[0004] The purpose of the present invention is to provide a hairiness detection method based on affinity features and path reconnection, which solves the problem that the hairiness quantity and quality index detection information in the existing hairiness detection technology is not comprehensive enough and the repeatability of the detection results is poor.
[0005] The technical solution adopted by the present invention is a hairiness detection method based on affinity characteristics and path reconnection, comprising the following steps:
[0006] S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set;
[0007] S2, classify and annotate the hairiness detection data set and make label annotations;
[0008] S3, constructing a multi-directional strip convolution module and an information entropy feature selection module, using the multi-directional strip convolution module to capture the hairiness context information of the labeled annotated data set in S2 from four different directions, and using the information entropy feature selection module to enhance the original features of the hairiness context information to form an enhanced data set;
[0009] S4. Construct an affinity feature module, use the affinity feature module to learn the affinity relationship between adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers.
[0010] The present invention is also characterized in that:
[0011] The multi-directional strip convolution module in S3 is as follows: the input is X∈R H×W×C , where H, W, and C represent the width, height, and number of channels of the feature map, respectively; X represents a 1×1 convolution before being input into four parallel paths. Each of the four paths contains a strip convolution in one direction, and then the output feature maps are concatenated, upsampled, and convolved to obtain the final output. Let w∈R 2k+1 is a strip convolution of size 2K+1, D=(D h ,D W ) is the direction of the strip convolution w, Z D ∈R H×W×C ' represents the result of strip convolution; strip convolution is defined as:
[0012] Z D [i,j]=(X*w) D [i,j] (1);
[0013] Where: X*w represents the convolution operation; D is the direction of the strip convolution;
[0014] The multi-directional strip convolution module takes the values of (0, 1), (1, 0), (1, 1) and (-1, 1) for strip convolutions for horizontal, vertical, left diagonal and right diagonal convolutions respectively. For the strip convolution w, k = 4 is set so that each strip convolution has 9 parameters, which is the same as the 3×3 convolution kernel.
[0015] The information entropy feature selection module in S3 is specifically as follows: The information entropy feature selection module provides additional information about the similarities and differences between regions to assist in distinguishing targets, which is expressed as:
[0016]
[0017] P i,j =f(i n ,jn ) / (H×W) (3);
[0018] Where in is the gray value of the center pixel of the nth 3×3 sliding window; jn is the average gray value of the remaining pixels in the window; Pi,j represents the probability that (in, jn) appears in the entire image; H and W represent the image size; E represents the information entropy;
[0019] The pixels in the image correspond to grayscale values of [0, 255]. Each element in the feature map represents the activation level of the convolution at a specific position in the input image. Given an input feature Fx, the tuple (i, j) obtained by the sliding window is converted into a histogram, which involves rearranging the feature map activations, which represents the size of the activation level and its distribution in the neighborhood;
[0020] The information entropy feature selection module dynamically selects features from the input features to enhance the channel features that have a greater effect on the current object segmentation. Specifically, for the input yarn hairiness image X, its depth feature F x =[f1,f2,f3,...,f c ]∈R C×H×W , obtain F through the encoder x =Encoder(X,θ x ), where the weight is θ x , feature enhancement can be expressed as:
[0021] F x '=max{S(F x ),r} (4);
[0022] Where: F x ' is the selected feature map; S is the quantization method; r is the selected ratio.
[0023] The affinity feature module in S4 is as follows: Given a semantic label image G s =R H×W Let xl be one of the eight neighboring pixels in N(x), and N(x) be the set of the eight neighboring pixels in x. For different object sizes, the adaptive weight of each scale affinity domain of each pixel will be the label affinity domain Represented as N relative position affinity vectors corresponding to x, pixels x and x l belong to the same category, and the affinity of l The direction of is defined as 1, then the affinity of each relative position of x to l As shown in formula (5):
[0024]
[0025] In the formula, G s(x l ) represents the affinity domain of pixel x at position l in the label image;
[0026] For affinity domain learning, binary cross entropy (BCE) loss and affinity domain cosine distance (ACD) loss are used to produce a clean affinity domain, which is defined as:
[0027]
[0028] L t =L BCE (Y s ,G s )+L BCE (Y A ,G A )+λL ACD (Y A ,G A ) (9);
[0029] Where Y s (x) and G s (x) are the predicted segmentation map and label map of x respectively; the predicted It is represented as the predicted affinity vectors of N relative positions corresponding to x; |*| is the size measure; ||*|| is the size of the vector; λ b is a balanced hyperparameter; L CAD It helps the model extract better multi-scale semantic relationships for feathers of different sizes and backgrounds;
[0030] For the feature enhancement part, we first calculate the N relative position prediction affinity vectors corresponding to x. The average predicted affinity domain μ of x is used as a reference for feature selection during segmentation. The average affinity feature represents the overall state of its neighborhood semantic relationship, and its definition is shown in formula (10):
[0031]
[0032] Where N is the total number of x's neighbors; l represents the relative position; represents affinity; under the guidance of the average affinity domain μ, any relative position with an affinity greater than μ is likely to have similar semantic information to x;
[0033] Then feature enhancement is achieved through grouping and selection, for which similar category position affinity domains are represented as Its corresponding relative position x is obtained by comparing the affinity of each neighbor position A similar category to the average affinity domain μ selection position can be defined as:
[0034]
[0035] Given the selected location l, according to the segmentation feature f of x seg (x) Enhancement:
[0036]
[0037] In the formula, f seg (x l ) represents the segmentation feature corresponding to l; W M (x) represents the multi-scale adaptive weights for different S; S represents a set of scales.
[0038] The effective refinement algorithm in S4 is as follows: after obtaining the feather skeleton pixels, since the feather skeleton is a structure connected by a single pixel and eight neighborhoods, a 3×3 filter is designed to traverse the feather skeleton to identify three key points: endpoints, intersections, and cross-extension points; when performing path tracing, in order to avoid tracking errors when performing eight-neighborhood tracking in some cases, cross-extension points are set. If the endpoint is tracked, the tracking path is recorded and the tracking ends; the pixel value of the tracked pixel is set to 0, and all the endpoints in the image are tracked and the tracking path is recorded; in order to facilitate the subsequent connection of feather fragments, the tracking path is saved in reverse order in the array during the saving process. After the endpoint tracking is completed, the intersection-to-intersection tracking is performed, and then the tracking path is saved;
[0039] After obtaining the tracking results, the feather segments are connected. First, the two segments A and B with the smallest distance between the feather segments of the endpoint tracking path are found. The distance is;
[0040]
[0041] Where disAB represents the distance between A and B. As for the result of the thinning algorithm, there is an inaccurate description of the feather morphology, and the feather intersection is thinned into a short segment instead of a point. Here, d = 5 is set based on experience, and the distance constraint is used to ensure that the two feather segments are not too far apart, that is, disAB <d;
[0042] Then, the feather cross extension points are used to match and connect each feather segment, and the path points are adaptively selected by counting the number of pixel points n recorded in the array before the feather point:
[0043]
[0044] Then the bending angle of the connection path is calculated, and the reconnection path with a bending angle less than 135° is rejected, as shown in equations (15) to (18), and finally the complete splicing of the feathers is achieved;
[0045] (x C ,y C )=((xA +x B ) / 2,(y A +y B ) / 2) (15);
[0046] ΑC=(x A1 -x C ),(y A1 -y C ) (16);
[0047] BC=(x B1 -x C ),(y B1 -y C ) (17);
[0048]
[0049] Where θ is the angle formed by the three points ACB; the coordinates of A and B at n / 3 are (x A1 ,y A1 ),(x B1 ,y B1 ); AC and BC represent vectors.
[0050] The beneficial effects of the present invention are:
[0051] The hairiness detection method based on affinity features and path reconnection provided by the present invention adopts an extended efficient convolutional layer integrated network to enhance the feature learning ability of the network and improve the detection effect. The features obtained through training and learning can better reveal the essential structural characteristics of hairiness, help to achieve more precise hairiness segmentation and detection, reduce the workload of manual detection, and save a lot of labor. At the same time, the detection method adopted by the present invention avoids the waste of raw materials to a large extent, improves the working environment of workers, and can detect the number of hairiness more efficiently and accurately. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 It is a model architecture diagram of the hairiness detection method based on affinity features and path reconnection in Example 4 of the present invention;
[0053] Figure 2 is a structural diagram of a multi-directional strip convolution module in Embodiment 4 of the present invention;
[0054] Figure 3 This is the information entropy feature selection module diagram in Example 4 of the present invention;
[0055] Figure 4 is an affinity feature enhancement change diagram in Example 4 of the present invention;
[0056] Figure 5is an example diagram of key points of the hairiness skeleton in Example 4 of the present invention;
[0057] Figure 6 4 is a diagram of the yarn hairiness detection process in Embodiment 4 of the present invention;
[0058] Figure 7 This is a visualization effect diagram of yarn hairiness detection in Example 4 of the present invention. DETAILED DESCRIPTION
[0059] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0060] Example 1
[0061] The hairiness detection method based on affinity features and path reconnection proposed in this embodiment includes the following steps:
[0062] S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set;
[0063] S2, classify and annotate the hairiness detection data set and make label annotations;
[0064] S3, constructing a multi-directional strip convolution module and an information entropy feature selection module, using the multi-directional strip convolution module to capture the hairiness context information of the labeled annotated data set in S2 from four different directions, and using the information entropy feature selection module to enhance the original features of the hairiness context information to form an enhanced data set;
[0065] S4. Construct an affinity feature module, use the affinity feature module to learn the affinity relationship between adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers.
[0066] Example 2
[0067] The hairiness detection method based on affinity features and path reconnection proposed in this embodiment includes the following steps:
[0068] S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set;
[0069] S2, classify and annotate the hairiness detection data set and make label annotations;
[0070] S3, constructing a multi-directional strip convolution module and an information entropy feature selection module, using the multi-directional strip convolution module to capture the hairiness context information of the labeled annotated data set in S2 from four different directions, and using the information entropy feature selection module to enhance the original features of the hairiness context information to form an enhanced data set;
[0071] The multi-directional strip convolution module in S3 is as follows: the input is X∈R H×W×C , where H, W, and C represent the width, height, and number of channels of the feature map, respectively; X represents a 1×1 convolution before being input into four parallel paths. Each of the four paths contains a strip convolution in one direction, and then the output feature maps are concatenated, upsampled, and convolved to obtain the final output. Let w∈R 2k+1 is a strip convolution of size 2K+1, D=(D h ,D W ) is the direction of the strip convolution w, Z D ∈R H×W×C ' represents the result of strip convolution; strip convolution is defined as:
[0072] Z D [i,j]=(X*w) D [i,j] (1);
[0073] Where: X*w represents the convolution operation; D is the direction of the strip convolution;
[0074] The multi-directional strip convolution module takes the values of (0, 1), (1, 0), (1, 1) and (-1, 1) for strip convolutions for horizontal, vertical, left diagonal and right diagonal convolutions respectively. For the strip convolution w, k = 4 is set so that each strip convolution has 9 parameters, which is the same as the 3×3 convolution kernel;
[0075] The information entropy feature selection module in S3 is specifically as follows: The information entropy feature selection module provides additional information about the similarities and differences between regions to assist in distinguishing targets, which is expressed as:
[0076]
[0077] P i,j =f(i n ,j n ) / (H×W) (3);
[0078] Where in is the gray value of the center pixel of the nth 3×3 sliding window; jn is the average gray value of the remaining pixels in the window; Pi,j represents the probability that (in, jn) appears in the entire image; H and W represent the image size; E represents the information entropy;
[0079] The pixels in the image correspond to grayscale values of [0, 255]. Each element in the feature map represents the activation level of the convolution at a specific position in the input image. Given an input feature Fx, the tuple (i, j) obtained by the sliding window is converted into a histogram, which involves rearranging the feature map activations, which represents the size of the activation level and its distribution in the neighborhood;
[0080] The information entropy feature selection module dynamically selects features from the input features to enhance the channel features that have a greater effect on the current object segmentation. Specifically, for the input yarn hairiness image X, its depth feature F x =[f1,f2,f3,...,f c ]∈R C×H×W , obtain F through the encoder x =Encoder(X,θ x ), where the weight is θ x , feature enhancement can be expressed as:
[0081] F x '=max{S(F x ),r} (4);
[0082] Where: F x ' is the selected feature map; S is the quantization method; r is the selected ratio;
[0083] S4. Construct an affinity feature module, use the affinity feature module to learn the affinity relationship between adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers.
[0084] Example 3
[0085] The hairiness detection method based on affinity features and path reconnection proposed in this embodiment includes the following steps:
[0086] S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set;
[0087] S2, classify and annotate the hairiness detection data set and make label annotations;
[0088] S3, constructing a multi-directional strip convolution module and an information entropy feature selection module, using the multi-directional strip convolution module to capture the hairiness context information of the labeled annotated data set in S2 from four different directions, and using the information entropy feature selection module to enhance the original features of the hairiness context information to form an enhanced data set;
[0089] The multi-directional strip convolution module in S3 is as follows: the input is X∈R H×W×C , where H, W, and C represent the width, height, and number of channels of the feature map, respectively; X represents a 1×1 convolution before being input into four parallel paths. Each of the four paths contains a strip convolution in one direction, and then the output feature maps are concatenated, upsampled, and convolved to obtain the final output. Let w∈R 2k+1 is a strip convolution of size 2K+1, D=(D h ,D W ) is the direction of the strip convolution w, Z D ∈R H×W×C ' represents the result of strip convolution; strip convolution is defined as:
[0090] Z D [i,j]=(X*w) D [i,j] (1);
[0091] Where: X*w represents the convolution operation; D is the direction of the strip convolution;
[0092] The multi-directional strip convolution module takes the values of (0, 1), (1, 0), (1, 1) and (-1, 1) for strip convolutions for horizontal, vertical, left diagonal and right diagonal convolutions respectively. For the strip convolution w, k = 4 is set so that each strip convolution has 9 parameters, which is the same as the 3×3 convolution kernel;
[0093] The information entropy feature selection module in S3 is specifically as follows: The information entropy feature selection module provides additional information about the similarities and differences between regions to assist in distinguishing targets, which is expressed as:
[0094]
[0095] P i,j =f(i n ,j n ) / (H×W) (3);
[0096] Where in is the gray value of the center pixel of the nth 3×3 sliding window; jn is the average gray value of the remaining pixels in the window; Pi,j represents the probability that (in, jn) appears in the entire image; H and W represent the image size; E represents the information entropy;
[0097] The pixels in the image correspond to grayscale values of [0, 255]. Each element in the feature map represents the activation level of the convolution at a specific position in the input image. Given an input feature Fx, the tuple (i, j) obtained by the sliding window is converted into a histogram, which involves rearranging the feature map activations, which represents the size of the activation level and its distribution in the neighborhood;
[0098] The information entropy feature selection module dynamically selects features from the input features to enhance the channel features that have a greater effect on the current object segmentation. Specifically, for the input yarn hairiness image X, its depth feature F x =[f1,f2,f3,...,f c ]∈R C×H×W , obtain F through the encoder x =Encoder(X,θ x ), where the weight is θ x , feature enhancement can be expressed as:
[0099] F x '=max{S(F x ),r} (4);
[0100] Where: F x ' is the selected feature map; S is the quantization method; r is the selected ratio;
[0101] S4, construct an affinity feature module, use the affinity feature module to learn the affinity relationship of adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers;
[0102] The affinity feature module in S4 is as follows: Given a semantic label image G s =R H×W Let xl be one of the eight neighboring pixels in N(x), and N(x) be the set of the eight neighboring pixels in x. For different object sizes, the adaptive weight of each scale affinity domain of each pixel will be the label affinity domain Represented as N relative position affinity vectors corresponding to x, pixels x and x l belong to the same category, and the affinity of l The direction of is defined as 1, then the affinity of each relative position of x to l As shown in formula (5):
[0103]
[0104] In the formula, G s (x l ) represents the affinity domain of pixel x at position l in the label image;
[0105] For affinity domain learning, binary cross entropy (BCE) loss and affinity domain cosine distance (ACD) loss are used to produce a clean affinity domain, which is defined as:
[0106]
[0107] L t =L BCE (Y s ,G s )+L BCE (Y A ,G A )+λL ACD (Y A ,G A ) (9);
[0108] Where Y s (x) and G s (x) are the predicted segmentation map and label map of x respectively; the predicted It is represented as the predicted affinity vectors of N relative positions corresponding to x; |*| is the size measure; ||*|| is the size of the vector; λ b is a balanced hyperparameter; L CAD It helps the model extract better multi-scale semantic relationships for feathers of different sizes and backgrounds;
[0109] For the feature enhancement part, we first calculate the N relative position prediction affinity vectors corresponding to x. The average predicted affinity domain μ of x is used as a reference for feature selection during segmentation. The average affinity feature represents the overall state of its neighborhood semantic relationship, and its definition is shown in formula (10):
[0110]
[0111] Where N is the total number of x's neighbors; l represents the relative position; represents affinity; under the guidance of the average affinity domain μ, any relative position with an affinity greater than μ is likely to have similar semantic information to x;
[0112] Then feature enhancement is achieved through grouping and selection, for which similar category position affinity domains are represented as Its corresponding relative position x is obtained by comparing the affinity of each neighbor position A similar category to the average affinity domain μ selection position can be defined as:
[0113]
[0114] Given the selected location l, according to the segmentation feature f of x seg (x) Enhancement:
[0115]
[0116] In the formula, f seg (x l ) represents the segmentation feature corresponding to l; W M(x) represents the multi-scale adaptive weights for different S; S represents a set of scales.
[0117] The effective refinement algorithm in S4 is as follows: after obtaining the feather skeleton pixels, since the feather skeleton is a structure connected by a single pixel and eight neighborhoods, a 3×3 filter is designed to traverse the feather skeleton to identify three key points: endpoints, intersections, and cross-extension points; when performing path tracing, in order to avoid tracking errors when performing eight-neighborhood tracking in some cases, cross-extension points are set. If the endpoint is tracked, the tracking path is recorded and the tracking ends; the pixel value of the tracked pixel is set to 0, and all the endpoints in the image are tracked and the tracking path is recorded; in order to facilitate the subsequent connection of feather fragments, the tracking path is saved in reverse order in the array during the saving process. After the endpoint tracking is completed, the intersection-to-intersection tracking is performed, and then the tracking path is saved;
[0118] After obtaining the tracking results, the feather segments are connected. First, the two segments A and B with the smallest distance between the feather segments of the endpoint tracking path are found. The distance is;
[0119]
[0120] Where disAB represents the distance between A and B. As for the result of the thinning algorithm, there is an inaccurate description of the feather morphology, and the feather intersection is thinned into a short segment instead of a point. Here, d = 5 is set based on experience, and the distance constraint is used to ensure that the two feather segments are not too far apart, that is, disAB <d;
[0121] Then, the feather cross extension points are used to match and connect each feather segment, and the path points are adaptively selected by counting the number of pixel points n recorded in the array before the feather point:
[0122] 2≤n / 3≤6 (14);
[0123] Then the bending angle of the connection path is calculated, and the reconnection path with a bending angle less than 135° is rejected, as shown in equations (15) to (18), and finally the complete splicing of the feathers is achieved;
[0124] (x C ,y C )=((x A +x B ) / 2,(y A +y B ) / 2) (15);
[0125] ΑC=(x A1 -x C ),(y A1 -y C) (16);
[0126] BC=(x B1 -x C ),(y B1 -y C ) (17);
[0127]
[0128] Where θ is the angle formed by the three points ACB; the coordinates of A and B at n / 3 are (x A1 ,y A1 ),(x B1 ,y B1 ); AC and BC represent vectors.
[0129] Example 4
[0130] The hairiness detection method based on affinity features and path reconnection proposed in this embodiment includes the following steps:
[0131] S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set;
[0132] An industrial camera is selected for yarn image acquisition. Considering the fine structure of the hairiness, high-precision size detection is required. Ordinary lenses have the problem of diffuse light spots, which will cause image blur. Therefore, this device uses Shenzhen Optics' 0.7X-5.6X variable-magnification telecentric lens, which has the advantages of small distortion, no parallax and high resolution. In order to collect high-quality yarn hairiness images, before obtaining the hairiness images, it is also necessary to adjust the traction speed, light source brightness, image size, camera position, acquisition frame rate and exposure time to maximize the clarity of the collected yarn images. The data set contains 436 yarn hairiness images, of which 356 are used for model training and 80 are used for model testing;
[0133] S2, classify and annotate the hairiness detection data set and make label annotations;
[0134] In the stage of hairiness counting, 4 types of yarn images were collected for testing, and 436 yarn hairiness images were annotated, including 21S cotton yarn, 26S cotton yarn, 32S cotton yarn and 40S cotton yarn. Five sets of data were collected for each yarn specification, each set of data contained 1000 yarn hairiness images, totaling 5000 yarn hairiness images, where the actual length of each image was about 7.2cm, and the size of each image was 1024×1024 pixels. 80 images were used for testing. The yarn samples came from Shaanxi Boyu Textile Co., Ltd. The specific parameters of the yarn samples are shown in Table 1-1:
[0135] Table 1-1 Yarn sample parameters
[0136]
[0137]
[0138] S3, such as Figure 1 As shown, a multi-directional strip convolution module and an information entropy feature selection module are constructed, and the multi-directional strip convolution module is used to capture the hairiness context information of the data set annotated with labels in S2 from four different directions, and the information entropy feature selection module is used to enhance the original features of the hairiness context information to form an enhanced data set;
[0139] The multi-directional strip convolution module in S3 is as follows: the input is X∈R H×W×C , where H, W and C represent the width, height and number of channels of the feature map respectively; X represents a 1×1 convolution before being input into four parallel paths. Each of the four paths contains a strip convolution in one direction, and then the output feature maps are concatenated, upsampled and convolved to obtain the final output, such as Figure 2 As shown, let w∈R 2k+1 is a strip convolution of size 2K+1, D=(D h ,D W ) is the direction of the strip convolution w, Z D ∈R H×W×C ' represents the result of strip convolution; strip convolution is defined as:
[0140] Z D [i,j]=(X*w) D [i,j] (1);
[0141] Where: X*w represents the convolution operation; D is the direction of the strip convolution;
[0142] The multi-directional strip convolution module takes the values of (0, 1), (1, 0), (1, 1) and (-1, 1) for strip convolutions for horizontal, vertical, left diagonal and right diagonal convolutions respectively. For the strip convolution w, k = 4 is set so that each strip convolution has 9 parameters, which is the same as the 3×3 convolution kernel;
[0143] The information entropy feature selection module in S3 is specifically as follows: The information entropy feature selection module provides additional information about the similarities and differences between regions to assist in distinguishing targets, which is expressed as:
[0144]
[0145] P i,j =f(i n ,j n) / (H×W) (3);
[0146] Where in is the gray value of the center pixel of the nth 3×3 sliding window; jn is the average gray value of the remaining pixels in the window; Pi,j represents the probability that (in, jn) appears in the entire image; H and W represent the image size; E represents the information entropy;
[0147] The pixels in the image correspond to grayscale values of [0, 255], and each element in the feature map represents the activation level of the convolution at a specific location in the input image, such as Figure 3 As shown, given an input feature Fx, the tuple (i, j) obtained by the sliding window is converted into a histogram, which involves rearranging the feature map activations, which represents the size of the activation level and the distribution in the neighborhood;
[0148] The information entropy feature selection module dynamically selects features from the input features to enhance the channel features that have a greater effect on the current object segmentation. Specifically, for the input yarn hairiness image X, its depth feature F x =[f1,f2,f3,...,f c ]∈R C×H×W , obtain F through the encoder x =Encoder(X,θ x ), where the weight is θ x , feature enhancement can be expressed as:
[0149]
[0150] Where: F x ' is the selected feature map; S is the quantization method; r is the selected ratio;
[0151] S4, construct an affinity feature module, use the affinity feature module to learn the affinity relationship of adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers, such as Figure 4 As shown;
[0152] The affinity feature module in S4 is as follows: Given a semantic label image G s =R H×W Let xl be one of the eight neighboring pixels in N(x), and N(x) be the set of the eight neighboring pixels in x. For different object sizes, the adaptive weight of each scale affinity domain of each pixel will be the label affinity domain Represented as N relative position affinity vectors corresponding to x, pixels x and x l belong to the same category, and the affinity of l The direction of is defined as 1, then the affinity of each relative position of x to l As shown in formula (5):
[0153]
[0154] In the formula, G s (x l ) represents the affinity domain of pixel x at position l in the label image;
[0155] For affinity domain learning, binary cross entropy (BCE) loss and affinity domain cosine distance (ACD) loss are used to produce a clean affinity domain, which is defined as:
[0156]
[0157] Where Y s (x) and G s (x) are the predicted segmentation map and label map of x respectively; the predicted It is represented as the predicted affinity vectors of N relative positions corresponding to x; |*| is the size measure; ||*|| is the size of the vector; λ b is a balanced hyperparameter; L CAD It helps the model extract better multi-scale semantic relationships for feathers of different sizes and backgrounds;
[0158] For the feature enhancement part, we first calculate the N relative position prediction affinity vectors corresponding to x. The average predicted affinity domain μ of x is used as a reference for feature selection during segmentation. The average affinity feature represents the overall state of its neighborhood semantic relationship, and its definition is shown in formula (10):
[0159]
[0160] Where N is the total number of x's neighbors; l represents the relative position; represents affinity; under the guidance of the average affinity domain μ, any relative position with an affinity greater than μ is likely to have similar semantic information to x;
[0161] Then feature enhancement is achieved through grouping and selection, for which similar category position affinity domains are represented as Its corresponding relative position x is obtained by comparing the affinity of each neighbor position A similar category to the average affinity domain μ selection position can be defined as:
[0162]
[0163] Given the selected location l, according to the segmentation feature f of x seg (x) Enhancement:
[0164]
[0165] In the formula, f seg (x l ) represents the segmentation feature corresponding to l; W M (x) represents the multi-scale adaptive weights of different S; S represents a set of scales;
[0166] The effective refinement algorithm in S4 is as follows: After obtaining the feather skeleton pixels, since the feather skeleton is a structure connected by a single pixel and eight neighborhoods, a 3×3 filter is designed to traverse the feather skeleton to identify three key points: endpoints, intersections, and intersection extension points, such as Figure 5 As shown in the figure; when performing path tracing, in order to avoid tracking errors when performing eight-neighborhood tracking in some cases, the intersection extension point is set. If the endpoint is tracked, the tracking path is recorded and the tracking ends; the pixel value of the tracked pixel is set to 0, and all the endpoints in the image are tracked and the tracking path is recorded; in order to facilitate the subsequent connection of feather segments, the tracking path is saved in the array in reverse order during the saving process. After the endpoint tracking is completed, the intersection is tracked to the intersection, and then the tracking path is saved;
[0167] After obtaining the tracking results, the feather segments are connected. First, the two segments A and B with the smallest distance between the feather segments of the endpoint tracking path are found. The distance is;
[0168]
[0169] Where disAB represents the distance between A and B. As for the result of the thinning algorithm, there is an inaccurate description of the feather morphology, and the feather intersection is thinned into a short segment instead of a point. Here, d = 5 is set based on experience, and the distance constraint is used to ensure that the two feather segments are not too far apart, that is, disAB <d;
[0170] Then, the feather cross extension points are used to match and connect each feather segment, and the path points are adaptively selected by counting the number of pixel points n recorded in the array before the feather point:
[0171] 2≤n / 3≤6 (14);
[0172] Then the bending angle of the connection path is calculated, and the reconnection path with a bending angle less than 135° is rejected, as shown in equations (15) to (18), and finally the complete splicing of the feathers is achieved;
[0173] (x C ,y C )=((x A +x B ) / 2,(y A +yB ) / 2) (15);
[0174] ΑC=(x A1 -x C ),(y A1 -y C ) (16);
[0175] BC=(x B1 -x C ),(y B1 -y C ) (17);
[0176]
[0177] Where θ is the angle formed by the three points ACB; the coordinates of A and B at n / 3 are (xA1, yA1) and (xB1, yB1) respectively; AC and BC represent vectors;
[0178] When counting the number of yarn hairiness, Figure 6 As shown, firstly, semantic segmentation is performed on the acquired yarn hairiness image to obtain a hairiness binary image, then the hairiness binary image is refined to obtain a hairiness skeleton image, and finally, each cross hairiness and independent hairiness are distinguished in the hairiness skeleton image by using the path reconnection method;
[0179] In order to verify the accuracy, four feather images are selected for display. Figure 7 As shown in the figure, the first line is the hairiness binary image, and the second line is the hairiness detection result. According to the hairiness detection result figure, it can be seen that this method can effectively detect cross hairiness and independent hairiness. In addition, the Figure 7 The number of hairiness of different lengths in the four images in FIG. 1 is shown in FIG. 1 . According to the comparison results, it can be seen that the method of the present invention can more accurately count the number of hairiness of different lengths.
Claims
1. A method for hairiness detection based on affinity features and path reconnection, characterized in that: The following steps are involved: S1. Use Basler acA2500-60uc industrial camera to collect yarn images, filter and sort all images, and generate a hairiness detection data set; S2, classify and annotate the hairiness detection data set and make label annotations; S3, constructing a multi-directional strip convolution module and an information entropy feature selection module, using the multi-directional strip convolution module to capture the hairiness context information of the labeled annotated data set in S2 from four different directions, and using the information entropy feature selection module to enhance the original features of the hairiness context information to form an enhanced data set; S4. Construct an affinity feature module, use the affinity feature module to learn the affinity relationship between adjacent pixels of the enhanced data set in S3, use the affinity information as geometric and contextual guidance to enhance the segmentation features, use an effective refinement algorithm to achieve accurate segmentation of the feathers, and then use the path reconnection method to achieve accurate statistics of the number of feathers.
2. The hairiness detection method based on affinity features and path reconnection according to claim 1, characterized in that: The multi-directional strip convolution module described in S3 is specifically: the input is X∈R H×W×C , where H, W, and C represent the width, height, and number of channels of the feature map, respectively; X represents a 1×1 convolution before being input into four parallel paths. Each of the four paths contains a strip convolution in one direction, and then the output feature maps are concatenated, upsampled, and convolved to obtain the final output. Let w∈R 2k+1 is a strip convolution of size 2K+1, D=(D h ,D W ) is the direction of the strip convolution w, Z D ∈R H×W×C ' represents the result of strip convolution; strip convolution is defined as: Z D [i,j]=(X*w) D [i,j] (1); Where: X*w represents the convolution operation; D is the direction of the strip convolution; The multi-directional strip convolution module takes the values of (0, 1), (1, 0), (1, 1) and (-1, 1) for strip convolutions for horizontal, vertical, left diagonal and right diagonal convolutions respectively. For the strip convolution w, k = 4 is set so that each strip convolution has 9 parameters, which is the same as the 3×3 convolution kernel.
3. The hairiness detection method based on affinity features and path reconnection according to claim 1, characterized in that: The information entropy feature selection module in S3 is specifically: the information entropy feature selection module provides additional information about the similarities and differences between regions to assist in distinguishing targets, which is expressed as: P i,j =f(i n ,j n ) / (H×W) (3); Where in is the gray value of the center pixel of the nth 3×3 sliding window; jn is the average gray value of the remaining pixels in the window; Pi,j represents the probability that (in, jn) appears in the entire image; H and W represent the image size; E represents the information entropy; The pixels in the image correspond to grayscale values of [0, 255]. Each element in the feature map represents the activation level of the convolution at a specific position in the input image. Given an input feature Fx, the tuple (i, j) obtained by the sliding window is converted into a histogram, which involves rearranging the feature map activations, which represents the size of the activation level and its distribution in the neighborhood; The information entropy feature selection module dynamically selects features from the input features to enhance the channel features that have a greater effect on the current object segmentation. Specifically, for the input yarn hairiness image X, its depth feature F x =[f1,f2,f3,...,f c ]∈R C×H×W , obtain F through the encoder x =Encoder(X,θ x ), where the weight is θ x , feature enhancement can be expressed as: F x '=max{S(F x ),r} (4); Where: F x ' is the selected feature map; S is the quantization method; r is the selected ratio.
4. The hairiness detection method based on affinity features and path reconnection according to claim 1, characterized in that: The affinity feature module described in S4 is specifically: given a semantic label image G s =R H×W Let xl be one of the eight neighboring pixels in N(x), and N(x) be the set of the eight neighboring pixels in x. For different object sizes, the adaptive weight of each scale affinity domain of each pixel will be the label affinity domain Represented as N relative position affinity vectors corresponding to x, pixels x and x l belong to the same category, and the affinity of l The direction of is defined as 1, then the affinity of each relative position of x to l As shown in formula (5): In the formula, G s (x l ) represents the affinity domain of pixel x at position l in the label image; For affinity domain learning, binary cross entropy (BCE) loss and affinity domain cosine distance (ACD) loss are used to produce a clean affinity domain, which is defined as: Where Y s (x) and G s (x) are the predicted segmentation map and label map of x respectively; the predicted It is represented as the predicted affinity vectors of N relative positions corresponding to x; |*| is the size measure; ||*|| is the size of the vector; λ b is a balanced hyperparameter; L CAD It helps the model extract better multi-scale semantic relationships for feathers of different sizes and backgrounds; For the feature enhancement part, we first calculate the N relative position prediction affinity vectors corresponding to x. The average predicted affinity domain μ of x is used as a reference for feature selection during segmentation. The average affinity feature represents the overall state of its neighborhood semantic relationship, and its definition is shown in formula (10): Where N is the total number of x's neighbors; l represents the relative position; represents affinity; under the guidance of the average affinity domain μ, any relative position with an affinity greater than μ is likely to have similar semantic information to x; Then feature enhancement is achieved through grouping and selection, for which similar category position affinity domains are represented as Its corresponding relative position x is obtained by comparing the affinity of each neighbor position A similar category to the average affinity domain μ selection position can be defined as: Given the selected location l, according to the segmentation feature f of x seg (x) Enhancement: In the formula, f seg (x l ) represents the segmentation feature corresponding to l; W M (x) represents the multi-scale adaptive weights for different S; S represents a set of scales.
5. The hairiness detection method based on affinity features and path reconnection according to claim 1, characterized in that: The effective refinement algorithm described in S4 is specifically as follows: after obtaining the feather skeleton pixels, since the feather skeleton is a structure connected by a single pixel and an eight-neighborhood, a 3×3 filter is designed to traverse the feather skeleton to identify three key points: endpoints, intersections, and cross-extension points; when performing path tracing, in order to avoid tracking errors when performing eight-neighborhood tracking in certain situations, cross-extension points are set. If the endpoint is tracked, the tracking path is recorded and the tracking ends; the pixel value of the tracked pixel point is set to 0, and all the endpoints in the image are tracked and the tracking path is recorded; in order to facilitate the subsequent connection of feather fragments, the tracking path is saved in an array in reverse order during the saving process, and after the endpoint tracking is completed, the intersection-to-intersection tracking is performed, and then the tracking path is saved; After obtaining the tracking results, the feather segments are connected. First, the two segments A and B with the smallest distance between the feather segments of the endpoint tracking path are found. The distance is; Where disAB represents the distance between A and B. As for the result of the thinning algorithm, there is an inaccurate description of the feather morphology, and the feather intersection is thinned into a short segment instead of a point. Here, d = 5 is set based on experience, and the distance constraint is used to ensure that the two feather segments are not too far apart, that is, disAB <d; Then, the feather cross extension points are used to match and connect each feather segment, and the path points are adaptively selected by counting the number of pixel points n recorded in the array before the feather point: 2≤n / 3≤6 (14); Then the bending angle of the connection path is calculated, and the reconnection path with a bending angle less than 135° is rejected, as shown in equations (15) to (18), and finally the complete splicing of the feathers is achieved; (x C ,and C )=((x A +x B ) / 2,(and A +y B ) / 2) (15); ΑC=(x A1 -x C ),(the A1 -the C ) (16)? BC=(x B1 -x C ),(y B1 -y C ) (17); Where θ is the angle formed by the three points ACB; the coordinates of A and B at n / 3 are (x A1 ,y A1 ),(x B1 ,y B1 ); AC and BC represent vectors.
