Food impurity detection method based on spectrum technology

Through spectral technology combined with background segmentation, edge detection and bilateral filtering algorithms, the noise removal and edge blur problems caused by Gaussian filtering are solved, and the accurate identification and labeling of food impurities is achieved, and the efficiency and safety of food detection are improved.

CN119809998AActive Publication Date: 2025-04-11SHENYANG JIUDAO TECHNOLOGY CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202510294025.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-13
Publication Date
2025-04-11
Estimated Expiration
2045-03-13

AI Technical Summary

Technical Problem

While removing noise, existing Gaussian filtering technology will cause blurring of image edge information, which will affect the accurate identification of food impurities.

Method used

The food impurity detection method based on spectral technology is used to calculate the filter weight of pixel points through background segmentation, edge detection and bilateral filtering algorithms, reconstruct the spectral value of pixel points, and identify and label impurity food.

Benefits of technology

Effectively remove noise, retain edge information, improve the accuracy of identification of food impurities, improve the efficiency of food detection and ensure food safety.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119809998A_ABST
    Figure CN119809998A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image enhancement, in particular to a food impurity detection method based on a spectrum technology, which comprises the following steps: acquiring a mixed image of normal food and impurity food, and preprocessing to generate an initial image; performing background segmentation on the initial image to obtain a target image, performing edge detection based on the target image to screen out a single food area, and calculating a filtering weight of a pixel point by using a bilateral filtering algorithm for the single food area; pixel points in the single food area are reconstructed based on the filtering weight, and spectral values of the reconstructed pixel points are obtained; spectrum values of all pixel points in the target image after reconstruction are determined, filtering processing is carried out, impurity food is identified according to difference analysis, and marking is carried out; by optimizing the bilateral filtering algorithm, the interference of normal food on the impurity food is eliminated, the error of the identification result is avoided, the difference between the impurity food and the normal food in the spectral image is improved, and the accuracy of identifying the impurity food is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image enhancement, and in particular to a food impurity detection method based on spectroscopy technology. Background Art

[0002] Spectroscopic technology is to obtain detailed information about substances by deeply analyzing the wavelength or frequency distribution of light. It uses the principle that different substances have different absorption, emission or scattering characteristics of light. In practical applications, spectral technology will decompose light into a series of different wavelengths and accurately measure the intensity or other related characteristics of these wavelengths. In this way, spectral technology can reveal the composition, structure and other important physical and chemical properties of substances. Due to its unique advantages in material analysis, spectral technology is widely used in chemical analysis, materials science, biomedicine, environmental monitoring, food quality testing and other fields, providing accurate material identification and quantitative information for scientific research and industrial production. Spectroscopic technology is often used in the detection of food impurities.

[0003] In existing technical practices, spectral technology is usually used to detect moldy soybeans mixed in soybeans. However, the differences in color and surface features between moldy soybeans and normal soybeans are often very small. These subtle changes may be difficult to be clearly distinguished in hyperspectral images, and hyperspectral images are easily affected by environmental noise during the acquisition process, which will reduce the image quality and affect the recognition effect of moldy soybeans. At present, in order to reduce the impact of noise, Gaussian filtering technology is usually used to process images. However, while Gaussian filtering effectively removes noise, it will also cause the blurring of image edge information and the loss of some key detail features, which will also have an adverse effect on the recognition of moldy soybeans, making it difficult to ensure the accuracy of the detection process. Summary of the invention

[0004] In order to solve the technical problem that the existing Gaussian filter cannot simultaneously filter out the noise in the image and retain the edge information, resulting in the inability to accurately identify food impurities, the purpose of the present invention is to provide a food impurity detection method based on spectral technology, and the technical solution adopted is as follows: Collecting images of a mixture of normal food and impurity food, and performing preprocessing to generate an initial image; Perform background segmentation on the initial image to obtain the target image, perform edge detection based on the target image to screen out a single food area, and use the bilateral filtering algorithm to calculate the filtering weight of the pixel points in the single food area; Reconstruct the pixel points in a single food area based on the filter weights to obtain the spectral value of the reconstructed pixel points; Determine the reconstructed spectral values ​​of all pixels in the target image, perform filtering, and then identify and label the impure food based on difference analysis.

[0005] Preferably, the initial image is subjected to background segmentation to obtain a target image, and a single food area is screened out by edge detection based on the target image, including: Set the segmentation threshold, filter out the pixels in the initial image that exceed the segmentation threshold as the background area, and exclude them to obtain the target image; Edge detection is performed based on the target image to identify the edges of food and screen out a single food area.

