Food impurity detection method based on spectral technology
Through the background segmentation and bilateral filtering algorithm of spectral technology, the edge information blur problem caused by Gaussian filtering is solved, and the accurate identification and labeling of food impurities is achieved, and the detection efficiency and safety are improved.
Patent Information
- Application Number
- CN202510294025.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-13
- Publication Date
- 2025-07-08
- Estimated Expiration
- 2045-03-13
AI Technical Summary
While removing noise, the existing Gaussian filtering technology can easily lead to blurred image edge information in food impurities detection, affecting the accuracy of identification of impurities such as moldy soybeans.
Using a spectral technology-based method, a single food area is screened through background segmentation and edge detection, a bilateral filtering algorithm is used to calculate the filter weight of pixel points, reconstruct the spectral value of pixel points, and identify and label impurity foods.
It improves the accuracy and efficiency of food impurity testing, ensures food safety, and provides strong support for subsequent quality control and safety testing.
Smart Images

Figure CN119809998B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image enhancement, and particularly to a method for detecting food impurities based on spectral technology. Background Art
[0002] Spectral technology obtains detailed information about substances by deeply analyzing the wavelength or frequency distribution of light, which is based on the principle that different substances have different absorption, emission, or scattering characteristics of light; in practical applications, spectral technology decomposes light into a series of different wavelengths and precisely measures 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 many fields such as chemical analysis, materials science, biomedicine, environmental monitoring, and food quality detection, providing accurate material identification and quantification information for scientific research and industrial production; and spectral technology is often used in the detection of grain impurities.
[0003] In existing technical practices, for the detection of moldy soybeans mixed in soybeans, spectral technology is usually used. However, the differences in color and surface characteristics between moldy soybeans and normal soybeans are often very small, and these subtle changes may be difficult to clearly distinguish in hyperspectral images. Moreover, 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; currently, in order to reduce the influence of noise, Gaussian filtering technology is usually used to process images, but while Gaussian filtering effectively removes noise, it will also cause the blurring of image edge information, and thus some key detail features are lost, which will also have an adverse impact on the recognition of moldy soybeans, making it difficult to guarantee the accuracy during the detection process. Summary of the Invention
[0004] In order to solve the technical problem that the existing Gaussian filtering cannot simultaneously ensure the filtering of noise in the image and the retention of edge information, resulting in inaccurate identification of food impurities, the purpose of the present invention is to provide a method for detecting food impurities based on spectral technology, and the specific technical solutions adopted are as follows:
[0005] Collect an image of a mixture of normal food and impurity food, and perform preprocessing to generate an initial image;
[0006] Perform background segmentation on the initial image to obtain a target image, perform edge detection based on the target image to screen out a single food area, and use a bilateral filtering algorithm to calculate the filtering weights of pixel points for the single food area;
[0007] Reconstruct the pixel points in the single food area based on the filtering weights to obtain the spectral values of the pixel points after reconstruction;
[0008] Determine the spectral values of all pixel points in the target image after reconstruction. After filtering, identify the contaminated food based on difference analysis and mark it.
[0009] Preferably, perform background segmentation on the initial image to obtain the target image. Based on the target image, perform edge detection to screen out the single food area, including:
[0010] Set the segmentation threshold, screen out the pixel points in the initial image that exceed the segmentation threshold as the background area, and exclude them to obtain the target image;
[0011] Perform edge detection based on the target image, identify the food edge, and screen to obtain the single food area.
[0012] Preferably, use the bilateral filtering algorithm to calculate the filtering weights of pixel points for the single food area, including:
[0013] Define any pixel point in the single food area as the target pixel point, and determine the spot manifestation degree of the target pixel point;
[0014] Determine the spot manifestation degrees of all pixel points in the single food area. According to the distribution of spot manifestation degrees, cluster the single food area, determine the cluster area of the target pixel point, and judge whether the target pixel point is an edge spot pixel point. If so, correct the spot manifestation degree of the target pixel point;
[0015] Select another non-target pixel point from the single food area as the auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point;
[0016] Obtain the distance between the target pixel point and the auxiliary pixel point, and combine the similarity to obtain the filtering weight.
[0017] Preferably, determine the spot manifestation degree of the target pixel point, including:
[0018] Taking the target pixel point as the center, select several pixel points in each neighborhood direction of it, and sequentially obtain the spectral values of each pixel point, and calculate the degree of decrease of the spectral value of the target pixel point in each neighborhood direction;
[0019] Obtain the spot manifestation degree of the target pixel point according to the degree of decrease.
[0020] Preferably, calculate the degree of decrease of the spectral value of the target pixel point in each neighborhood direction, and the corresponding calculation formula is:
[0021]
[0022] Wherein, represents the target pixel point in the neighborhood direction The degree of decrease of the upper spectral value; Indicates the neighborhood direction Any pixel point on The spectral value of; Indicates the neighborhood direction Any pixel point on To this neighborhood direction The last pixel point The spectral value of; Indicates the proportional normalization function.
[0023] Preferably, the spot manifestation degree of the target pixel point is obtained, and the corresponding calculation formula is:
[0024]
[0025] Among them, Indicates the target pixel point The spot manifestation degree of; Indicates the target pixel point In the neighborhood direction The degree of decrease of the spectral value on.
[0026] Preferably, the spot manifestation degree of the target pixel point is corrected, and the corresponding calculation formula is:
[0027]
[0028] Among them, Indicates the corrected target pixel point The spot manifestation degree of; Indicates the target pixel point The spot manifestation degree of; And Respectively indicate any set of adjacent edge chain codes in the cluster region where the target pixel point Is located; Indicates the target pixel point The last edge chain code in the cluster region where it is located; Indicates the target pixel point The variance of the non-zero terms in the edge chain code of the cluster region where it is located; Indicates the inverse proportional normalization function; Indicates a constant term used to prevent the denominator from being 0.
[0029] Preferably, the similarity between the target pixel point and the auxiliary pixel point is calculated, and the corresponding calculation formula is:
[0030]
[0031] Among them, Indicates the target pixel point And the auxiliary pixel point Similarity; and respectively represent the corrected target pixel point and the auxiliary pixel point of the spot performance; represents the inverse proportional normalization function.
[0032] Preferably, obtain the distance between the target pixel point and the auxiliary pixel point, and combine the similarity to obtain the filtering weight. The corresponding calculation formula is:
[0033]
[0034] wherein, represents in a single food area the target pixel point in the reconstruction process, referring to the filtering weight of the auxiliary pixel point ; represents the target pixel point and the auxiliary pixel point the distance between; represents the target pixel point and the auxiliary pixel point similarity; represents the inverse proportional normalization function.
[0035] Preferably, based on the filtering weight, reconstruct the pixel points in the single food area, and obtain the spectral value of the pixel points after reconstruction, including:
[0036] Define each non-target pixel point in the single food area as an auxiliary pixel point, and record each auxiliary pixel point respectively and respectively obtain the filtering weights of each auxiliary pixel point in turn as and the spectral values of each auxiliary pixel point in turn as ; ;
[0037] Obtain the spectral value of the pixel points after reconstruction. The corresponding calculation formula is:
[0038]
[0039] wherein, represents the spectral value of the target pixel point after reconstruction; represents in the single food area the target pixel point in the reconstruction process, referring to the filtering weight of any auxiliary pixel point ; represents the number of auxiliary pixel points; Indicates the target pixel points that need to be reconstructed The spectral value; Indicates any auxiliary pixel point The spectral value.
[0040] The present invention has the following beneficial effects:
[0041] In this application, first, the background area in the food image is segmented through the highlight feature of the background area, and then each single food area is framed; according to the feature that the spectral values of the pixel points in the food area decrease towards the surroundings, the spot manifestation degree is calculated, and the spot manifestation degree of the edge spot pixel points is corrected to improve the recognition accuracy; according to the difference features between normal food and impurity food, the filtering weight is calculated to exclude the interference of normal food on the recognition of impurity food. Finally, the image is reconstructed to improve the image quality. Based on the spectral value change difference between impurity food and normal food in the hyperspectral image, the impurity food is identified and labeled, so as to effectively identify the impurity food in the mixed food, which not only improves the efficiency of food detection, but also ensures the safety of food, providing strong support for subsequent food quality control and safety detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required to be used in the description of the embodiments or the prior art. Obviously, the following drawings are only some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0043] Figure 1 It is a flowchart of the steps of a food impurity detection method based on spectral technology provided by an embodiment of the present invention;
[0044] Figure 2 It is an image of a mixture of normal soybeans and impurity soybeans of a food impurity detection method based on spectral technology provided by an embodiment of the present invention;
[0045] Figure 3 It is a spectral image of a mixture of normal soybeans and impurity soybeans of a food impurity detection method based on spectral technology provided by an embodiment of the present invention;
[0046] Figure 4 It is a spectral image of oval normal soybeans of a food impurity detection method based on spectral technology provided by an embodiment of the present invention;
[0047] Figure 5 It is a filtered spectral image of a mixture of normal soybeans and impurity soybeans of a food impurity detection method based on spectral technology provided by an embodiment of the present invention. Detailed implementation manners
[0048] In order to further elaborate on the technical means and effects adopted by the present invention to achieve the predetermined invention purpose, the following specifically describes, with reference to the accompanying drawings and preferred embodiments, a food impurity detection method based on spectral technology proposed according to the present invention, including its specific implementation manners, structures, features, and effects. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. In addition, the specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the technical field to which the present invention belongs.
[0050] The following specifically describes the specific solution of a food impurity detection method based on spectral technology provided by the present invention with reference to the accompanying drawings.
[0051] Please refer to Figure 1 , which shows a flowchart of the steps of a food impurity detection method based on spectral technology provided by an embodiment of the present invention. The method includes:
[0052] Step S1: Collect an image of a mixture of normal food and impurity food, and perform preprocessing to generate an initial image;
[0053] Step S2: Perform background segmentation on the initial image to obtain a target image. Based on the target image, perform edge detection to screen out a single food area, and use the bilateral filtering algorithm to calculate the filtering weights of the pixel points for the single food area;
[0054] Step S3: Reconstruct the pixel points in the single food area based on the filtering weights to obtain the spectral values of the pixel points after reconstruction;
[0055] Step S4: Determine the spectral values of all pixel points in the target image after reconstruction. After filtering processing, identify the impurity food according to the difference analysis and perform annotation.
[0056] As an optional implementation manner, in this embodiment, an analysis is made based on soybean food.
[0057] For better illustration, this application conducts detection on normal soybeans and soybeans with impurities. Herein, soybeans with impurities refer to soybeans containing impurities, being damaged, or having lower quality, such as soybeans affected by moisture and mold, soybeans damaged by insects, immature or overripe soybeans, and soybeans mixed with other plant seeds or foreign substances, etc.; the color changes and surface features between soybeans with impurities and normal soybeans are relatively subtle. It can be noted that the epidermis of soybeans is relatively thin and smooth. When soybeans are affected by the external environment, such as moisture, insect damage, overripeness, etc., the changes are often limited to small areas of the soybean epidermis and do not cause significant impacts on the color and surface features of the entire soybean. Also, the internal structure and chemical composition of soybeans may undergo subtle changes due to these external factors, but these changes are often difficult to detect visually; in addition, due to differences in factors such as soybean variety, origin, and storage conditions, there are also certain differences in color and surface features among normal soybeans themselves, which also increases the difficulty of distinguishing soybeans with impurities from normal soybeans, resulting in the difficulty of differentiating soybeans with impurities from normal soybeans in hyperspectral images; the quality and safety of soybeans are crucial for consumers' health. For example, moldy soybeans are usually caused by various molds, such as Aspergillus and Penicillium, which not only lead to a decline in the nutritional value of soybeans but may also produce harmful mycotoxins such as aflatoxin, posing a serious threat to human health and potentially causing poisoning, cancer, and other health problems.
[0058] Spectral technology is an advanced technology that uses spectral analysis to study the composition, structure, and properties of substances. By analyzing the specific spectra generated by the interaction of light of different wavelengths with substances, it can reveal the internal information of substances; spectral technology uses the wavelength and frequency of light to analyze the components of food to effectively identify and quantify impurities in food.
[0059] In this application, by optimizing the existing bilateral filtering algorithm, it is possible to identify impurity foods, namely soybeans with impurities, in mixed foods; among them, the bilateral filtering algorithm is an image processing technology that can effectively remove noise in images while maintaining edge information to achieve the effect of smoothing the image. It determines the filtering weight by considering the similarity between a pixel and the pixels in its neighborhood, as well as the spatial distance between the pixel and the pixels in its neighborhood, so that while obtaining a smoothed image through filtering processing, it can avoid blurring important edge information in the image.
[0060] Please refer to Figure 2 and Figure 3 , which shows an image of a mixture of normal soybeans and soybeans with impurities and a spectral image of a mixture of normal soybeans and soybeans with impurities provided by an embodiment of the present invention. Among them, the moldy soybeans, that is, soybeans with impurities, are within the marked frames.
[0061] It is explained that in step S1, an image of a mixture of normal food and contaminated food is collected, that is, an image of a mixture of normal soybeans and contaminated soybeans; and the image is preprocessed by grayscale conversion to generate an initial image, that is, each pixel point in the initial image only has a grayscale value, and the range of the grayscale value is usually from 0 to 255, representing the 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 - 1000 nm band to capture rich spectral data from the visible light to the near-infrared region; among them, the hyperspectral camera can capture the detailed spectral information of each pixel point in the initial image, providing a rich data basis for subsequent image processing and analysis.
[0062] Further, in step S2, the background of the initial image is segmented to obtain a target image, and edge detection is performed based on the target image to screen out single food regions, including:
[0063] Step S211: Set a segmentation threshold, and screen out the pixel points in the initial image that exceed the segmentation threshold as the background region, and exclude them to obtain the target image.
[0064] It can be explained that in the image of the mixed soybeans, due to the gaps between soybean grains, there are background regions in the initial image that do not belong to the soybeans themselves, which will interfere with the identification of moldy soybeans. Therefore, before performing impurity detection, it is necessary to exclude these background regions to ensure that the subsequent impurity identification process can be more accurate.
[0065] As an optional implementation manner, in the initial image, first, possible influencing factors in the initial image are removed by histogram equalization to improve the quality of the initial image; then, the segmentation threshold is obtained by the method of otsu (Otsu's method, Otsu thresholding method). Preferably, in this embodiment, the segmentation threshold ; among them, otsu threshold segmentation is an automatic threshold determination method widely used in image processing. By calculating the histogram in the initial image, it finds a segmentation threshold that maximizes the between-class variance of the foreground and background of the segmented image, achieving 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.
[0066] Step S212: Perform edge detection based on the target image, identify the food edge, and screen out the single food region.
[0067] Preferably, in this embodiment, Canny edge detection is used to identify the food edge and obtain a single food region, that is, a single soybean region. In this embodiment, the single food region 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.
[0068] 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.
[0069] 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:
[0070] 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.
[0071] 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.
[0072] Furthermore, in step S221, determining the light spot expression degree of the target pixel point includes:
[0073] 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.
[0074] 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.
[0075] 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.
[0076] Understandably, in this embodiment, since soybeans are round or oval, in the hyperspectral image, for round soybeans, the characteristics of the light spot pixel points are that the spectral values decrease uniformly in all surrounding directions, that is, the changes in spectral values in all directions are relatively consistent; for oval soybeans, the characteristics of their light spot pixel points are that in the extension direction of the ellipse, the spectral values decrease less on both sides, while in the perpendicular direction, the spectral values decrease more significantly, which indicates that the spectral characteristics of oval soybeans are non-uniform in different directions; therefore, in the hyperspectral image of soybeans, the area of normal soybeans shows that the spectral values of a single soybean area are relatively high, and gradually decrease from this area to the surrounding, showing obvious light spot characteristics, and the spectral value changes of the entire normal soybean area are relatively large; on the contrary, the spectral value changes of impurity soybeans are relatively small, so impurity soybeans will disrupt the normal spectral distribution pattern, resulting in the spectral values decreasing not significantly or irregularly, affecting the accuracy of recognition; therefore, for similarity, when both of two pixel points show non-light spot characteristics, the similarity is greater, and when the difference in spectral characteristics between the two pixel points is smaller, the similarity is also greater.
[0077] Specifically, in this embodiment, the target pixel point is analyzed, that is, with the target pixel point as the center, 5 pixel points in each of its 8 neighborhood directions are selected, and the spectral value change characteristics of each pixel point in each direction are judged. Starting from the neighborhood direction horizontally to the right, each neighborhood direction is sequentially denoted as in a clockwise manner, and the pixel point sequence in each neighborhood direction starts from the target pixel point and extends outward. Denote the pixel point sequence in any one of the neighborhood directions as , and the spectral values corresponding to the pixel point sequence are denoted as .
[0078] Furthermore, in step S2211, the degree of decrease of the spectral value of the target pixel point in each neighborhood direction is calculated, and the corresponding calculation formula is:
[0079]
[0080] where, represents the degree of decrease of the spectral value of the target pixel point in the neighborhood direction ; represents the spectral value of any pixel point in the neighborhood direction ; represents the distance from any pixel point in the neighborhood direction to the last pixel point in this neighborhood direction Spectral value; Represents a direct proportional normalization function.
[0081] It can be explained that the degree of decrease in the spectral value refers to the amplitude by which the spectral intensity decreases as the wavelength or frequency changes, and is used to measure spectral characteristics.
[0082] Make an explanation, Represents the neighborhood direction Any pixel point on The spectral value of, that is Represents the pixel point Any pixel point The spectral value of; Represents the neighborhood direction Any pixel point on To this neighborhood direction The last pixel point The spectral value of, that is Represents To The spectral value of the pixel point; Represents the pixel point And the sum of the differences between all pixel points after this pixel point. The greater the difference, the greater the degree of decrease; Represents the target pixel point In the neighborhood direction On, analyze the sum of the spectral value differences between each pixel point and all pixel points after these pixel points in sequence, that is, the degree of decrease in the spectral value.
[0083] Step S2212: Obtain the spot manifestation degree of the target pixel point according to the degree of decrease.
[0084] Specifically, still taking the target pixel point As the center, obtain the degree of decrease in the spectral values corresponding to each neighborhood direction In sequence, and record them as .
[0085] Furthermore, in step S2212, to obtain the spot manifestation degree of the target pixel point, the corresponding calculation formula is:
[0086]
[0087] Among them, Represents the spot manifestation degree of the target pixel point ; Represents the target pixel point In the neighborhood direction The degree of decrease in the spectral value on.
[0088] Make an explanation, Represents taking the target pixel point as the center 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.
[0089] 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.
[0090] 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.
[0091] 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.
[0092] 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 .
[0093] Further, in step S222, the spot expressiveness of the target pixel is corrected, and the corresponding calculation formula is:
[0094]
[0095] Wherein, represents the spot expressiveness of the corrected target pixel ; represents the spot expressiveness of the target pixel ; and respectively represent any set of adjacent edge chain codes in the cluster region where the target pixel is located; represents the last edge chain code in the cluster region where the target pixel is located; represents the variance of the non-zero terms in the edge chain codes of the cluster region where the target pixel is located; represents the inverse proportional normalization function; represents a constant term used to prevent the denominator from being zero.
[0096] It should be noted that represents the difference between two adjacent edge chain codes; represents the average difference of the adjacent edge chain codes in the cluster region . The smaller the difference, the smoother the edge of the cluster region , the better the spot expressiveness in this cluster region, indicating that the spot expressiveness of the target pixel in this cluster region is better; represents the variance of the non-zero terms in the edge chain codes of the cluster region where the target pixel is located, which is used to measure the dispersion degree of the spot expressiveness. The smaller the variance, the more regular the spot change of the edge of the cluster region , that is, the more in line with the spot performance; represents the last edge chain code in the cluster region where the target pixel is located. It should be noted that the edge chain code is used to describe the trend of the object edge 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 different cluster regions. Therefore, in some specific image structures and edge trends, the last edge chain code in the cluster region where the target pixel is located may be equal to 1. Therefore, the constant term is set to prevent the denominator from being zero.
[0097] Step S223: Select another non-target pixel point from the single food area as the auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point.
[0098] It can be explained that similarity refers to the degree of proximity between two pixel points in terms of color, brightness, and other visual features.
[0099] Understandably, for the target pixel point to be reconstructed, refer to other pixel points in the single food area i.e., the auxiliary pixel points for the filtering weight. The greater the similarity, the greater the filtering weight; the closer the distance between two pixel points, the greater the filtering weight.
[0100] Furthermore, in step S223, to calculate the similarity between the target pixel point and the auxiliary pixel point, the corresponding calculation formula is:
[0101]
[0102] where represents the similarity between the target pixel point and the auxiliary pixel point ; and respectively represent the spot manifestation degrees of the corrected target pixel point and the auxiliary pixel point ; represents the inverse proportional normalization function.
[0103] It should be noted that the smaller the spot manifestation degrees of the corrected target pixel point and the auxiliary pixel point , and the greater the non-spot manifestation degree, the more the two pixel points conform to the similarity; represents the difference in spot manifestation degrees between the target pixel point and the auxiliary pixel point . The smaller the difference between the two pixel points, the greater the similarity.
[0104] Step S224: Obtain the distance between the target pixel point and the auxiliary pixel point, and combine the similarity to obtain the filtering weight.
[0105] It can be explained that the closer the distance between the target pixel point and the auxiliary pixel point , the closer the positions of the two pixel points in the single food area, and at this time, their attributes such as color and brightness are more likely 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 point and the auxiliary pixel point.
[0106] Further, in step S224, the distance between the target pixel and the auxiliary pixel is obtained, and the filtering weight is obtained by combining the similarity. The corresponding calculation formula is:
[0107]
[0108] Among them, represents the filtering weight of the target pixel in the single food area with reference to the auxiliary pixel during the reconstruction process; represents the distance between the target pixel and the auxiliary pixel ; represents the similarity between the target pixel and the auxiliary pixel ; represents the inverse proportional normalization function.
[0109] It should be noted that represents the distance between the target pixel and the auxiliary pixel . The closer the distance, the higher the correlation between the two pixels in the single food area, and the greater the filtering weight. And represents the similarity between the target pixel and the auxiliary pixel . The greater the similarity, the more difficult it is to distinguish these two pixels visually. Therefore, when the bilateral filtering algorithm is used subsequently, the filtering weight is also greater.
[0110] Further, in step S3, the pixels in the single food area are reconstructed based on the filtering weight, and the spectral value of the pixel after reconstruction is obtained, including:
[0111] Define each non-target pixel in the single food area as an auxiliary pixel, and denote each auxiliary pixel respectively , and the filtering weights of each auxiliary pixel are obtained in sequence as , and the spectral values of each auxiliary pixel are obtained in sequence as ;
[0112] Obtain the spectral value of the pixel after reconstruction. The corresponding calculation formula is:
[0113]
[0114] Among them, represents the spectral value of the target pixel after reconstruction; represents in the single food area Among them, the target pixel point During the reconstruction process, refer to any auxiliary pixel point for its filtering weight; represents the number of auxiliary pixel points; represents the target pixel point for which reconstruction is required represents any auxiliary pixel point for its spectral value.
[0115] Make an explanation represents the weight ratio of the original spectral value that has not been reconstructed, that is, it reflects the influence of the original data on the data that needs to be reconstructed after reconstruction, so as to indicate which data will be given priority during the reconstruction process; represents any auxiliary pixel point for its filtering weight ratio, so as to effectively adjust the local features of the target image. It is used to ensure that the initial image with the background area segmented reaches the purpose of optimizing the image quality after filtering; and by optimizing the allocation of the weight ratio of each data, the accuracy and stability of food impurity detection can be effectively improved.
[0116] It can be explained that in step S4, after determining the spectral values of all pixel points in the target image after reconstruction and performing filtering processing, the target image can be smoothed, noise interference can be reduced, specific features in the target image can be enhanced, and it is convenient to more clearly identify the impurity food in the target image in the subsequent process; according to the difference analysis, the impurity food is identified and marked, that is, the impurity food is clearly marked on the target image, so that the staff can quickly identify the impurity food; among them, the difference analysis refers to a detailed study and comparison of the differences between two or more objects, data sets or situations.
[0117] Please refer to Figure 5 , which shows the filtered spectral image of the mixture of normal soybeans and impurity soybeans of a food impurity detection method based on spectral technology provided by an embodiment of the present invention.
[0118] Specifically, based on the above step principle, all spectral images in the 400 - 1000nm band are filtered, so as to increase the difference between normal soybeans and impurity soybeans in the hyperspectral image, making the features of impurity 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 work.
[0119] Understandably, in this application, the background area in the food image is first segmented through the highlighting feature of the background area, and then each single food area is framed; according to the feature that the spectral values of the pixel points in the food area decrease towards the surroundings, the spot expressiveness is calculated, and the spot expressiveness of the edge spot pixel points is corrected to improve the recognition accuracy; according to the distinguishing features between normal food and impurity food, the filtering weight is calculated to exclude the interference of normal food on the recognition of impurity food, and finally the image is reconstructed to improve the image quality. Based on the spectral value change differences between impurity food and normal food in the hyperspectral image, the impurity food is identified and labeled, so as to effectively identify the impurity food in the mixed food, which not only improves the efficiency of food detection, but also ensures the safety of food, providing strong support for subsequent food quality control and safety detection.
[0120] It should be noted that the above order of the embodiments of the present invention is only for description and does not represent the superiority or inferiority 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.
[0121] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the differences from other embodiments.
Claims
1. A food impurity detection method based on spectral technology, characterized in that, The method includes: Collect an image of a mixture of normal food and contaminated food, and perform preprocessing to generate an initial image; Perform background segmentation on the initial image to obtain a target image. Based on the target image, perform edge detection to screen out single-food regions, and use the bilateral filtering algorithm to calculate the filtering weights of pixel points for the single-food regions; Reconstruct the pixel points in the single-food regions based on the filtering weights to obtain the spectral values of the pixel points after reconstruction; Determine the spectral values of all pixel points in the target image after reconstruction. After performing filtering processing, identify the contaminated food according to differential analysis and perform annotation; Using the bilateral filtering algorithm to calculate the filtering weights of pixel points for the single-food regions includes: Define any pixel point in the single-food region as a target pixel point, and determine the spot expressiveness of the target pixel point; Determine the spot expressiveness of all pixel points in the single-food region. According to the distribution of the spot expressiveness, cluster the single-food region to determine the cluster region of the target pixel point, and judge whether the target pixel point is an edge spot pixel point. If so, correct the spot expressiveness of the target pixel point; Select another non-target pixel point from the single-food region as an auxiliary pixel point, and calculate the similarity between the target pixel point and the auxiliary pixel point; Obtain the distance between the target pixel point and the auxiliary pixel point, and combine the similarity to obtain the filtering weight; Determining the spot expressiveness of the target pixel point includes: Taking the target pixel point as the center, select several pixel points in each neighborhood direction of it, and sequentially obtain the spectral values of each pixel point, and calculate the degree of decrease in the spectral value of the target pixel point in each neighborhood direction; Obtain the spot expressiveness of the target pixel point according to the degree of decrease; 2. The method for detecting food impurities based on spectroscopic technology according to claim 1, characterized in that, Performing background segmentation on the initial image to obtain a target image. Based on the target image, performing edge detection to screen out single-food regions includes: Set a segmentation threshold, screen out the pixel points in the initial image that exceed the segmentation threshold as the background region, and exclude them to obtain the target image; Perform edge detection based on the target image to identify the food edges and screen out the single-food regions; 3. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The formula for calculating the degree of decrease in the spectral value of the target pixel point in each neighborhood direction is: Among them, represents the target pixel point in the neighborhood direction of the degree of decrease in the spectral value; represents the neighborhood direction any pixel point of the spectral value; represents the neighborhood direction any pixel point to the neighborhood direction the last pixel point of the spectral value; represents the proportional normalization function.
4. The food impurity detection method based on spectral technology according to claim 1, characterized in that The formula for obtaining the spot expressiveness of the target pixel point is: Among them, represents the spot manifestation degree of the target pixel point ; represents the degree of decrease in the spectral value of the target pixel point in the neighborhood direction ; 5. The method for detecting food impurities based on spectroscopic technology according to claim 1, characterized in that, The formula for correcting the spot expressiveness of the target pixel point is: Among them, represents the spot expressiveness of the corrected target pixel point ; represents the spot expressiveness of the target pixel point ; and respectively represent any group of adjacent edge chain codes in the cluster region where the target pixel point is located; represents the last edge chain code in the cluster region where the target pixel point is located; represents the variance of non-zero terms in the edge chain codes of the cluster region where the target pixel point is located; represents the inverse proportional normalization function; represents a constant term used to prevent the denominator from being zero.
6. The food impurity detection method based on spectral technology according to claim 1, characterized in that, The formula for calculating the similarity between the target pixel point and the auxiliary pixel point is: Among them, represents the similarity between the target pixel point and the auxiliary pixel point ; and respectively represent the spot manifestation degrees of the corrected target pixel point and the auxiliary pixel point ; represents the inverse proportional normalization function.
7. The food impurity detection method based on spectral technology according to claim 1, characterized in that The formula for obtaining the distance between the target pixel point and the auxiliary pixel point and combining the similarity to obtain the filtering weight is: Among them, represents the filtering weight of the reference auxiliary pixel point in the single food area during the reconstruction process for the target pixel point; ; represents the distance between the target pixel point and the auxiliary pixel point; represents the similarity between the target pixel point and the auxiliary pixel point; represents the inverse proportional normalization function.
8. The food impurity detection method based on spectral technology according to claim 1, characterized in that Reconstructing the pixel points in the single-food regions based on the filtering weights to obtain the spectral values of the pixel points after reconstruction includes: Define a single food area Each non-target pixel in is an auxiliary pixel, and each auxiliary pixel is respectively denoted , and the filtering weights of each auxiliary pixel are obtained in sequence as , and the spectral values of each auxiliary pixel are in sequence as ; The formula for obtaining the spectral value of the pixel point after reconstruction is: Among them, represents the target pixel The spectral value after reconstruction; represents in a single food area Among them, the target pixel During the reconstruction process, referring to any auxiliary pixel Filtering weight; Represents the number of auxiliary pixels; Represents the target pixel that needs to be reconstructed Spectral value; Represents any auxiliary pixel Spectral value.
Citation Information
Patent Citations
Method for detecting impurities in preserved vegetables based on hyperspectral image acquisition system
CN111008970A
Dam termite damage identification method and system based on infrared characteristic attributes
CN118918532A
Cited By
Food impurity detection method based on spectrum technology
CN122089666A