Cotton foreign fiber detection method and cotton foreign fiber removal system based on multi-mode classification algorithm
Through the multi-mode classification algorithm, the cotton opposite-sex fiber detection method is solved, and the existing technology cannot be adjusted adaptively, achieving efficient and accurate detection and removal of cotton opposite-sex fibers is achieved, thereby reducing labor costs.
Patent Information
- Application Number
- CN202510461362.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-14
- Publication Date
- 2025-07-11
AI Technical Summary
The existing machine vision system cannot adaptively adjust parameters in cotton opposite-sex fiber detection, resulting in unsatisfactory detection results, inefficient production efficiency, and increased labor costs.
The cotton opposite-sex fiber detection method based on the multi-mode classification algorithm is adopted. Images are collected through the linear array CCD camera, light correction, noise processing and image enhancement are performed, multi-modal features are extracted, and the opposite-sex fiber is determined using the statistical mode classification algorithm, and the high-pressure air valve removal is triggered.
It improves detection accuracy, reduces the use of high-cost spectral equipment, adapts to changing production environments, and has strong industrial application prospects.
Smart Images

Figure CN120298802A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of agricultural equipment and machine vision, and particularly to a method for detecting foreign fibers in cotton and a removal system based on a multi-mode classification algorithm. Background Art
[0002] In recent years, machine vision technology has been widely applied in the fields of agriculture and food processing. Through image processing and pattern recognition technologies, machine vision systems can achieve automatic detection of foreign fibers in cotton. However, existing machine vision systems often cannot adaptively adjust parameters when dealing with different types of cotton and impurities, resulting in unsatisfactory detection effects. Therefore, there is an urgent need for an adaptive machine vision system to improve the detection accuracy and efficiency of foreign fibers in cotton. The invention patent with the Chinese patent publication number CN116698870A discloses a "defect detection device and method for machine-picked seed cotton based on deep learning". The hardware facilities of this patent include a frame, a feeding component, a feeding component, a detection component, a blanking component, and a control system, etc. Combining deep learning technology, through image acquisition and light transmittance detection, it realizes the batch detection of defects in machine-picked seed cotton. The implementation method includes steps such as raw material feeding, image acquisition, light transmittance detection, spacing adjustment, and compaction detection. This patent mentions that in order to ensure the accuracy of image recognition, machine-picked seed cotton needs to be quantitatively and separately transported. This requirement may lead to low production efficiency in actual applications and is difficult to achieve large-scale detection of seed cotton. Secondly, during the use of the equipment, it requires continuous debugging by staff and is difficult to achieve autonomous learning and debugging. This increases labor costs and may lead to detection errors caused by improper operation. Summary of the Invention
[0003] Object of the Invention: The object of the present invention is to address the above problems and propose a method for detecting foreign fibers in cotton and a removal system based on a multi-mode classification algorithm
[0004] Technical Solution: To achieve the above object, the present invention adopts the following technical solutions:
[0005] The first aspect of the present invention provides a method for detecting foreign fibers in cotton based on a multi-mode classification algorithm, including the following steps:
[0006] S1: Collect cotton flow images through a line array CCD camera and configure a uniform white light source;
[0007] S2: Preprocess the images, including illumination correction based on histogram equalization, median filtering for noise reduction, and contrast enhancement by contrast-limited adaptive histogram equalization;
[0008] S3: Extract multi-modal features from the preprocessed image, including: grayscale histogram statistical features, calculating the mean, variance, and cumulative difference value of the grayscale distribution; RGB color space threshold features, locating the foreign fiber area through multi-channel threshold segmentation; gray-level co-occurrence matrix texture features, extracting contrast, correlation, and energy parameters;
[0009] S4: Use a statistical pattern classification algorithm to classify the multi-modal feature vectors, and determine whether there are foreign fibers in the image through a classifier;
[0010] S5: If foreign fibers are detected, trigger the high-pressure air valve to remove them.
[0011] Further, in step S2, the histogram equalization method is used to adjust the uneven illumination. Specifically: calculate the grayscale histogram of the image, determine the number of pixels at each grayscale level, and map the grayscale levels to new grayscale values through the cumulative distribution function. The basic formula for histogram equalization is:
[0012]
[0013] In the formula, H(x) is the histogram of the original image, and H’(x) is the histogram after equalization.
[0014] Further, in S2, the median filtering algorithm is used to suppress the noise effect by replacing the value of each pixel with the median of the pixel values in its neighborhood. Specifically: for each pixel, first determine a neighborhood window, then calculate the median of all pixel values in this window, and assign this median to the central pixel. The formula for median filtering is:
[0015] f′(x,y)=median{f(i,j)|(i,j)∈N(x,y)}
[0016] f'(x,y) is the pixel value of the output image at (x,y), f(i,j) is the pixel value of the input image at (x,y), and N(x,y) is the neighborhood of the pixel (x,y). Usually, this neighborhood is a square or circular window, such as a 3×3 or 5×5 sized area. median{...} is the operation of taking the middle value in the set. If the number of pixel values in the neighborhood is odd, the median is the middle number after sorting; if it is even, the median is usually taken as the average of the two middle numbers after sorting.
[0017] Further, the grayscale histogram statistical features in S3 are obtained by mapping each pixel value in the image to the corresponding grayscale level and counting the number of pixels at each grayscale level, resulting in a histogram representing the grayscale distribution of the image. The horizontal axis of this histogram represents the grayscale level, and the vertical axis represents the corresponding number of pixels. The grayscale feature statistical histogram of the image is a 1-D discrete function:
[0018] H(k) = n k / n k = 0, 1, 2, 3..., L - 1
[0019] Wherein, the feature value is represented by k, the number of available numerical values is represented by L, and n k is the number of pixels with a feature value of k in the image, and the total number of image pixels is n
[0020] Judgment is carried out by combining the accumulation of the difference in the number of pixels at each gray level:
[0021]
[0022] Wherein, n i is the number of pixels with a feature value of i in the equalized histogram, and n (avg)i is the average number of pixels with a feature value of i in the equalized histogram. D is the accumulation of the difference in the number of these two types of pixels at each gray level. After calculating D, comparison operations are carried out by combining the difference in the number of 256 - level gray pixels to judge the cotton image. The gray - level distribution of normal cotton can be reflected by the equalized histogram. At this time, after calculating the gray - level histogram, comparison is carried out. If the image is normal at this time, its gray level needs to conform to the distribution in the equalized histogram. On the contrary, if the difference between the two is relatively significant, it indicates that it is abnormal. Further, in step S4, N features are extracted, the image types are divided into m categories, and combined with the features, assumptions are made about the vectors with representative patterns, and it is necessary to judge neural networks, functions, etc. Types such as linear discriminant functions are relatively common types. The recognition pattern is considered as a feature vector of an input sample X, specifically as follows:
[0023] X = [x1, x2,..., x n T
[0024] X is a feature vector, representing the features of a sample in an N - dimensional space. x i is the i - th feature of the feature vector, and the pattern categories are ω1, ω2,..., ω n represent possible classification labels. The recognition activity is to judge X to see if it belongs to the corresponding pattern category.
[0025] Further, in step S3, the gray - level value of the pixel point in the RGB color - space threshold feature extraction is specifically represented by I, and the component values of different colors of the pixel points in the color image are represented by G, R, and B. For the pseudo - gray - level image, edge - detection activities are carried out, and the corresponding results are as follows:
[0026]
[0027] Wherein, GRAD(f R ), GRAD(f G ), GRAD(f B ) is the edge intensity obtained from the edge detection of the R, G, B pseudo-gray scale image; f R , f G , f B are the R, G, B components; g is the structural element; GRAD(f) represents the comprehensively obtained edge intensity.
[0028] Further, in the step S3, the texture features are extracted by the gray-level co-occurrence matrix (GLCM) method. The calculation formula of the GLCM is:
[0029]
[0030] where δ is the indicator function, Ω is the image region, and (Δx, Δy) is the relative position.
[0031] The second aspect of the present invention provides a cotton foreign fiber removal system based on a multi-mode classification algorithm, including an opening cotton mechanism, a cotton conveying motor and pipeline, an image acquisition device, a plurality of LED light sources, a computer, a high-pressure air valve, and a waste discharge pipeline. After the cotton undergoes strong dust removal treatment, its structure becomes more fluffy, and then it is guided to the feeding port of the system through the main air duct. Under the action of the conveying system and the uniform dispersion mechanism, the cotton will be effectively dispersed, and its form changes from fluffy to snowflake-like. Under the combined action of the main air duct and gravity, the cotton continuously falls. When the cotton is within the field of view of the camera or inside the glass cavity, the camera will scan the cotton flow. Two cameras are distributed on both sides of the channel, and image data collection operations are carried out simultaneously to avoid the attachment of foreign fibers to the surface of the cotton layer, thereby causing the problem of missed detection. With the support of the image acquisition card, the acquired images will be combined with the corresponding data format and transmitted to the computer. The computer will perform real-time processing based on the feature differences of the image data to identify the specific positions of the foreign fibers in the cotton. After successfully identifying the foreign fibers, the control system will receive their position signals and issue corresponding instructions to transmit a cleaning signal to the cleaning system. When the cotton reaches the waste discharge port, the system will start the solenoid valve according to the received signal and, combined with the action of the high-pressure air flow, blow away the foreign fibers, thereby effectively separating the cotton from the foreign fibers.
[0032] Beneficial effects: Compared with the prior art, the present invention has the following advantages: The present invention adopts a multi-mode classification algorithm to balance speed and accuracy, effectively improves the detection accuracy rate, reduces the use of high-cost spectral equipment, and at the same time, the adaptive parameter adjustment mechanism of the present invention adapts to the changing production environment and has strong industrial application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 is a schematic diagram of the detection process in the embodiment of the present invention;
[0034] Figure 2 It is a schematic diagram in an embodiment of the present invention;
[0035] Figure 3 It is a schematic diagram of the RGB three-dimensional color space;
[0036] Figure 4 It is a schematic diagram of a model in the cotton color space. Detailed implementation manners
[0037] The following further clarifies the present invention in conjunction with the accompanying drawings and specific embodiments. These embodiments are implemented on the premise of the technical solution of the present invention. It should be understood that these embodiments are only used to illustrate the present invention and not to limit the scope of the present invention.
[0038] Embodiment 1
[0039] A method for detecting foreign fibers in cotton based on a multi-mode classification algorithm in this embodiment is as Figure 1-2 shown.
[0040] First, the system collects cotton images through a camera and performs preprocessing operations such as light adjustment, noise processing, and image enhancement to improve the image quality. Then, feature information is extracted from the preprocessed image, and statistical methods are used for pattern classification to determine whether there are foreign fibers in the image. According to the classification result, the system will output a normal signal or activate an actuator, such as the spray valve working, to separate the foreign fibers from the cotton. The whole process ensures the quality detection of cotton and the effective removal of foreign fibers; it specifically includes the following steps:
[0041] 1. Perform pattern recognition and classification. Based on statistical methods, input digital images, remove interference and differences, perform preprocessing, transform the original signal into a form that can be operated by a computer, and perform feature extraction.
[0042] 2. According to the classification algorithm of cotton image data, extract and compare the image features to achieve effective classification of cotton images.
[0043] 3. Edge detection based on mathematical morphology, use morphological operations to extract the edge information of the image, and enhance the image features.
[0044] 4. Preprocess the cotton image, including uneven light adjustment, image enhancement, noise processing, and image segmentation.
[0045] 5. Extract feature information from the preprocessed image and perform pattern classification using statistical methods. By analyzing the features, determine whether the image belongs to normal cotton or contains foreign fibers.
[0046] 6. If foreign fibers are detected, activate the solenoid valve and use high-pressure air flow to remove the foreign fibers.
[0047] In step 1, using the statistical pattern recognition method, it can be classified as a classification problem. If N features have been extracted and the types of images can be divided into m categories. At this time, combining the features to determine the category corresponding to the pixel. Generally, the recognition pattern can be regarded as the X vector in the N-dimensional space, specifically as follows:
[0048] X = [x1, x2,..., x n T
[0049] The pattern categories are ω1, ω2,..., ω n , and the recognition activity is to judge X to see if it belongs to the corresponding pattern category. In this process, it is required that the value of the number of features N is as small as possible and can effectively judge the classification.
[0050] In step 2, through the classification algorithm of cotton data, that is, the normal cotton gray distribution can be represented by the equalized histogram. At this time, after calculating the gray histogram and making a comparison, the normality of the image can be judged. If the image is normal at this time, its gray level needs to conform to the distribution in the equalized histogram. Conversely, if the difference between the two is significant, it indicates that it is abnormal. In this embodiment, the comparison operation is directly carried out by taking the difference of the number of 256-level gray pixels. After improving the algorithm, it can better distinguish foreign fibers in cotton. The gray feature statistical histogram of the image is a 1-D discrete function
[0051] H(k) = n k / n k = 0, 1, 2, 3..., L - 1
[0052] In the above formula, the feature value is represented by k, the number of available values is represented by L, and n k is the number of pixels with the feature value of k in the image, and the total number of image pixels is n. After obtaining the statistical histogram, the feature matching operation of the image can be completed by combining the calculation of the histogram distance. This patent combines the accumulation of the difference in the number of pixels at each gray level to make a judgment.
[0053]
[0054] n i is the number of pixels with the feature value of i in the equalized histogram, n (avg)i is the average number of pixels with the feature value of i in the equalized histogram. D is the accumulation of the difference in the number of these two types of pixels at each gray level. After calculating D, the cotton image is judged by combining the value. As described above, the algorithm has a relatively good effect when distinguishing foreign fibers in cotton. Especially in terms of random noise, the robustness of the algorithm is extremely significant.
[0055] In step 3, the binary image is used as a set, and the exploration operation is performed through the structuring element, which is the basic principle of mathematical morphology. Among them, the most basic concept is the structuring element. By constructing different structuring elements, various image analysis tasks can be completed. Erosion and dilation operations are the basis for processing images. Since they are not inverse operations, they can be cascaded and used together.
[0056] Definition of dilation:
[0057] Definition of erosion: fΘg(x,y) = min (i,j) {f(x + i, y + j) + g(i, j)}
[0058] At this time, the dilation operation is applied, and the specific detection operator is as follows:
[0059]
[0060] If the erosion operation is applied, the specific detection operator is as follows:
[0061] G e = f(x, y) - f(x, y)Θg(i, j)
[0062] Combined with the morphological gradient to complete the corresponding detection work, and the operator at this time is:
[0063]
[0064] In this embodiment, the color images are stored in the RGB format. Represented by combining the three color channels, it provides relatively more information compared to a single color channel and can locate edge features at the position that best reflects the image structure.
[0065] The gray value of a pixel is specifically represented by I, and the component values of different colors of a pixel in a color image can be represented by G, R, and B. Similar to the edge detection operator for grayscale images, edge detection activities need to be carried out for the pseudo-grayscale image, and the corresponding results are as follows:
[0066]
[0067] In the formula, GRAD(f R ), GRAD(f G ), GRAD(f B ) are the edge intensities obtained from the edge detection of the R, G, and B pseudo-grayscale images; f R , f G , f B are the R, G, and B components; g is the structuring element.
[0068] Therefore, when determining the comprehensive edge operator previously, the average value of three channels was selected, which did not match the characteristics of the cotton foreign fiber image. Combining the arithmetic square root of the sum of numerical squares as the improved operator solved the problem that the previous operator could not detect high-resolution color images well. The specific improved expression is as follows:
[0069]
[0070] In the above formula, GRAD(f) represents the comprehensively obtained edge intensity.
[0071] In step 4, when preprocessing the cotton image, the illuminance needs to be adjusted first. Since the reflection of light constitutes the specific signal of the collected image, and its illuminance on cotton is uneven. When the intensity is too high, it appears brighter, and vice versa, it appears darker. In this regard, misjudgment often occurs during the image processing work, resulting in a higher waste cotton rate. Therefore, the homomorphic filtering method is used here to correct the cotton image. Specifically, the following model is formed after light reflection:
[0072] f(x,y) = r(x,y) * i(x,y)
[0073] In the formula, i(x,y) represents the illuminance component, and its spectrum is distributed in the low-frequency range, while r(x,y) represents the reflection component, which shows the details of the image and its spectrum is mostly distributed in the high-frequency band. The logarithmic operation is performed on the image to transform the product model into an addition model. After taking the logarithm, the distribution regions of the illuminance and the reflection component do not change, so the two components can be distinguished. After the distinction, the adjustment work can be carried out. To solve the problem of uneven illuminance, it is usually done by weakening the illuminance component and enhancing the reflection component. The related approach is as follows: First, divide the image into image blocks, specifically 32*32, select the minimum illuminance value as the specific illuminance, then expand the background illuminance matrix to make its size equal to the size of the original image, and then remove the background illuminance from the original image to achieve the correction goal.
[0074] When enhancing the cotton foreign fiber image, the frequency domain enhancement method is mainly used, which can be expressed as follows in combination with mathematical formulas:
[0075] g(x,y) = T[f(x,y)]
[0076] For the above formula, the images before and after enhancement are represented by g(x,y) and f(x,y) respectively, and the function transformation is represented by T. By combining the image transformation method, an image in the image space is transformed into other spaces in a relevant form, then processed in a corresponding way, and then transformed back to the original image.
[0077] In the processing of the noise in cotton images, there are many reasons for the formation of noise. In terms of the image signal, a black-and-white image can be considered as f(x,y), that is, the brightness distribution. At this time, the interference of the noise can be expressed in combination with n(x,y). In terms of the distribution of the noise, it can be described in combination with statistical characteristics. E{n 2 (x,y)} represents the magnitude of the total power of the noise, and E{(n(x,y)-E{n(x,y)} 2 )} is the magnitude of the alternating current power of the noise, and [E{n(x,y)}] 2 is the magnitude of the direct current power of the noise.
[0078] In this embodiment, the median filtering method is used, that is, in combination with neighborhood operations, the pixels are sorted according to the gray level, and then the median value is selected, and then the output of the pixel value is completed. If the conditions are appropriate, problems such as image detail blur caused by mean filtering and the like will be overcome, and median filtering is extremely effective in terms of image scanning noise and pulse interference. As a typical in low-pass filters, median filtering can achieve the suppression of pulse noise, and in addition, spike interference noise will be completely removed. The following belongs to a standard definition formula:
[0079] y k =mid{x K-N , x K-N+1 ,..., x K+N-1 , x K+N}
[0080] Among them, mid represents taking the median value. For two-dimensional median filtering, the size design, window shape, etc. will greatly affect the filtering effect, and mostly square, linear, etc. are used. To achieve the image processing objectives of this patent, not only noise elimination is required, but in addition, the gray values of the cotton image and foreign fibers need to be increased in order to carry out subsequent segmentation processing operations.
[0081] Because the image based on the threshold has the fastest segmentation speed, so when the machine vision system has relatively high requirements for speed, this method can often be used. The activity of processing cotton foreign fiber images described in this patent belongs to the above situation. The following will specifically introduce the threshold segmentation method.
[0082] Based on the trichromatic theory, in terms of color perception, three types of visible light stimulate the relevant cells in the retina, and then the purpose of perceiving colors is achieved. When the wavelengths of red, green, and blue light reach 630nm, 530nm, and 450nm respectively, the stimulation will reach the maximum value. Combining the comparison of the light source intensity, the eyes can distinguish the colors of different lights. This theory combines the above three primary colors to display colors on the monitor, which is the RGB color model.
[0083] Combined with Figure 3-4 It can be found that after definition, a corresponding regular hexahedron is formed. Describing the above model, that is, by mixing the three primary colors to form a new color, which is the additive color model. For this model, any color can be represented by combining the color coordinates (r, g, b). The addition of red and blue forms the vertex magenta with the triple (255, 0, 255), and the sum of the three-color vertices can represent white (255, 255, 255). At any position on the main diagonal of black and white, the gray level can be represented. For any point on the diagonal, it is a mixture of equal amounts of primary colors, and the medium-brightness gray in black and white can be represented by (128, 128, 128).
[0084] When describing any color, three quantities are required. Any combination of two colors cannot form the third color, but can form a set of bases, that is, the three primary colors. After mixing blue, red, etc., all colors can be produced. Therefore, in this space, color C can be expressed as follows:
[0085] C = rR + gG + bB
[0086] The above is the normalized model. For the system described in the paper, for the three primary colors, the camera will use eight-bit quantization, including a total of 256 levels, ranging from 0 to 255, corresponding to 0 to 1 respectively.
[0087] If it is natural light at this time, the effect is basically white, and the gray value of cotton fiber is still the same, so (255, 255, 255) is its RGB value, or within a certain range close to it. In the three-dimensional color space, such image data has relatively close three-color values, and the gray value is on the main diagonal that forms the same angle with the three coordinate axes. When acquiring the image, after cotton receives light, the light will be reflected, and the light will be collected at this time. When the angles are different, the reflection intensity of cotton is naturally different, and the gray level will change accordingly. Combined with the color space, there is a certain range of change on the main diagonal gray axis. Due to the influence of many factors, the gray-scale image is incomplete, that is, the values of the three components are not exactly the same. In terms of the space, the distribution of cotton image points is not only on the gray axis, but also in the surrounding range, equivalent to the gray values of adjacent pixel points.
[0088] Select qualified cotton, collect images in large quantities, and realize that in the three-dimensional color space, the shape of its image is club-shaped. Its main body is the gray axis consistent with the included angle of the coordinate axes. Due to the uneven distribution of reflected light in the cotton, at this time, gray exists as the central color and is relatively elongated. The above are the model characteristics of cotton in the three-dimensional color space. If more qualified cotton is photographed, the threshold can be determined. It can be determined that good cotton is specifically distributed at the positions of the club-shaped distribution, and the rest are often foreign fibers that need to be separated.
[0089] In the three-dimensional color space, the distribution of the following types of foreign fibers does not overlap with the range of high-quality cotton.
[0090] (1) Small particles, with a relatively dark color, close to black. In terms of the image, its brightness is extremely low, and compared with the lower end of the gray axis, its gray value is also relatively small.
[0091] (2) Plastic fibers, with a relatively light color and easy to reflect light. In terms of the image, the brightness of such foreign fibers is extremely high, and the position of the gray value is often at the upper end of the gray axis.
[0092] (3) The color of the cotton is impure, which is not the same as white, making the image often show a certain color, and in space, it is specifically reflected as follows, that is, it deviates from the relevant coordinate axes.
[0093] The gray value of high-quality cotton is often in the upper-middle part, while those with a smaller gray value are at the lower end. If the brightness is too high, it is at the highest end. If the cotton is impure, it will deviate towards the color axis at this time, and the distance from the gray axis is relatively far. Therefore, by combining the threshold of standard cotton existing in this space, the distinction between foreign fibers and cotton can be realized. Furthermore, it can be considered that such a cotton characteristic model basically meets the recognition requirements.
[0094] Three independent basic planes form a color image, which can be decomposed and placed on three planes. For example, the RGB space model of standard cotton can be projected onto the three planes of RG, GB, and BR to achieve the conversion from the space model to a two-dimensional image. The key idea of the system algorithm is that when identifying, judging, and converting foreign fibers and cotton, the three-dimensional color model is respectively under the R-G, G-B, and B-R coordinates to complete the judgment activity. It has extremely significant advantages. First, it can achieve the conversion from three-dimensional space to two-dimensional plane, making the concept more intuitive. Second, the image processing algorithm designed on the two-dimensional plane can also be more easily implemented on a computer. After comparing the signals of manually selected cotton and foreign fibers, it is found that foreign fibers can be divided into two categories: one is colored impurities, with at least one component relatively low; the other is strongly reflective substances with bright colors, and images can be collected after ultraviolet irradiation, and the analysis shows that at least one of its components is higher than that of cotton fibers. By deeply exploring image morphology, observing the signal morphology after separation, and mastering the law of small signal mutations, a detection basis is formed. Combining feature classification, an upper and lower limit double-threshold algorithm is obtained, and a dynamic differential algorithm is summarized. The two are the key design bases of the system algorithm, forming an upper and lower limit threshold judgment algorithm for detection activities. The system needs to obtain three model curves of threshold upper and lower limits, and the acquisition methods are the same. Taking the specific process of the R component threshold as an example, the following are the specific acquisition steps:
[0095] First: For qualified cotton, 32 data collection operations are carried out, and the R component is classified by using the average value filtering method. The specific data is as follows:
[0096] r0, r1, r2... r k ... r 4095
[0097] Second: Multiply the data in the above formula by the non-linear parameter sequence of the R component of the line array camera:
[0098] X0, X1, X2... X k ... X 4095
[0099] This set of data is calculated by the following formula:
[0100] X k =r k ×δ k (k = 0, 1, 2... 4095)
[0101] Third: For the data in the above formula, find the maximum value:
[0102] Max=max(X0, X1, X2... X k ... X 4095 )
[0103] Fourthly: After obtaining Max, repeat the above steps continuously to obtain the corresponding data U0, U1, U2... U k ... U 4095 , that is, the upper limit threshold sequence of the R component.
[0104] According to the above steps, the lower limit can be obtained by simply multiplying it by the lower limit non-linear parameter, and by changing the third step to the minimum value and performing the inverse calculation operation, the goal can be achieved. Finally, the upper and lower limit curves of the R component threshold as shown in the following figure are obtained. Subsequently, for the pixels collected after the image is captured, compare the thresholds one by one according to the above steps. When it is found that any component of the pixel does not match the set range, it can be considered as foreign fiber, and if all components are within the range, it indicates that it is cotton fiber.
[0105] The removal system in this embodiment includes an opening cotton mechanism, a cotton conveying motor and pipeline, an image acquisition device, several LED light sources, a computer, a high-pressure air valve, and a waste discharge pipeline. After the cotton undergoes strong dust removal treatment, its structure becomes more fluffy and is then guided to the feeding port of the system through the main air duct. Under the action of the conveying system and the uniform dispersion mechanism, the cotton will be effectively dispersed, and its form changes from fluffy to snowflake-like. Under the combined action of the main air duct and gravity, the cotton keeps falling. When the cotton is within the field of view of the camera or inside the glass cavity, the camera will scan the cotton flow. Two cameras are distributed on both sides of the channel to collect image data simultaneously to avoid the surface of the cotton layer being attached by foreign fibers, thus preventing the occurrence of missed detection problems. With the support of the image acquisition card, the acquired image will be combined with the corresponding data format and transmitted to the computer. The computer will perform real-time processing based on the characteristic differences of the image data to identify the specific position of the foreign fibers in the cotton. After successfully identifying the foreign fibers, the control system will receive its position signal and issue corresponding instructions to transmit a cleaning signal to the cleaning system. When the cotton reaches the waste discharge port, the system will start the solenoid valve according to the received signal and, combined with the action of the high-pressure air flow, blow away the foreign fibers, thereby realizing the effective separation of the cotton and the foreign fibers.
[0106] Embodiment 2
[0107] A cotton foreign fiber detection method based on a multi - mode classification algorithm in this embodiment. First, image acquisition is carried out. A high - resolution CCD camera is used to scan the cotton in real time. To ensure the clarity and contrast of the image, a suitable light source needs to be set. The selection and arrangement of the light source are crucial for the image quality. Usually, a uniform white light source is adopted to avoid the interference of shadows and reflections. The acquired image will be used as input data for subsequent image processing and analysis. Image pre - processing is a key step to improve the accuracy of subsequent analysis, mainly including uneven illumination adjustment, noise filtering, and contrast enhancement, etc. First, the uneven illumination adjustment is to eliminate the image brightness difference caused by uneven light sources. The histogram equalization method is used to adjust the illumination of the image. The basic formula of histogram equalization is:
[0108]
[0109] Through equalization, the gray - level distribution of the image can be made more uniform, thereby improving the contrast. Secondly, noise filtering is to remove the random noise in the image. The commonly used filtering method is median filtering. The basic idea of median filtering is to replace the current pixel value with the median value in the neighborhood. The formula is:
[0110] f′(x,y)=median{f(i,j)|(i,j)∈N(x,y)}
[0111] Median filtering can effectively remove salt - and - pepper noise while retaining edge information. Finally, contrast enhancement is to enhance the image contrast through histogram equalization or adaptive histogram equalization (CLAHE), making the difference between foreign fibers and the background more obvious. The basic idea of CLAHE is to divide the image into multiple small blocks, perform histogram equalization on each small block, and then combine these small blocks to avoid over - enhancement.
[0112] Image segmentation is the process of dividing an image into a target region and a background. The purpose of segmentation is to extract foreign fibers from the background for subsequent analysis and processing. A threshold - based method is used for segmentation. A suitable threshold T is set to divide the image into foreground and background. The segmentation formula is:
[0113]
[0114] Among them, f(x,y) is the original image, and g(x,y) is the segmented image. By selecting a suitable threshold, foreign fibers can be effectively separated from the background. The selection of the threshold can be made by maximizing the between - class variance to select the optimal threshold.
[0115] Edge detection is used to extract edge information in images. Commonly used algorithms include the Canny edge detection algorithm. The steps of the Canny algorithm include Gaussian filtering, calculating gradients, non-maximum suppression, and double-threshold detection. Its core is to find edges by calculating the gradients of the image. The formula for calculating gradients is:
[0116]
[0117] where G x and G y are the gradients of the image in the x and y directions respectively. The Canny algorithm realizes edge detection through the following steps:
[0118] 1. Gaussian filtering: To reduce noise in the image, Gaussian filtering is first performed on the image. The formula for the Gaussian filter is:
[0119]
[0120] where σ is the standard deviation of the Gaussian function. Through Gaussian filtering, the image can be smoothed and the influence of noise on edge detection can be reduced.
[0121] 2. Calculating gradients: The Sobel operator is used to calculate the gradient magnitude and direction of the image. The Sobel operator calculates gradients by performing convolution operations on the image. Commonly used convolution kernels are:
[0122]
[0123] By performing convolution on the image, the gradient magnitude and direction of each pixel point can be obtained.
[0124] 3. Non-maximum suppression: In the gradient magnitude map, non-maximum suppression is used to suppress non-edge points and retain local maxima. The specific steps are:
[0125] (1) For each pixel point, check its gradient direction and find the two adjacent pixel points in that direction.
[0126] (2) If the gradient magnitude of the current pixel point is not the maximum among these two adjacent pixel points, set it to 0.
[0127] 4. Double-threshold detection: Set two thresholds, high and low, to determine strong edges and weak edges. Strong edges refer to pixel points with gradient magnitudes greater than the high threshold, and weak edges refer to pixel points with gradient magnitudes between the high threshold and the low threshold. Through double-threshold detection, edges can be effectively identified.
[0128] 5. Edge connection: Finally, complete edges are formed by connecting strong edges and weak edges. For weak edges, if they are connected to strong edges, they are retained; otherwise, they are suppressed.
[0129] Mathematical morphology processing is used to further improve the image quality. Common operations include opening, closing, erosion, and dilation. Opening can remove small noises, and closing can fill small holes. The erosion operation can effectively remove small noise points and enhance the connectivity of the target. The dilation operation can fill small holes and enhance the shape of the target. By combining erosion and dilation operations, opening and closing operations can be achieved, thereby further improving the image quality. The result of mathematical morphology processing will provide a clearer image for subsequent feature extraction, ensuring that the algorithm can accurately identify the characteristics of foreign fibers.
[0130] Feature extraction is the process of extracting useful information from the processed image. Common features include color features, shape features, and texture features. For color features, the RGB histogram of the image can be calculated. Shape features can be obtained through contour extraction. Texture features can be extracted by methods such as the gray-level co-occurrence matrix (GLCM). The calculation formula of GLCM is:
[0131]
[0132] where δ is the indicator function, Ω is the image region, and (Δx, Δy) is the relative position. By calculating the GLCM, texture features of the image, such as contrast, correlation, and uniformity, can be extracted. The result of feature extraction will provide important information for subsequent classification, ensuring that the algorithm can accurately identify and classify foreign fibers.
[0133] According to the extracted features, a suitable classification algorithm is selected for the detection of foreign fibers. Common classification algorithms include support vector machine (SVM), decision tree, and K-nearest neighbor (KNN), etc. Selecting a suitable algorithm can improve the accuracy and efficiency of detection. The basic principle of the support vector machine is to construct a hyperplane to maximize the margin between different classes, and its optimization objective is: Under the constraint conditions: where ω is the weight vector, b is the bias, y i is the sample label, and x i is the sample feature. By training the model, the support vector machine can effectively separate samples of different classes, thereby achieving classification.
[0134] After completing feature extraction and classification, the system will detect and classify foreign fibers in the image. Whether there are foreign fibers in the image is judged by the set threshold, and corresponding classification is carried out. The detection result will be fed back to the control system for subsequent sorting operations. At this time, the system can adjust itself according to historical data and real-time feedback to improve the accuracy and efficiency of subsequent detection.
Claims
1. A method for detecting foreign fibers in cotton based on a multi-mode classification algorithm, characterized in that, Including the following steps: S1: Collect cotton flow images through a linear array CCD camera and configure a uniform white light source; S2: Preprocess the images, including illumination correction based on histogram equalization, median filtering for denoising, and contrast-limited adaptive histogram equalization for contrast enhancement; S3: Extract multi-modal features from the preprocessed images, including: gray histogram statistical features, calculating the mean, variance, and cumulative difference value of the gray distribution; RGB color space threshold features, locating foreign fiber regions through multi-channel threshold segmentation; gray-level co-occurrence matrix texture features, extracting contrast, correlation, and energy parameters; S4: Use a statistical pattern classification algorithm to classify the multi-modal feature vectors, and determine whether there are foreign fibers in the images through a classifier; S5: If foreign fibers are detected, trigger the high-pressure air valve to remove them.
2. The cotton foreign fiber detection method based on the multi-mode classification algorithm according to claim 1, characterized in that In step S2, the histogram equalization method is used to adjust uneven illumination. Specifically: calculate the gray histogram of the image, determine the number of pixels at each gray level, and map the gray levels to new gray values through the cumulative distribution function. The basic formula for histogram equalization is: In the formula, H(x) is the histogram of the original image, and H’(x) is the histogram after equalization.
3. The cotton foreign fiber detection method based on a multi-mode classification algorithm according to claim 1, characterized in that, In S2, the median filtering algorithm is used. By replacing the value of each pixel with the median of the pixel values in its neighborhood, the influence of noise is suppressed. Specifically: for each pixel, first determine a neighborhood window, then calculate the median of all pixels in this window, and assign this median to the central pixel. The formula for median filtering is: f′(x,y)=median{f(i,j)|(i,j)∈N(x,y)} In the formula, f'(x,y) is the pixel value of the output image at (x,y), f(i,j) is the pixel value of the input image at (x,y), N(x,y) is the neighborhood of the pixel (x,y), the neighborhood is a square or circular window, and median{...} is the operation of taking the middle value of the set. If the number of pixel values in the neighborhood is odd, the median is the middle number after sorting. If it is even, the median is the average of the two middle numbers after sorting.
4. The cotton foreign fiber detection method based on the multi-mode classification algorithm according to claim 1, wherein In S3, the gray histogram statistical features are obtained by mapping each pixel value in the image to the corresponding gray level and counting the number of pixels at each gray level, obtaining a histogram representing the gray distribution of the image. The horizontal axis of this histogram represents the gray level, and the vertical axis represents the corresponding number of pixels. The gray feature statistical histogram of the image is a 1-D discrete function: H(k) = n k / n k = 0, 1, 2, 3..., L - 1 In the formula, the characteristic value is represented by k, the number of available numerical values is represented by L, and n k is the number of pixels in the image with the characteristic value of k, and the total number of image pixels is n Combined with the accumulation of the difference in the number of gray pixels at each level for judgment: where n i is the number of pixels with eigenvalue i in the equalized histogram, n( avg ) i is the average number of pixels with eigenvalue i in the equalized histogram, D is the sum of the differences between the two numbers of pixels at each gray level. After calculating D, a subtraction is performed with the number of 256 gray-level pixels to carry out a comparison operation to judge the cotton image. The normal cotton gray distribution can be represented by the equalized histogram. At this time, after calculating the gray histogram, a comparison is made. If the image is normal at this time, its gray level should conform to the distribution in the equalized histogram. On the contrary, if the difference between the two is significant, it indicates that it is abnormal.
5. The cotton foreign fiber detection method based on a multi-mode classification algorithm according to claim 4, characterized in that The statistical pattern recognition method classifies it as a classification problem. If N features are extracted and the image types are divided into m categories, combined with the features, make an assumption about the vector with a representative pattern, and consider the recognition pattern as the feature vector of an input sample X. Specifically as follows: X = [x1, x2,..., x n T X is a feature vector, representing the features of a sample in an N-dimensional space, and x i is the i-th feature of the feature vector, and the pattern classes are ω1, ω2,..., ω n represents the possible classification labels. The recognition activity is to judge X to determine whether it belongs to the corresponding pattern class.
6. The cotton foreign fiber detection method based on a multi-mode classification algorithm according to claim 1, characterized in that In the extraction of RGB color space threshold features in S3, the gray value of the pixel point is specifically represented by I, and the component values of different colors of the pixel point in the color image are represented by G, R, and B. For the pseudo-gray image, carry out edge detection activities, and the corresponding results are as follows: Wherein, GRAD(f R ), GRAD(f G ), GRAD(f B ) are the edge intensities obtained by edge detection of the R, G, B pseudo-gray images; f R , f G , f B are the R, G, B components; g is the structural element; GRAD(f) represents the comprehensively obtained edge intensity.
7. The cotton foreign fiber detection method based on the multi-mode classification algorithm according to claim 1, wherein In S3, the texture features are extracted by the gray-level co-occurrence matrix (GLCM) method. The calculation formula of GLCM is as follows: where δ is the indicator function, Ω is the image region, and (Δx, Δy) is the relative position.
8. A cotton foreign fiber removal system based on a multi-mode classification algorithm, characterized in that, It includes an opening mechanism, a cotton conveying motor and pipeline, an image acquisition device, an LED light source, a computer, a high-pressure air valve, and a waste removal pipeline.
Citation Information
Patent Citations
Machine-harvested seed cotton defect detection device and method based on deep learning
CN116698870A
Measuring method and system for weight of cotton foreign fiber based on machine vision technique
CN101555661A
Method and system for quickly segmenting high-resolution color image of cotton foreign fibers
CN101770645A
Detecting and positioning method of cotton foreign fibers
CN103234975A
Cotton foreign fiber identifying method based on RBF neural network
CN105095907A
Cited By
A method, device and system for self-adaptive adjustment of parameters for detection of foreign fibers in cotton
CN122509648A