[0006] Preferably, the filtering weights of the pixels are calculated using a bilateral filtering algorithm for a single food area, including: Define any pixel point in a single food area as a target pixel point, and determine the light spot expression degree of the target pixel point; Determine the light spot expression of all pixels in a single food area, cluster the single food area according to the distribution of the light spot expression, determine the cluster area of ​​the target pixel, determine whether the target pixel is an edge light spot pixel, and if so, correct the light spot expression of the target pixel; Select another non-target pixel point from a single food area as an auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point; Get the distance between the target pixel and the auxiliary pixel, and combine the similarity to get the filtering weight.

[0007] Preferably, determining the light spot expression degree of the target pixel point includes: Taking the target pixel as the center, select several pixels in each neighborhood direction, obtain the spectral value of each pixel in turn, and calculate the decrease degree of the spectral value of the target pixel in each neighborhood direction; The light spot expression degree of the target pixel is obtained according to the degree of decrease.

[0008] Preferably, the decrease degree of the spectral value of the target pixel in each neighborhood direction is calculated, and the corresponding calculation formula is: in, Indicates the target pixel In the neighborhood direction The degree of decrease of the upper spectrum value; Indicates the neighborhood direction Any pixel on Spectral value of Indicates the neighborhood direction Any pixel on To the neighborhood The last pixel Spectral value of Represents the direct proportional normalization function.

[0009] Preferably, the light spot expression degree of the target pixel point is obtained, and the corresponding calculation formula is: in, Indicates the target pixel The light spot performance; Indicates the target pixel In the neighborhood direction The decrease of the upper spectrum value.

[0010] Preferably, the light spot expression degree of the target pixel is corrected, and the corresponding calculation formula is: in, Represents the corrected target pixel The light spot performance; Indicates the target pixel The light spot performance; and Represents the target pixel points Any set of adjacent edge chain codes in the cluster region; Indicates the target pixel The last edge chain code in the cluster region; Indicates the target pixel The variance of non-zero items in the edge chain code of the cluster region; represents the inverse normalization function; Represents a constant term, used to prevent the denominator from being zero.

[0011] Preferably, the similarity between the target pixel and the auxiliary pixel is calculated, and the corresponding calculation formula is: in, Indicates the target pixel and auxiliary pixels similarity; and Represent the corrected target pixels respectively and auxiliary pixels The light spot performance; represents the inverse normalization function.

[0012] Preferably, the distance between the target pixel and the auxiliary pixel is obtained, and the filtering weight is obtained in combination with the similarity. The corresponding calculation formula is: in, Indicates that in a single food area In the target pixel During the reconstruction process, the auxiliary pixels are referenced The filter weights of Indicates the target pixel and auxiliary pixels The distance between Indicates the target pixel and auxiliary pixels similarity; represents the inverse normalization function.

[0013] Preferably, reconstructing the pixel points in a single food area based on the filtering weights to obtain the spectral value of the reconstructed pixel points includes: Defining a single food area Each non-target pixel is an auxiliary pixel, and each auxiliary pixel is recorded as , and the corresponding filtering weights of each auxiliary pixel are respectively , and the spectral value of each auxiliary pixel is ; Get the spectral value after pixel reconstruction. The corresponding calculation formula is: in, Indicates the target pixel The reconstructed spectral values; Indicates that in a single food area In the target pixel During the reconstruction process, refer to any auxiliary pixel point The filter weights of Indicates the number of auxiliary pixels; Indicates the target pixel that needs to be reconstructed Spectral value of Represents any auxiliary pixel spectral value.

[0014] The present invention has the following beneficial effects: In this application, the background area in the food image is first segmented by the highlight features of the background area, and then each single food area is selected; the spot expression is calculated according to the feature that the spectral value of the pixel points in the food area decreases toward the surrounding area, and the spot expression of the edge spot pixel points is corrected to improve the recognition accuracy; the filtering weight is calculated according to the distinguishing features between normal food and impure food to eliminate the interference of normal food on the recognition of impure food, and finally the image is reconstructed to improve the image quality, and the impure food is identified and labeled based on the difference in spectral value changes between impure food and normal food in the hyperspectral image, so as to effectively identify the impure food in the mixed food, which not only improves the efficiency of food detection, but also ensures the safety of food, and provides strong support for subsequent food quality control and safety detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0016] Figure 1 A flowchart of a method for detecting food impurities based on spectroscopy technology provided by one embodiment of the present invention; Figure 2 An image of a mixture of normal soybeans and impurity soybeans in a method for detecting food impurities based on spectral technology provided by an embodiment of the present invention; Figure 3 A spectral image of a mixture of normal soybeans and impurity soybeans in a food impurity detection method based on spectral technology provided by an embodiment of the present invention; Figure 4 A spectral image of an elliptical normal soybean in a food impurity detection method based on spectral technology provided by an embodiment of the present invention; Figure 5 A filtered spectral image of a mixture of normal soybeans and impure soybeans in a food impurity detection method based on spectral technology provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0017] In order to further explain the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following is a detailed description of the specific implementation method, structure, characteristics and effects of a food impurity detection method based on spectral technology proposed by the present invention in combination with the accompanying drawings and preferred embodiments. In the following description, different "one embodiment" or "another embodiment" does not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics in one or more embodiments may be combined in any suitable form.

[0018] Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.

[0019] A specific scheme of a food impurity detection method based on spectroscopy technology provided by the present invention is described in detail below in conjunction with the accompanying drawings.

[0020] See also Figure 1 , which shows a flowchart of a method for detecting food impurities based on spectroscopy technology provided by an embodiment of the present invention, the method comprising: Step S1: collecting images of a mixture of normal food and impurity food, and performing preprocessing to generate an initial image; Step S2: performing background segmentation on the initial image to obtain a target image, performing edge detection based on the target image to screen out a single food area, and using a bilateral filtering algorithm to calculate the filtering weights of the pixels in the single food area; Step S3: reconstructing the pixel points in the single food area based on the filtering weights to obtain the spectral values ​​of the reconstructed pixel points; Step S4: Determine the reconstructed spectral values ​​of all pixels in the target image, perform filtering, identify the impure food based on difference analysis, and mark it.

[0021] As an optional implementation, in this example, the analysis is performed based on soybean food.

[0022] For better explanation, the present application tests normal soybeans and impure soybeans, wherein impure soybeans refer to soybeans containing impurities, being damaged or of lower quality, such as damp and moldy soybeans, worm-eaten soybeans, immature or over-mature soybeans, and soybeans mixed with other plant seeds or foreign matter, etc.; and the color changes and surface characteristics of impure soybeans and normal soybeans are relatively small. It can be explained that the epidermis of soybeans is relatively thin and smooth. When soybeans are affected by the external environment, such as being damp, worm-eaten, over-mature, etc., the changes are often limited to a small area of ​​the soybean epidermis, which will not have a significant impact on the color and surface characteristics of the entire soybean, and the internal structure and chemical composition of the soybeans may also be affected by these. The quality and safety of soybeans are of vital importance to the health of consumers. For example, moldy soybeans are usually caused by a variety of molds, such as Aspergillus and Penicillium, which not only lead to a decrease in the nutritional value of soybeans, but also may produce harmful mycotoxins such as aflatoxins, which pose a serious threat to human health and may cause poisoning, cancer and other health problems.

[0023] Spectroscopy is an advanced technology that uses spectral analysis to study the composition, structure and properties of matter. It can reveal the intrinsic information of matter by analyzing the specific spectrum produced by the interaction of light of different wavelengths with matter. Spectroscopy uses the wavelength and frequency of light to analyze the composition of food to effectively identify and quantify impurities in food.

[0024] In the present application, the existing bilateral filtering algorithm is optimized to identify impure foods, namely impure soybeans, in mixed foods. The bilateral filtering algorithm is an image processing technology that can effectively remove noise in an image while maintaining edge information to achieve the effect of smoothing the image. The filtering weight is determined by considering the similarity between a pixel and pixels in its neighborhood, as well as the spatial distance between a pixel and pixels in its neighborhood, so that important edge information in the blurred image can be avoided while obtaining a smooth image through filtering.

[0025] Please combine Figure 2 and Figure 3 , which shows an image of a mixture of normal soybeans and impurity soybeans and a spectral image of a mixture of normal soybeans and impurity soybeans in a food impurity detection method based on spectral technology provided by an embodiment of the present invention, wherein the marked box contains moldy soybeans, i.e. impurity soybeans.

[0026] It is explained that in step S1, an image of a mixture of normal food and impure food, that is, an image of a mixture of normal soybeans and impure soybeans is collected; and the image is pre-processed into grayscale to generate an initial image, that is, each pixel in the initial image has only a grayscale value, and the grayscale value usually ranges from 0 to 255, indicating a brightness change from black to white, so as to reduce the amount of calculation and facilitate subsequent image processing; at the same time, a hyperspectral camera is used to collect spectral data of the initial image in the 400-1000nm band to capture rich spectral data from visible light to near-infrared regions; wherein the hyperspectral camera can capture detailed spectral information of each pixel in the initial image, providing a rich data basis for subsequent image processing and analysis.

[0027] Furthermore, in step S2, the background of the initial image is segmented to obtain a target image, and a single food area is screened out by edge detection based on the target image, including: Step S211: setting a segmentation threshold, screening out pixels in the initial image that exceed the segmentation threshold as background areas, and excluding them to obtain a target image.

[0028] It can be explained that in the mixed soybean image, due to the gaps between the soybean particles, background areas that do not belong to the soybeans themselves appear in the initial image, which will interfere with the identification of moldy soybeans. Therefore, before impurity detection, these background areas need to be excluded to ensure that the subsequent impurity identification process can be more accurate.

[0029] As an optional implementation, in the initial image, the influencing factors that may exist in the initial image are first removed by histogram equalization to improve the quality of the initial image; then the segmentation threshold is obtained by the Otsu (Otsu's method) threshold segmentation method. Preferably, in this embodiment, the segmentation threshold ; Among them, Otsu threshold segmentation is an automatic threshold determination method widely used in image processing. It calculates the histogram in the initial image and finds a segmentation threshold so that the inter-class variance of the foreground and background of the segmented image is maximized to achieve the best segmentation effect. It can automatically adapt to different image brightness and contrast, and has good versatility and robustness when processing different types of images.

[0030] Step S212: performing edge detection based on the target image, identifying food edges, and screening to obtain a single food area.

[0031] Preferably, in this embodiment, Canny edge detection is used to identify the edge of the food to obtain a single food area, that is, a single soybean area. In this embodiment, the single food area is defined as Among them, Canny edge detection detects the edges in the initial image through multi-stage processing. Its main goal is to provide low error rate, good positioning and minimize the response of edge points; and a single soybean area is used as a mask, that is, a technical means of analyzing and processing within the soybean area, and then reconstructing the initial image, a type of hyperspectral image.

[0032] It can be understood that when reconstructing the initial image, when a pixel point is in a single soybean area, the pixel points that are closer to the pixel point have a higher reference value for the pixel points in the reconstruction process due to their proximity in position, so they need to be assigned a larger filtering weight, and the two pixels show a higher similarity in features.

[0033] Furthermore, in step S2, a bilateral filtering algorithm is used to calculate the filtering weight of the pixel points for a single food area, including: Step S221: define any pixel point in a single food area as a target pixel point, and determine the light spot expression degree of the target pixel point.

[0034] To clarify, light spot expression refers to the clarity and visibility of bright spots or bright spots on an image caused by light sources or reflections in image processing. This phenomenon usually occurs when the lens is aimed at a strong light source, or under certain lighting conditions, such as shooting against the light. The quality of light spot expression directly affects the aesthetics and visual effects of the photo, and a high-quality lens can better control the light spot, making it appear as a beautiful circle or a specific shape, increasing the artistic sense of the photo. Conversely, a low-quality lens may cause the light spot to have an irregular shape, or even glare and ghosting, affecting the overall quality of the photo.

[0035] Furthermore, in step S221, determining the light spot expression degree of the target pixel point includes: Step S2211: Taking the target pixel as the center, select a number of pixels in each neighborhood direction, obtain the spectrum value of each pixel in turn, and calculate the degree of decrease of the spectrum value of the target pixel in each neighborhood direction.

[0036] To clarify, spectral value refers to the measurement of intensity or energy corresponding to light of different wavelengths or frequencies in spectral analysis, and is usually used to describe the characteristics of light sources, such as color temperature, spectral distribution, etc.

[0037] See also Figure 4 , which shows a spectral image of an elliptical normal soybean in a food impurity detection method based on spectral technology provided by an embodiment of the present invention.

[0038] It can be understood that in this embodiment, since the soybeans are round or elliptical, they are shown in the hyperspectral image. For round soybeans, the characteristic of the spot pixel point is that the spectral value decreases uniformly in the surrounding direction, that is, the change of the spectral value in each direction is relatively consistent; while for elliptical soybeans, the characteristic of the spot pixel point is that in the extension direction of the ellipse, the spectral value decreases less to both sides, and in the vertical direction, the spectral value decreases more, that is, the spectral characteristics of the elliptical soybeans in different directions are uneven; therefore, in the soybean hyperspectral image, the normal soybean area is shown as a single soybean area with a higher spectral value, which gradually decreases from the area to the surrounding, showing an obvious spot characteristic, and the spectral value of the entire normal soybean area changes greatly; on the contrary, the spectral value of the impurity soybean changes less, so the impurity soybean will disrupt the normal spectral distribution pattern, resulting in unclear or irregular decrease of the spectral value, affecting the accuracy of recognition; therefore, for similarity, when both pixels show non-spot characteristics, the greater the similarity, and when the difference between the two pixels in the spectral characteristics is smaller, the similarity is also greater.

[0039] Specifically, in this embodiment, for the target pixel point Analyze the target pixel centered, 5 pixels in each of the 8 neighborhood directions are selected to determine the spectral value variation characteristics of each pixel in each direction. Starting from the horizontal right neighborhood direction, each neighborhood direction is recorded clockwise as , and the pixel sequence in each neighborhood direction is based on the target pixel As the starting point, and extending outward, record any direction of the neighborhood The pixel sequence is , the spectral values ​​corresponding to the pixel sequence are recorded as .

[0040] Furthermore, in step S2211, the degree of decrease of the spectral value of the target pixel in each neighborhood direction is calculated, and the corresponding calculation formula is: in, Indicates the target pixel In the neighborhood direction The degree of decrease of the upper spectrum value; Indicates the neighborhood direction Any pixel on Spectral value of Indicates the neighborhood direction Any pixel on To the neighborhood The last pixel Spectral value of Represents the direct proportional normalization function.

[0041] It can be explained that the degree of decrease in spectral value refers to the extent to which the spectral intensity decreases with the change of wavelength or frequency, which is used to measure the spectral characteristics.

[0042] To explain, Indicates the neighborhood direction Any pixel on The spectral value of Represents pixel Any pixel Spectral value of Indicates the neighborhood direction Any pixel on To the neighborhood The last pixel The spectral value of express arrive Spectral value of pixel point; Represents pixel The sum of the differences between the pixel and all pixels after it. The greater the difference, the greater the decline. Indicates the target pixel In the neighborhood direction The sum of the spectral value differences between each pixel and all the pixels after these pixels is analyzed in turn, that is, the degree of decrease of the spectral value.

[0043] Step S2212: Obtain the light spot expression degree of the target pixel point according to the degree of decrease.

[0044] Specifically, the target pixel As the center, get the directions of each neighborhood The corresponding decrease in spectral values ​​is recorded as .

[0045] Furthermore, in step S2212, the light spot expression degree of the target pixel is obtained, and the corresponding calculation formula is: in, Indicates the target pixel The light spot performance; Indicates the target pixel In the neighborhood direction The decrease of the upper spectrum value.

[0046] To explain, Indicates the target pixel As the center, each neighborhood direction The average decrease of the spectral value on the upper side, the greater the decrease, the closer the target pixel point is to the target pixel point. Satisfying the characteristic of decreasing spectral values ​​in each neighborhood direction, the target pixel point The surrounding spectrum distribution is relatively uniform and shows a certain regularity, which means that the target pixel The greater the light spot expression.

[0047] Step S222: Determine the spot expression degree of all pixels in a single food area, cluster the single food area according to the distribution of the spot expression degree, determine the cluster area of ​​the target pixel, and judge whether the target pixel is an edge spot pixel. If so, correct the spot expression degree of the target pixel.

[0048] It can be understood that in a single food area, that is, the center of a single soybean area, the pixel point has a higher spot expression, while the pixel points at the edge of the single soybean area may not fully conform to the characteristic that the spectral value decreases toward the surrounding area, and the spot expression is poor. Therefore, in order to ensure the accuracy of subsequent data analysis, it is necessary to correct the spot expression of these edge pixels.

[0049] Specifically, the spot expression of all pixels in a single food area is obtained and recorded as ; Then, K-Means (K-Means Clustering, K-means) clustering is performed on all the light spot performances. Preferably, in this embodiment, ; K-Means clustering divides the light spot performance into K clusters through an iterative process, so that the light spot performance similarity in each cluster area is as high as possible, while the light spot performance similarity between different cluster areas is as low as possible; it realizes clustering by minimizing the sum of square errors of samples within the cluster to achieve data division and classification; when the target pixel point When the cluster area is circular or elliptical, that is, when the spot performance of the pixel points in the cluster area satisfies the uniform change, it indicates that the target pixel point is the pixel point at the edge of the light spot, so the target pixel point needs to be Make corrections.

[0050] Define the target pixel The cluster area is The 8-chain code representation of the edge in the cluster region is , and the absolute value of the first-order difference chain code is recorded as , and in the first-order difference chain code, the variance of the non-zero term is recorded as .

[0051] Furthermore, in step S222, the light spot expression degree of the target pixel is corrected, and the corresponding calculation formula is: in, Represents the corrected target pixel The light spot performance; Indicates the target pixel The light spot performance; and Represents the target pixel points Any set of adjacent edge chain codes in the cluster region; Indicates the target pixel The last edge chain code in the cluster region; Indicates the target pixel The variance of non-zero items in the edge chain code of the cluster region; represents the inverse normalization function; Represents a constant term, used to prevent the denominator from being zero.

[0052] To explain, Represents the difference between two adjacent edge chain codes; Represents cluster area The average difference of adjacent edge chain codes in the cluster is smaller, indicating that the cluster area The smoother the edge, the better the performance of the light spot in the cluster area, indicating that the cluster area The target pixel within The better the light spot performance; Indicates the target pixel The variance of the non-zero items in the edge chain code of the cluster area is used to measure the discrete degree of the spot performance. The smaller the variance, the cluster area The more regular the change of the light spot at the edge is, the more consistent it is with the light spot performance; Indicates the target pixel The last edge chain code in the cluster area where the target pixel is located can be explained as follows: the edge chain code is used to describe the direction of the edge of the object in the image. Each chain code value represents the extension of the edge in a specific direction. Usually, the edge chain code is continuous, and each pixel point may belong to a different cluster area. Therefore, in some specific image structures and edge directions, the target pixel point The last edge chain code in the cluster region may be equal to 1, so the constant term is set Used to prevent the denominator from being 0.

[0053] Step S223: Filter out another non-target pixel point from the single food area as an auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point.

[0054] It can be explained that similarity refers to the closeness of two pixels in color, brightness and other visual features.

[0055] Understandably, for the target pixel Reconstructed with reference to a single food area Other pixels in the The greater the similarity, the greater the filtering weight; the closer the distance between two pixels, the greater the filtering weight.

[0056] Furthermore, in step S223, the similarity between the target pixel and the auxiliary pixel is calculated, and the corresponding calculation formula is: in, Indicates the target pixel and auxiliary pixels similarity; and Represent the corrected target pixels respectively and auxiliary pixels The light spot performance; represents the inverse normalization function.

[0057] Explain that the corrected target pixel and auxiliary pixels The smaller the light spot expression is, the larger the non-light spot expression is, which means that the two pixels are more similar. Indicates the target pixel and auxiliary pixels The smaller the difference between two pixels, the greater the similarity.

[0058] Step S224: Obtain the distance between the target pixel and the auxiliary pixel, and obtain the filtering weight in combination with the similarity.

[0059] It can be explained that the target pixel and auxiliary pixels The closer the distance between them is, the closer the positions of the two pixels are in a single food area, and the more likely the properties such as color and brightness are to be similar. Preferably, common distance measurement methods such as Euclidean distance and Manhattan distance are used to obtain the distance between the target pixel and the auxiliary pixel.

[0060] Furthermore, in step S224, the distance between the target pixel and the auxiliary pixel is obtained, and the filtering weight is obtained in combination with the similarity. The corresponding calculation formula is: in, Indicates that in a single food area In the target pixel During the reconstruction process, the auxiliary pixels are referenced The filter weights of Indicates the target pixel and auxiliary pixels The distance between Indicates the target pixel and auxiliary pixels similarity; represents the inverse normalization function.

[0061] To explain, Indicates the target pixel and auxiliary pixels The closer the distance is, the higher the correlation between the two pixels in a single food area, and the greater the filtering weight. Indicates the target pixel and auxiliary pixels The greater the similarity, the more difficult it is to distinguish the two pixels visually. Therefore, when the bilateral filtering algorithm is used later, the filtering weight is also greater.

[0062] Furthermore, in step S3, the pixel points in the single food area are reconstructed based on the filter weights to obtain the spectral values ​​of the reconstructed pixel points, including: Defining a single food area Each non-target pixel is an auxiliary pixel, and each auxiliary pixel is recorded as , and the corresponding filtering weights of each auxiliary pixel are respectively , and the spectral value of each auxiliary pixel is ; Get the spectral value after pixel reconstruction. The corresponding calculation formula is: in, Indicates the target pixel The reconstructed spectral values; Indicates that in a single food area In the target pixel During the reconstruction process, refer to any auxiliary pixel point The filter weights of Indicates the number of auxiliary pixels; Indicates the target pixel that needs to be reconstructed Spectral value of Represents any auxiliary pixel spectral value.

[0063] To explain, Indicates the weight ratio of the original spectral values ​​that have not been reconstructed, that is, reflects the impact of the original data on the data that needs to be reconstructed, so as to indicate which data will be given priority in the reconstruction process; Represents any auxiliary pixel The filtering weight ratio is used to effectively adjust the local features of the target image, which is used to ensure that the initial image with the background area segmented out can achieve the purpose of optimizing the image quality after filtering. And by optimizing the distribution of the weight ratio of each data, the accuracy and stability of food impurity detection can be effectively improved.

[0064] It can be explained that in step S4, the spectral values ​​of all pixels in the target image after reconstruction are determined, and after filtering processing, the target image can be smoothed, noise interference can be reduced, and specific features in the target image can be enhanced, so that the impure food in the target image can be more clearly identified in the future; according to the difference analysis, the impure food is identified and labeled, that is, the impure food is clearly marked on the target image, so that the staff can quickly identify the impure food; wherein, the difference analysis refers to a detailed study and comparison of the differences between two or more objects, data sets or situations.

[0065] See also Figure 5 , which shows a filtered spectral image of a mixture of normal soybeans and impure soybeans in a food impurity detection method based on spectral technology provided by an embodiment of the present invention.

[0066] Specifically, based on the principles of the above steps, all spectral images in the 400-1000nm band are filtered to increase the difference between normal soybeans and impure soybeans in the hyperspectral images, making the characteristics of impure soybeans more obvious; according to the difference analysis, the impurity soybeans in the mixed soybeans are effectively identified and marked for subsequent processing and analysis.

[0067] It can be understood that in this application, the background area in the food image is first segmented by the highlight features of the background area, and then each single food area is selected; the spot expression is calculated according to the feature that the spectral value of the pixel point in the food area decreases toward the surrounding area, and the spot expression of the edge spot pixel point is corrected to improve the recognition accuracy; according to the distinguishing features between normal food and impure food, the filtering weight is calculated to eliminate the interference of normal food on the recognition of impure food, and finally the image is reconstructed to improve the image quality, and the impure food is identified and labeled based on the difference in spectral value changes between impure food and normal food in the hyperspectral image, so as to effectively identify the impure food in the mixed food, which not only improves the efficiency of food detection, but also ensures the safety of food, and provides strong support for subsequent food quality control and safety detection.

[0068] It should be noted that the sequence of the above embodiments of the present invention is only for description and does not represent the advantages and disadvantages of the embodiments. The processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0069] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.

Claims

1. A method for detecting food impurities based on spectroscopy technology, characterized in that: The method comprises: Collecting images of a mixture of normal food and impurity food, and performing preprocessing to generate an initial image; Perform background segmentation on the initial image to obtain the target image, perform edge detection based on the target image to screen out a single food area, and use the bilateral filtering algorithm to calculate the filtering weight of the pixel points in the single food area; Reconstruct the pixel points in a single food area based on the filter weights to obtain the spectral value of the reconstructed pixel points; Determine the reconstructed spectral values ​​of all pixels in the target image, perform filtering, and then identify and label the impure food based on difference analysis.

2. The method for detecting food impurities based on spectroscopy technology according to claim 1, characterized in that: Perform background segmentation on the initial image to obtain the target image, and perform edge detection based on the target image to filter out a single food area, including: Set the segmentation threshold, filter out the pixels in the initial image that exceed the segmentation threshold as the background area, and exclude them to obtain the target image; Edge detection is performed based on the target image to identify the edges of food and screen out a single food area.

3. The method for detecting food impurities based on spectroscopy technology according to claim 2, characterized in that: The bilateral filtering algorithm is used to calculate the filtering weights of pixels for a single food area, including: Define any pixel point in a single food area as a target pixel point, and determine the light spot expression degree of the target pixel point; Determine the light spot expression of all pixels in a single food area, cluster the single food area according to the distribution of the light spot expression, determine the cluster area of ​​the target pixel, determine whether the target pixel is an edge light spot pixel, and if so, correct the light spot expression of the target pixel; Select another non-target pixel point from a single food area as an auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point; Get the distance between the target pixel and the auxiliary pixel, and combine the similarity to get the filtering weight.

4. The method for detecting food impurities based on spectroscopy technology according to claim 3, characterized in that: Determine the light spot performance of the target pixel, including: Taking the target pixel as the center, select several pixels in each neighborhood direction, obtain the spectral value of each pixel in turn, and calculate the decrease degree of the spectral value of the target pixel in each neighborhood direction; The light spot expression degree of the target pixel is obtained according to the degree of decrease.

5. The method for detecting food impurities based on spectroscopy technology according to claim 4, characterized in that: Calculate the degree of decrease of the spectral value of the target pixel in each neighborhood direction. The corresponding calculation formula is: in, Indicates the target pixel In the neighborhood direction The degree of decrease of the upper spectrum value; Indicates the neighborhood direction Any pixel on Spectral value of Indicates the neighborhood direction Any pixel on To the neighborhood The last pixel Spectral value of Represents the positive proportional normalization function.

6. The method for detecting food impurities based on spectroscopy technology according to claim 4, characterized in that: The light spot expression degree of the target pixel is obtained, and the corresponding calculation formula is: in, Indicates the target pixel The light spot performance; Indicates the target pixel In the neighborhood direction The decrease of the upper spectrum value.

7. The method for detecting food impurities based on spectroscopy technology according to claim 3, characterized in that: Correct the spot performance of the target pixel, and the corresponding calculation formula is: in, Represents the corrected target pixel The light spot performance; Indicates the target pixel The light spot performance; and Represents the target pixel points Any set of adjacent edge chain codes in the cluster region; Indicates the target pixel The last edge chain code in the cluster region; Indicates the target pixel The variance of non-zero items in the edge chain code of the cluster region; represents the inverse normalization function; Represents a constant term, used to prevent the denominator from being zero.

8. The method for detecting food impurities based on spectroscopy technology according to claim 3, characterized in that: Calculate the similarity between the target pixel and the auxiliary pixel. The corresponding calculation formula is: in, Indicates the target pixel and auxiliary pixels similarity; and Represent the corrected target pixels respectively and auxiliary pixels The light spot performance; represents the inverse normalization function.

9. The method for detecting food impurities based on spectroscopy technology according to claim 3, characterized in that: Get the distance between the target pixel and the auxiliary pixel, and combine the similarity to get the filtering weight. The corresponding calculation formula is: in, Indicates that in a single food area In the target pixel During the reconstruction process, reference auxiliary pixels The filter weights of Indicates the target pixel and auxiliary pixels The distance between Indicates the target pixel and auxiliary pixels similarity; represents the inverse normalization function.

10. The method for detecting food impurities based on spectroscopy technology according to claim 3, characterized in that: Reconstruct the pixel points in a single food area based on the filter weights to obtain the spectral values ​​of the reconstructed pixel points, including: Defining a single food area Each non-target pixel is an auxiliary pixel, and each auxiliary pixel is recorded as , and the corresponding filtering weights of each auxiliary pixel are respectively , and the spectral value of each auxiliary pixel is ; Get the spectral value after pixel reconstruction. The corresponding calculation formula is: in, Indicates the target pixel The reconstructed spectral values; Indicates that in a single food area In the target pixel During the reconstruction process, refer to any auxiliary pixel point The filter weights of Indicates the number of auxiliary pixels; Indicates the target pixel that needs to be reconstructed Spectral value of Represents any auxiliary pixel spectral value.

Citation Information

Patent Citations

  • Device and method for detecting cold damage of peach fruits based on hyperspectral images

    CN103439270A

  • Foreign substance detection system based on spectral imaging and foreign substance detection method based on spectral imaging

    CN103983649A

  • Method for detecting impurities in preserved vegetables based on hyperspectral image acquisition system

    CN111008970A

  • Crystal impurity detection method for boehmite production

    CN116385446A

  • Dam termite damage identification method and system based on infrared characteristic attributes

    CN118918532A