A rapid quality detection method for dehydrated vegetables based on image data
Through grayscale image processing and shadow weight analysis, the threshold is adjusted for iterative segmentation, which solves the problem of poor segmentation of dehydrated vegetables and achieves more accurate mold detection and quality assessment.
Patent Information
- Application Number
- CN202410930983.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-12
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2044-07-12
AI Technical Summary
In the existing technology, the segmentation effect of dehydrated vegetables is poor, resulting in large errors in mold detection results and poor quality detection results. This is mainly because the grayscale of the shadow part and the mold part are relatively similar, making it difficult to effectively segment.
By obtaining the grayscale image of the vegetable surface, determine the initial threshold and the main peak and secondary peak grayscale levels in the grayscale histogram, combine the shadow weight and local grayscale distribution, adjust the threshold for iterative segmentation, and reduce the impact of the shadow part on the segmentation. Finally, Obtain accurate segmentation thresholds for quality detection.
It improves the segmentation effect, reduces the interference of shadow parts on detection, makes the mildew detection results more accurate, and improves the accuracy and effect of dehydrated vegetable quality detection.
Smart Images

Figure CN118470019B
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of area division, and in particular to a method for quickly detecting the quality of dehydrated vegetables based on image data. Background Art
[0002] Dehydrated vegetables are widely used in fast food because of their convenience in production, long storage time and little impact from the storage environment. With the development of the dehydrated vegetable manufacturing industry, its quality inspection standards are becoming more and more complete, such as the water content, size, and mold spots of dehydrated vegetables. If the product quality does not meet the standards, such as moldy vegetables being made into dried vegetables, it will affect the quality of the final product, so it is particularly important to conduct quality inspections.
[0003] Due to the complex surface features of vegetables after dehydration, the shadow part produced by the wrinkles after dehydration is close to the grayscale of the mold part. When segmenting with the existing single threshold, the interference of the shadow part cannot be avoided, resulting in poor segmentation effect. The error of detecting mold spots through the segmentation results is large, resulting in poor quality detection effect. Summary of the invention
[0004] In order to solve the technical problem that the segmentation effect in the prior art is poor, the error of the mold spot detection result through the segmentation result is large, resulting in poor quality detection effect, the purpose of the present invention is to provide a method for rapid quality detection of dehydrated vegetables based on image data, and the technical scheme adopted is as follows:
[0005] The present invention provides a method for quickly detecting the quality of dehydrated vegetables based on image data, the method comprising:
[0006] Obtain a grayscale image of the vegetable surface; determine an initial threshold value according to the grayscale value in the vegetable surface grayscale image to obtain a low grayscale area; determine a main peak grayscale level and a secondary peak grayscale level according to a grayscale level change in a grayscale histogram corresponding to the vegetable surface grayscale image; the secondary peak grayscale level is located in the low grayscale area;
[0007] In the preset grayscale range of the secondary peak grayscale, based on the difference in the local grayscale distribution of the pixels corresponding to each grayscale and combined with the number of pixels in the low grayscale area, the difference ratio within the preset grayscale range of the secondary peak grayscale is obtained; according to the difference ratio of the secondary peak grayscale and the local grayscale distribution offset of the secondary peak grayscale, as well as the difference between the secondary peak grayscale and the main peak grayscale, the shadow weight of the secondary peak grayscale is obtained;
[0008] According to the difference between each gray level in the preset gray level range of the sub-peak gray level and the sub-peak gray level, the distribution of each gray level in the low gray level area, and the shadow weight, the adjustment amount of each gray level in the preset gray level range is obtained; based on the adjustment amount of each gray level in the preset gray level range of the sub-peak gray level, combined with the quantity distribution of each gray level in the low gray level area, the adjusted gray level mean value of the low gray level area is obtained;
[0009] The initial threshold is adjusted according to the adjusted grayscale mean of the low grayscale area, and a new low grayscale area is obtained for iterative segmentation. The process stops when the change of the initial threshold is less than the preset threshold, and the final segmentation threshold is obtained. The quality of the vegetable surface grayscale image division is inspected according to the final segmentation threshold.
[0010] Furthermore, the method of determining an initial threshold value according to the grayscale value in the vegetable surface grayscale image to obtain a low grayscale area includes:
[0011] Calculate the average value between the maximum grayscale value and the minimum grayscale value in the vegetable surface grayscale image to obtain the initial threshold;
[0012] The low grayscale area in the vegetable surface grayscale image is determined according to the initial threshold, and the grayscale levels of the pixels in the low grayscale area are all less than the initial threshold.
[0013] Further, the determining of the main peak grayscale level and the secondary peak grayscale level according to the grayscale level change in the grayscale histogram corresponding to the vegetable surface grayscale image includes:
[0014] Obtain all peaks in the grayscale histogram corresponding to the grayscale image of the vegetable surface; take the peak with the largest number of pixels as the main peak, and the grayscale level corresponding to the peak value of the main peak as the main peak grayscale level;
[0015] Among the peaks other than the main peak, the peak with the second highest number of pixels and the corresponding gray level in the low gray area is selected as the secondary peak, and the gray level of the secondary peak corresponding to the peak is the secondary peak gray level.
[0016] Furthermore, the method for obtaining the difference ratio includes:
[0017] Obtain the mean value of the gradient direction of all pixels in the grayscale image of the vegetable surface, and use the direction of the straight line corresponding to the mean value as the detection direction;
[0018] Sequentially use each pixel point corresponding to a gray level in a preset gray level range as a detection pixel point, and use the preset number of pixels to the left and right of the detection pixel point in the detection direction as analysis pixels for the detection pixel point;
[0019] Calculate the cumulative value of the gray value difference between the detection pixel and each analysis pixel; when the cumulative value is greater than the preset difference threshold, take the detection pixel as the difference pixel; count the number of all difference pixels in the preset gray level range of the sub-peak gray level as the difference number;
[0020] The ratio of the number of differences to the total number of all pixels in the low grayscale area is taken as the difference ratio within the preset grayscale range of the sub-peak grayscale.
[0021] Furthermore, the method for obtaining the shadow weight includes:
[0022] Calculating the skewness of the preset grayscale range of the sub-peak grayscale as a deviation index corresponding to the sub-peak grayscale;
[0023] The difference in the number of pixels corresponding to the secondary peak gray level and the primary peak gray level is used as the quantity difference index corresponding to the secondary peak gray level;
[0024] According to the offset index, quantity difference index and difference proportion corresponding to the sub-peak gray level, the shadow weight of the sub-peak gray level is obtained; the offset index and the difference proportion are positively correlated with the shadow weight, and the quantity difference index is negatively correlated with the shadow weight.
[0025] Furthermore, the method for obtaining the adjusted quantity includes:
[0026] The gray levels within the preset gray level range of the sub-peak gray level are sequentially taken as the target gray level, the difference in the corresponding gray level between the target gray level and the sub-peak gray level is calculated, and negative correlation mapping and normalization processing are performed to obtain the adjustment weight of the target gray level;
[0027] The ratio of the number of pixels in the target grayscale to the total number of pixels in the low grayscale area is used as the adjustment ratio of the target grayscale; the product of the increase weight of the target grayscale, the adjustment ratio and the shadow weight of the sub-peak grayscale is negatively correlated and normalized to obtain the adjustment degree of the target grayscale;
[0028] The product of the number of pixels in the target grayscale and the adjustment degree is calculated to obtain the adjustment amount of the target grayscale.
[0029] Furthermore, the method for obtaining the adjusted grayscale mean value includes:
[0030] Calculate the product of the adjustment amount of each gray level in the preset gray level range of the sub-peak gray level and the corresponding gray level to obtain the adjusted gray value of each gray level in the preset gray level range; add the adjusted gray values of all gray levels in the preset gray level range to obtain a first gray accumulated value;
[0031] The product of each gray level except the preset gray level range in the low gray level area and the number of corresponding pixels is used as the unadjusted gray value of each gray level; the unadjusted gray values of all gray levels are added to obtain a second gray accumulated value;
[0032] The sum of the first grayscale accumulated value and the second grayscale accumulated value is used as the total grayscale value of the low grayscale area; the ratio of the total grayscale value to the total number of pixels in the low grayscale area is calculated to obtain the adjusted grayscale mean of the low grayscale area.
[0033] Furthermore, the adjusting the initial threshold according to the adjusted grayscale mean of the low grayscale area to obtain a new low grayscale area for iterative segmentation includes:
[0034] Obtain the grayscale mean of all pixels in the non-low grayscale area; calculate the average value between the adjusted grayscale mean of the low grayscale area and the grayscale mean of the non-low grayscale area as a new initial threshold;
[0035] The area composed of pixels whose grayscale values are lower than the new initial threshold is taken as the new low grayscale area, and iterative segmentation is performed to obtain the new initial threshold and the new low grayscale area.
[0036] Furthermore, the step of stopping until the change degree of the initial threshold is less than a preset threshold to obtain the final segmentation threshold comprises:
[0037] If the difference between the initial threshold of the current iteration and the initial threshold of the previous iteration is less than the preset threshold, the iteration is stopped and the initial threshold of the last iteration is used as the final segmentation threshold.
[0038] Furthermore, the quality detection of the vegetable surface grayscale image segmentation according to the final segmentation threshold comprises:
[0039] The area in the vegetable surface grayscale image where the grayscale value is less than the final segmentation threshold is taken as the area to be detected; the area in the vegetable surface grayscale image where the grayscale value is greater than the final segmentation threshold is taken as the normal area;
[0040] Calculate the grayscale average value of the area to be detected as the minimum grayscale average value, and calculate the grayscale average value of the normal area as the maximum grayscale average value;
[0041] When the difference between the minimum grayscale mean and the maximum grayscale mean is greater than the preset grayscale difference threshold, the quality of the dehydrated vegetables corresponding to the grayscale image of the vegetable surface is recorded as unqualified; when the difference between the minimum grayscale mean and the maximum grayscale mean is less than or equal to the preset grayscale difference threshold, the quality of the dehydrated vegetables corresponding to the grayscale image of the vegetable surface is recorded as qualified.
[0042] The present invention has the following beneficial effects:
[0043] The present invention first obtains the initial low grayscale area in the grayscale image of the vegetable surface. Considering that the mold spots and shadow parts are both in the low grayscale part with a lower grayscale in the grayscale image of the vegetable surface, and the dehydrated vegetable surface has a large number of wrinkles, the number of pixels in the shadow part will be second only to the main part of the vegetable. Therefore, the main peak grayscale and the secondary peak grayscale of the shadow part are determined by the grayscale change in the grayscale histogram. Further, in the preset grayscale range of the secondary peak grayscale, combined with the characteristics of the shadow pixel points, the shadow weight of the secondary peak grayscale is obtained by the grayscale distribution difference of the grayscale corresponding pixel points in the preset grayscale range and the local grayscale distribution offset of the secondary peak grayscale, as well as the difference with the main peak. The shadow weight can reflect the proportion of the shadow, so as to reduce the influence of the shadow part on the segmentation in the future. Further, in the low grayscale area, the grayscale distribution of all grayscale levels within the preset grayscale range of the sub-peak grayscale level is analyzed, and the number of grayscale levels is adjusted in combination with the shadow weight, so that the number of pixels with a greater possibility of shadows is reduced, reducing their influence on the grayscale value analysis, and the adjusted number is combined with the distribution of all grayscale levels in the low grayscale area to obtain the adjusted grayscale mean after reducing the influence of the pixels in the shadow part. Adjusting the grayscale mean can adjust the initial threshold to obtain a new low grayscale area, iteratively reduce the influence of the shadow part, and finally obtain a more accurate final segmentation threshold, and then divide the detection quality according to the final segmentation threshold for better effect. The present invention improves the segmentation effect by reducing the interference of the grayscale value of the pixels in the shadow part on the segmentation, so that the result of detecting mildew spots through the segmentation result is more accurate, and then the effect of quality detection is better. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] 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.
[0045] Figure 1 A flow chart of a method for rapid quality detection of dehydrated vegetables based on image data provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0046] 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 method for rapid detection of dehydrated vegetable quality based on image data 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.
[0047] 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.
[0048] The specific scheme of the method for rapid quality detection of dehydrated vegetables based on image data provided by the present invention is described in detail below with reference to the accompanying drawings.
[0049] See also Figure 1 , which shows a flow chart of a method for rapid quality detection of dehydrated vegetables based on image data provided by an embodiment of the present invention, the method comprising the following steps:
[0050] S1: Obtain a grayscale image of the vegetable surface; determine an initial threshold value according to the grayscale value in the vegetable surface grayscale image to obtain a low grayscale area; determine the main peak grayscale level and the secondary peak grayscale level according to the grayscale level change in the grayscale histogram corresponding to the vegetable surface grayscale image; the secondary peak grayscale level is located in the low grayscale area.
[0051] In an embodiment of the present invention, after the dehydrated vegetable baking stage, the dehydrated vegetables are collected by a camera on a conveyor belt to obtain a vegetable surface image. In order to facilitate the analysis of only the shadow part with a lower grayscale value, the vegetable surface image is preprocessed to obtain a vegetable surface grayscale image. Among them, the image preprocessing process mainly includes grayscale processing, filtering denoising processing and background removal processing of the vegetable surface image. It should be noted that the preprocessing processes such as grayscale processing, filtering denoising processing and background removal processing are technical means well known to those skilled in the art, such as weighted average grayscale method, bilateral filtering method and background difference method, etc., which will not be described in detail here.
[0052] Since wrinkles will appear on the surface of dehydrated vegetables, and the wrinkled part will bring shadow areas, and since the grayscale values of the pixels in the shadow area are similar to those of the corresponding pixels in the moldy part, the grayscale image of the vegetable surface can be initially segmented to obtain the part representing the shadow or moldy part, that is, the initial threshold is determined according to the grayscale value in the grayscale image of the vegetable surface to obtain the low grayscale area. Preferably, the average value between the maximum grayscale value and the minimum grayscale value in the grayscale image of the vegetable surface is calculated to obtain the initial threshold, and the initial segmentation is performed according to the maximum and minimum grayscale values. The low grayscale area in the grayscale image of the vegetable surface is determined according to the initial threshold, and the grayscale levels of the pixels in the low grayscale area are all less than the initial threshold, that is, the pixels in the grayscale image of the vegetable surface whose grayscale values are lower than the initial threshold are taken as pixels in the low grayscale area, and the low grayscale area includes the shadow and moldy part.
[0053] Furthermore, in the grayscale histogram corresponding to the grayscale image of the vegetable surface, since the main part of the vegetable accounts for the largest proportion in the image, followed by the shadow part, a multi-peak feature will appear in the grayscale histogram. In an embodiment of the present invention, the horizontal axis of the grayscale histogram represents the grayscale level, and the vertical axis represents the number of pixels. The acquisition of the grayscale histogram is a technical means well known to those skilled in the art, and will not be described in detail here. The main peak grayscale level and the secondary peak grayscale level are determined according to the grayscale level changes in the grayscale histogram corresponding to the grayscale image of the vegetable surface.
[0054] Preferably, all peaks in the grayscale histogram corresponding to the grayscale image of the vegetable surface are obtained, that is, the number of pixels corresponding to the local maximum, and the peak with the largest number of pixels is taken as the main peak, and the grayscale corresponding to the peak is the main peak grayscale, and the main peak grayscale reflects the grayscale gathering of the main pixel points of the vegetable. Among the peaks other than the main peak, the peak with the second highest number of pixels and the corresponding grayscale in the low grayscale area is selected as the secondary peak, and the secondary peak is also the secondary peak. Since the shadow part occupies the largest proportion on the surface of the dehydrated vegetable except the main part, the secondary peak is found in the low grayscale area for analysis, and the grayscale corresponding to the peak is the secondary peak grayscale, and the secondary peak grayscale is the grayscale gathering of the pixels corresponding to the shadow part. It should be noted that the acquisition of the peak is a well-known technical means well known to those skilled in the art, that is, the acquisition of the local maximum, which will not be repeated here.
[0055] At this point, the preliminary analysis of the grayscale image of the vegetable surface is completed, the shadow part after the preliminary division is screened out, and the initial threshold of the division is further adjusted according to the possible degree of the shadow.
[0056] S2: In the preset grayscale range of the sub-peak grayscale, based on the difference in local grayscale distribution of pixels corresponding to each grayscale and combined with the number of pixels in the low grayscale area, obtain the difference ratio within the preset grayscale range of the sub-peak grayscale; according to the difference ratio of the sub-peak grayscale and the local grayscale distribution offset of the sub-peak grayscale, as well as the difference between the sub-peak grayscale and the main peak grayscale, obtain the shadow weight of the sub-peak grayscale.
[0057] Since the sub-peak grayscale may also include a mildew area, and in the embodiment of the present invention, the influence of the shadow part is continuously reduced through iterative analysis, it is necessary to analyze the shadow possibility of the obtained sub-peak grayscale and make appropriate adjustments based on the possibility.
[0058] Firstly, since the shadow part is in the grayscale gradient area in the image, the grayscale level also has regional range in the grayscale histogram. Therefore, analysis is performed in the preset grayscale range of the sub-peak grayscale level, and it is considered that the grayscale level in the preset grayscale range also has a certain shadow part that needs to be adjusted. In an embodiment of the present invention, the preset grayscale range is a range composed of 3 grayscale levels on the left and right of the sub-peak grayscale level as the center, that is, the preset grayscale range of the sub-peak grayscale is the range corresponding to the 7 grayscale levels in the grayscale histogram. The specific range size can be adjusted by the implementer according to the specific implementation situation.
[0059] In the preset grayscale range of the sub-peak grayscale, based on the local grayscale distribution difference of the pixel points corresponding to each grayscale, combined with the number of pixels in the low grayscale area, the difference proportion within the preset grayscale range of the sub-peak grayscale is obtained, and the characteristics of the distribution of the shadow pixels having large differences in the local area are first analyzed. Preferably, the mean of the gradient direction of all pixels in the grayscale image of the vegetable surface is obtained, and the straight line direction corresponding to the mean is used as the detection direction. Due to the influence of the acquisition light source, the shadow is usually evenly distributed in one direction. Therefore, by obtaining the mean direction of the gradient direction, the direction of change of the grayscale value of the shadow part is obtained, and the proportion of pixels with distribution differences can be obtained by the degree of grayscale change in this direction. For example, when the mean of the gradient direction is horizontal to the right, the horizontal direction is the detection direction. It should be noted that the acquisition of the gradient direction and the selection of the mean of the gradient direction are technical means well known to those skilled in the art, and will not be repeated here. In other embodiments of the present invention, the gradient direction corresponding to the maximum value of the gradient amplitude of all pixels can also be used as the detection direction, which is not limited here.
[0060] Further, each pixel corresponding to the gray level in the preset gray level range is sequentially used as a detection pixel, and the preset number of pixels to the left and right of the detection pixel in the detection direction are used as analysis pixels for the detection pixel. In an embodiment of the present invention, the preset number of pixels is set to 5. For example, when the detection direction is the horizontal direction, 5 pixels to the left and right of the detection pixel in the horizontal direction are used as analysis pixels for the detection pixel, that is, the detection pixel corresponds to 10 analysis pixels.
[0061] Furthermore, the cumulative value of the gray value difference between the detection pixel and each analysis pixel is calculated. When the cumulative value is greater than the preset difference threshold, it means that the detection pixel has a large grayscale difference in the direction of the shadow grayscale change. The detection pixel is used as a difference pixel, that is, a pixel that may be a shadow. In the embodiment of the present invention, the preset difference threshold is set to 50, and the specific value can be adjusted by the implementer according to the specific implementation situation. The number of all difference pixels in the preset grayscale range of the sub-peak grayscale is counted as the difference number, which is the number of pixels with shadow characteristics in the grayscale change in the possible shadow part. The ratio of the difference number to the total number of all pixels in the low grayscale area is used as the difference ratio within the preset grayscale range of the sub-peak grayscale.
[0062] Secondly, since the shadow part is caused by wrinkles, the gray value of the shadow part changes gradually, that is, the gray value changes from dark to light, and the gray level peak in the gray level histogram shows a deviation from the normal distribution. And since dehydrated vegetables are formed by continuous wrinkles, the number of gray levels corresponding to the shadow part is also large, which is close to the number of pixels in the main vegetable part. Combining these two shadow features with the gray distribution features, the shadow weight is obtained, that is, according to the difference proportion of the sub-peak gray level and the local gray distribution offset of the sub-peak gray level, as well as the difference between the sub-peak gray level and the main peak gray level, the shadow weight of the sub-peak gray level is obtained. The shadow weight reflects the possibility of seeing the sub-peak gray level as a shadow.
[0063] Preferably, the skewness of the preset grayscale range of the secondary peak grayscale is calculated as the offset index corresponding to the secondary peak grayscale, and the offset index reflects the offset degree of the peak corresponding to the secondary peak. In an embodiment of the present invention, the expression of the offset index is:
[0064]
[0065] In the formula, It is expressed as the offset index corresponding to the sub-peak gray level, The total number of pixels in the preset grayscale range represented as the sub-peak grayscale, Indicated as the first gray level in the preset gray level range of the sub-peak gray level The gray value of each pixel, that is, the gray level size, It is represented as the mean gray value of the pixel points in the preset gray level range of the sub-peak gray level, It is expressed as the gray value variance of the pixel points in the preset gray level range of the sub-peak gray level, It is expressed as an absolute value extraction function. It should be noted that the calculation of skewness is a public technical formula familiar to those skilled in the art, so the specific meaning of the formula will not be repeated.
[0066] The difference in the number of pixels corresponding to the secondary peak grayscale and the main peak grayscale is used as the quantity difference index corresponding to the secondary peak grayscale. The quantity difference index reflects the degree of difference between the number of pixels corresponding to the secondary peak grayscale and the number corresponding to the main peak grayscale. The smaller the difference, the more likely it is the shadow part.
[0067] The shadow weight of the sub-peak grayscale is obtained according to the offset index, the quantity difference index and the difference ratio. The shadow weight is the possibility of the shadow part at the corresponding position of the sub-peak grayscale. The greater the possibility, the more shadow pixels there are. The offset index and the difference ratio are both positively correlated with the shadow weight, and the quantity difference index is negatively correlated with the shadow weight. In the embodiment of the present invention, the expression of the shadow weight is:
[0068]
[0069] In the formula, Expressed as the shading weight of the sub-peak gray level, It is expressed as the offset index corresponding to the sub-peak gray level, It is represented by the number of pixels corresponding to the main peak gray level. It is expressed as the number of pixels corresponding to the sub-peak gray level. Expressed as the number of differences, It is expressed as the total number of pixels in the low grayscale area. Expressed as an absolute value extraction function, It is represented as an adjustment parameter and is set to 0.001 in the embodiment of the present invention, in order to prevent the denominator from being zero, which makes the formula meaningless.
[0070] in, It is expressed as the quantitative difference index corresponding to the sub-peak gray level, It is expressed as the difference ratio corresponding to the secondary peak grayscale. When the offset index is larger, it means that the deviation state of the secondary peak corresponding to the peak is more obvious, and it corresponds more to the grayscale gradient characteristics corresponding to the shadow part, so the shadow possibility is greater, that is, the shadow weight is greater. When the difference ratio is larger, it means that there are more pixels with grayscale difference at the secondary peak grayscale, and the proportion of pixels that may be shadow parts in the low grayscale area is larger, the shadow possibility is greater, that is, the shadow weight is greater. When the quantity difference index is smaller, it means that the number of pixels in the shadow part is more, and it is closer to the main peak number, so the shadow possibility is greater, that is, the shadow weight is greater.
[0071] At this point, the analysis of the possibility of the shadow part is completed. The larger the shadow proportion is, the greater the impact of reducing the grayscale value of the pixel point. Therefore, the segmentation grayscale value is further adjusted by the shadow weight.
[0072] S3: Obtain the adjustment quantity of each grayscale level in the preset grayscale range according to the difference between each grayscale level in the preset grayscale range of the sub-peak grayscale level and the sub-peak grayscale level, the distribution of each grayscale level in the low grayscale area, and the shadow weight; obtain the adjusted grayscale mean of the low grayscale area based on the adjustment quantity of each grayscale level in the preset grayscale range of the sub-peak grayscale level and the quantity distribution of each grayscale level in the low grayscale area.
[0073] Since the preset grayscale range of the sub-peak grayscale is represented as the possible grayscale range of the shadow part, the influence of the proportion of each grayscale in the preset grayscale range is reduced, and the grayscale level that is closer to the sub-peak grayscale level is considered to have a greater degree of increase. Therefore, the adjustment amount of each grayscale level in the preset grayscale range is obtained according to the difference between each grayscale level and the sub-peak grayscale level in the preset grayscale range of the sub-peak grayscale level, the distribution of each grayscale level in the low grayscale area, and the shadow weight.
[0074] Preferably, the gray levels within the preset gray level range of the sub-peak gray level are taken as target gray levels in turn, each gray level in the preset gray level range is analyzed, the difference in corresponding gray level sizes between the target gray level and the sub-peak gray level is calculated, and negative correlation mapping and normalization processing are performed to obtain the adjustment weight of the target gray level. The distance between the gray level and the sub-peak gray level is reflected by the difference in gray level size. The smaller the distance, the closer the target gray level is to the sub-peak gray level, and the more credible the adjustment degree is, so the larger the adjustment weight needs to be.
[0075] The ratio of the number of pixels in the target grayscale to the total number of pixels in the low grayscale area is used as the adjustment ratio of the target grayscale. The larger the target grayscale ratio is, the more adjustment is required. The product of the target grayscale increase weight, the adjustment ratio and the shadow weight of the sub-peak grayscale is negatively correlated and normalized to obtain the adjustment degree of the target grayscale. The larger the adjustment weight, the larger the adjustment ratio and the larger the shadow weight, the more adjustments are made to the target grayscale. The adjustment degree is a normalized value, so the smaller the adjustment degree is, the more the quantity is adjusted.
[0076] The product of the number of pixels in the target gray level and the adjustment degree is calculated to obtain the adjustment amount of the target gray level. The influence of the pixels in the possible shadow part in each gray level is reduced by the adjustment amount. In the embodiment of the present invention, the expression of the adjustment amount is:
[0077]
[0078] In the formula, Expressed as The number of gray levels to adjust. Expressed as The grayscale size of gray levels, It is expressed as the gray level size of the sub-peak gray level, Expressed as The number of grayscale pixels, It is expressed as the total number of pixels in the low grayscale area. Expressed as the shading weight of the sub-peak gray level, Expressed as an absolute value extraction function, Expressed as an exponential function with a natural constant as base, It is expressed as a normalization function. It should be noted that normalization is a technical means well known to those skilled in the art. The normalization function can be linear normalization or standard normalization, etc. The specific normalization method is not limited here.
[0079] in, Expressed as The adjustment weight of the gray level, Expressed as The adjustment ratio of gray levels is Expressed as The adjustment degree of each gray level. When the adjustment weight is larger, it means that the target gray level is closer to the secondary peak gray level, and the adjustment credibility is higher. When the adjustment proportion is larger, it means that the proportion of the target gray level is larger. When the shadow weight is larger, it means that the target gray level corresponds to the shadow part to a greater extent, and more adjustments are needed. Therefore, when the adjustment weight is larger, the adjustment proportion is larger, the shadow weight is larger, and the adjustment degree is smaller. Since the adjustment degree is a value normalized by an exponential function with a natural constant as the base, the smaller the adjustment degree is, the greater the degree of reduction in quantity is. Therefore, when the adjustment degree is smaller, the obtained adjustment quantity is smaller.
[0080] Furthermore, based on the adjusted number and other unadjusted numbers of gray levels, the adjusted grayscale average value of the low grayscale area is obtained, that is, the adjusted number of each grayscale level in the preset grayscale range based on the sub-peak grayscale level is combined with the quantity distribution of each grayscale level in the low grayscale area to obtain the adjusted grayscale mean value of the low grayscale area.
[0081] Preferably, the product of the adjustment amount of each gray level in the preset gray level range of the sub-peak gray level and the corresponding gray level is calculated to obtain the adjusted gray value of each gray level in the preset gray level range, that is, the gray level corresponding to the gray level after the influence of the pixels of the shadow part is reduced. The adjusted gray values of all gray levels in the preset gray level range are added to obtain a first gray level cumulative value, which is the total gray level value corresponding to the gray level after reducing the influence of the gray value of the shadow part.
[0082] The product of each grayscale level except the preset grayscale range in the low grayscale area and the corresponding number of pixels is taken as the unadjusted grayscale value of each grayscale level, and the unadjusted grayscale values of all grayscale levels are added to obtain a second grayscale cumulative value, which is the total grayscale value corresponding to the unadjusted grayscale level.
[0083] The sum of the first grayscale cumulative value and the second grayscale cumulative value is used as the total grayscale value of the low grayscale area, and the ratio of the total grayscale value to the total number of pixels in the low grayscale area is calculated to obtain the adjusted grayscale mean of the low grayscale area. The adjusted grayscale mean is reduced by the ratio to the original total number to highlight the more obvious low grayscale mildew area. In the embodiment of the present invention, the expression for adjusting the grayscale mean is:
[0084]
[0085] In the formula, It is expressed as the adjusted grayscale mean of the low grayscale area, Expressed as The number of gray levels to adjust. Expressed as The grayscale size of gray levels, The total number of gray levels in the preset gray level range expressed as the sub-peak gray level, It is expressed as the total number of gray levels in the low gray area except for the preset gray level range. Expressed as The number of pixels corresponding to each gray level, is the index value, Represented as the total number of pixels in the low grayscale area.
[0086] in, Expressed as Adjust the grayscale value of the gray level. Represented as the first grayscale accumulated value, Expressed as The unadjusted gray value of gray levels, Represented as the second grayscale accumulated value, It is expressed as the total gray value of the low gray area. By reducing the gray influence of the pixels in the shadow part, the division threshold is adjusted so that the division threshold is adjusted for the part closer to the mold defect.
[0087] S4: Adjust the initial threshold according to the adjusted grayscale mean of the low grayscale area, obtain a new low grayscale area for iterative segmentation, and stop when the change degree of the initial threshold is less than the preset threshold to obtain the final segmentation threshold; perform quality inspection on the grayscale image division of the vegetable surface according to the final segmentation threshold.
[0088] The initial threshold can be adjusted by adjusting the grayscale mean of the low grayscale area, and a new low grayscale area is obtained for iterative segmentation. After multiple adjustments, when the initial threshold changes little, it means that the adjustment has reached the limit, and the influence of the shadow part has been fully considered. The iteration is stopped, and the division threshold at this time is obtained. That is, the initial threshold is adjusted according to the adjusted grayscale mean of the low grayscale area, and a new low grayscale area is obtained for iterative segmentation, until the change degree of the initial threshold is less than the preset threshold, and the final segmentation threshold is stopped. Preferably, the grayscale mean of all pixels in the non-low grayscale area is obtained, and the average value between the adjusted grayscale mean of the low grayscale area and the grayscale mean of the non-low grayscale area is calculated as the new initial threshold, and the initial threshold is adjusted by the average value of the two areas until it is optimal. The area composed of pixels with grayscale values lower than the new initial threshold is taken as the new low grayscale area, and iterative segmentation is performed to obtain a new initial threshold and a new low grayscale area, and the shadow of the shadow part is repeatedly reduced by continuously analyzing the possibility of the shadow part.
[0089] If the difference between the initial threshold of the current iteration and the initial threshold of the previous iteration is less than the preset threshold, it means that the reduction degree has reached the limit, the iteration is stopped, and the initial threshold of the last iteration is used as the final segmentation threshold. At this time, the optimal effect of excluding the shadow part can be segmented. In the embodiment of the present invention, the preset threshold is set to 0.1, and the specific value can be adjusted by the implementer according to the specific implementation situation.
[0090] The grayscale image of the vegetable surface can be divided by the final segmentation threshold, and the part with a smaller grayscale value can reflect the mold area, or the remaining normal shadow part after excluding the shadow area as much as possible when there is no mold. Since the grayscale value of the mold area must be lower than the grayscale value of the normal shadow area, quality inspection is further performed according to the grayscale difference after division. In one embodiment of the present invention, the area in the grayscale image of the vegetable surface with a grayscale value less than the final segmentation threshold is taken as the area to be detected, that is, the area where mold may exist. The area in the grayscale image of the vegetable surface with a grayscale value greater than the final segmentation threshold is taken as the normal area. The grayscale average value of the area to be detected is calculated as the minimum grayscale mean, and the grayscale average value of the normal area is calculated as the maximum grayscale mean, and the grayscale difference analysis is performed through the grayscale average value.
[0091] When the difference between the minimum grayscale mean and the maximum grayscale mean is greater than the preset grayscale difference threshold, it means that the difference between the grayscale means is large, and mold spots may appear in the area to be detected, and the grayscale image of the vegetable surface corresponding to the quality of the dehydrated vegetables is recorded as unqualified. When the difference between the minimum grayscale mean and the maximum grayscale mean is less than or equal to the preset grayscale difference threshold, it means that the difference between the grayscale means is small, and no mold spots appear, and the grayscale image of the vegetable surface corresponding to the quality of the dehydrated vegetables is recorded as qualified. In an embodiment of the present invention, the preset grayscale difference threshold is 50, and the specific value can be adjusted by the implementer according to the specific implementation situation. In other embodiments of the present invention, the peak value of the area to be detected can also be further acquired. Considering that the mold spots also have certain peak characteristics, the mold spots are judged according to the grayscale difference between the peak part and the area to be detected, which is not further limited here.
[0092] In summary, the present invention first obtains the initial low grayscale area in the grayscale image of the vegetable surface. Considering that the mold spots and shadow parts are both in the low grayscale part with a lower grayscale in the grayscale image of the vegetable surface, and the dehydrated vegetable surface has a large number of wrinkles, the number of pixels in the shadow part will be second only to the main part of the vegetable. Therefore, the main peak grayscale and the secondary peak grayscale of the shadow part are determined by the grayscale change in the grayscale histogram. Further, in the preset grayscale range of the secondary peak grayscale, combined with the characteristics of the shadow pixel points, the shadow weight of the secondary peak grayscale is obtained by the grayscale distribution difference of the grayscale corresponding pixel points in the preset grayscale range and the local grayscale distribution offset of the secondary peak grayscale, as well as the difference with the main peak. The shadow weight can reflect the proportion of the shadow, so as to reduce the influence of the shadow part on the segmentation in the future. Further, in the low grayscale area, the grayscale distribution of all grayscale levels within the preset grayscale range of the sub-peak grayscale level is analyzed, and the number of grayscale levels is adjusted in combination with the shadow weight, so that the number of pixels with a greater possibility of shadows is reduced, reducing their influence on the grayscale value analysis, and the adjusted number is combined with the distribution of all grayscale levels in the low grayscale area to obtain the adjusted grayscale mean after reducing the influence of the pixels in the shadow part. Adjusting the grayscale mean can adjust the initial threshold to obtain a new low grayscale area, iteratively reduce the influence of the shadow part, and finally obtain a more accurate final segmentation threshold, and then divide the detection quality according to the final segmentation threshold for better effect. The present invention improves the segmentation effect by reducing the interference of the grayscale value of the pixels in the shadow part on the segmentation, so that the result of detecting mildew spots through the segmentation result is more accurate, and then the effect of quality detection is better.
[0093] It should be noted that the sequence of the above embodiments of the present invention is for description only 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.
[0094] 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 rapid detection method for dehydrated vegetable quality based on image data, It is characterized in that The method comprises: Obtain a grayscale image of the vegetable surface; determine an initial threshold value according to the grayscale value in the vegetable surface grayscale image to obtain a low grayscale area; determine a main peak grayscale level and a secondary peak grayscale level according to a grayscale level change in a grayscale histogram corresponding to the vegetable surface grayscale image; the secondary peak grayscale level is located in the low grayscale area; In the preset grayscale range of the secondary peak grayscale, based on the difference in the local grayscale distribution of the pixels corresponding to each grayscale and combined with the number of pixels in the low grayscale area, the difference ratio within the preset grayscale range of the secondary peak grayscale is obtained; according to the difference ratio of the secondary peak grayscale and the local grayscale distribution offset of the secondary peak grayscale, as well as the difference between the secondary peak grayscale and the main peak grayscale, the shadow weight of the secondary peak grayscale is obtained; According to the difference between each gray level in the preset gray level range of the sub-peak gray level and the sub-peak gray level, the distribution of each gray level in the low gray level area, and the shadow weight, the adjustment amount of each gray level in the preset gray level range is obtained; based on the adjustment amount of each gray level in the preset gray level range of the sub-peak gray level, combined with the quantity distribution of each gray level in the low gray level area, the adjusted gray level mean value of the low gray level area is obtained; The initial threshold is adjusted according to the adjusted grayscale mean of the low grayscale area, and a new low grayscale area is obtained for iterative segmentation, and the segmentation is stopped when the change degree of the initial threshold is less than the preset threshold, and the final segmentation threshold is obtained; the grayscale image of the vegetable surface is divided for quality inspection according to the final segmentation threshold; The method for obtaining the difference ratio includes: Obtain the mean value of the gradient direction of all pixels in the grayscale image of the vegetable surface, and use the direction of the straight line corresponding to the mean value as the detection direction; Sequentially use each pixel point corresponding to a gray level in a preset gray level range as a detection pixel point, and use the preset number of pixels to the left and right of the detection pixel point in the detection direction as analysis pixels for the detection pixel point; Calculate the cumulative value of the gray value difference between the detection pixel and each analysis pixel; when the cumulative value is greater than the preset difference threshold, take the detection pixel as the difference pixel; count the number of all difference pixels in the preset gray level range of the sub-peak gray level as the difference number; The ratio of the number of differences to the total number of all pixels in the low grayscale area is used as the difference ratio within the preset grayscale range of the sub-peak grayscale; The method for obtaining the shadow weight includes: Calculating the skewness of the preset grayscale range of the sub-peak grayscale as a deviation index corresponding to the sub-peak grayscale; The difference in the number of pixels corresponding to the secondary peak gray level and the primary peak gray level is used as the quantity difference index corresponding to the secondary peak gray level; According to the offset index, quantity difference index and difference proportion corresponding to the sub-peak gray level, the shadow weight of the sub-peak gray level is obtained; the offset index and the difference proportion are both positively correlated with the shadow weight, and the quantity difference index is negatively correlated with the shadow weight; The method for obtaining the adjustment quantity includes: The gray levels within the preset gray level range of the sub-peak gray level are sequentially taken as the target gray level, the difference in the corresponding gray level between the target gray level and the sub-peak gray level is calculated, and negative correlation mapping and normalization processing are performed to obtain the adjustment weight of the target gray level; The ratio of the number of pixels in the target grayscale to the total number of pixels in the low grayscale area is used as the adjustment ratio of the target grayscale; the product of the increase weight of the target grayscale, the adjustment ratio and the shadow weight of the sub-peak grayscale is negatively correlated and normalized to obtain the adjustment degree of the target grayscale; Calculate the product of the number of pixels in the target grayscale and the adjustment degree to obtain the adjustment amount of the target grayscale; The method for obtaining the adjusted grayscale mean value comprises: Calculate the product of the adjustment amount of each gray level in the preset gray level range of the sub-peak gray level and the corresponding gray level to obtain the adjusted gray value of each gray level in the preset gray level range; add the adjusted gray values of all gray levels in the preset gray level range to obtain a first gray accumulated value; The product of each gray level except the preset gray level range in the low gray level area and the number of corresponding pixels is used as the unadjusted gray value of each gray level; the unadjusted gray values of all gray levels are added to obtain a second gray accumulated value; The sum of the first grayscale accumulated value and the second grayscale accumulated value is used as the total grayscale value of the low grayscale area; the ratio of the total grayscale value to the total number of pixels in the low grayscale area is calculated to obtain the adjusted grayscale mean of the low grayscale area.
2. According to claim 1, a method for rapid detection of dehydrated vegetable quality based on image data, It is characterized in that The step of adjusting the initial threshold according to the adjusted grayscale mean value of the low grayscale area to obtain a new low grayscale area for iterative segmentation includes: Obtain the grayscale mean of all pixels in the non-low grayscale area; calculate the average value between the adjusted grayscale mean of the low grayscale area and the grayscale mean of the non-low grayscale area as a new initial threshold; The area composed of pixels whose grayscale values are lower than the new initial threshold is taken as the new low grayscale area, and iterative segmentation is performed to obtain the new initial threshold and the new low grayscale area.
3. According to claim 2, a method for rapid detection of dehydrated vegetable quality based on image data, It is characterized in that The step of stopping until the change degree of the initial threshold is less than the preset threshold, and obtaining the final segmentation threshold, comprises: If the difference between the initial threshold of the current iteration and the initial threshold of the previous iteration is less than the preset threshold, the iteration is stopped and the initial threshold of the last iteration is used as the final segmentation threshold.
4. According to claim 1, a method for rapid detection of dehydrated vegetable quality based on image data, It is characterized in that The quality detection of the vegetable surface grayscale image segmentation according to the final segmentation threshold comprises: The area in the vegetable surface grayscale image where the grayscale value is less than the final segmentation threshold is taken as the area to be detected; the area in the vegetable surface grayscale image where the grayscale value is greater than the final segmentation threshold is taken as the normal area; Calculate the grayscale average value of the area to be detected as the minimum grayscale average value, and calculate the grayscale average value of the normal area as the maximum grayscale average value; When the difference between the minimum grayscale mean and the maximum grayscale mean is greater than the preset grayscale difference threshold, the quality of the dehydrated vegetables corresponding to the grayscale image of the vegetable surface is recorded as unqualified; when the difference between the minimum grayscale mean and the maximum grayscale mean is less than or equal to the preset grayscale difference threshold, the quality of the dehydrated vegetables corresponding to the grayscale image of the vegetable surface is recorded as qualified.
5. According to claim 1, a method for rapid detection of dehydrated vegetable quality based on image data, It is characterized in that The method of determining an initial threshold value according to the grayscale value in the vegetable surface grayscale image to obtain a low grayscale area includes: Calculate the average value between the maximum grayscale value and the minimum grayscale value in the vegetable surface grayscale image to obtain the initial threshold; The low grayscale area in the vegetable surface grayscale image is determined according to the initial threshold, and the grayscale levels of the pixels in the low grayscale area are all less than the initial threshold.
6. According to claim 1, a method for rapid detection of dehydrated vegetable quality based on image data, It is characterized in that The method of determining the main peak grayscale level and the secondary peak grayscale level according to the grayscale level change in the grayscale histogram corresponding to the vegetable surface grayscale image comprises: Obtain all peaks in the grayscale histogram corresponding to the grayscale image of the vegetable surface; take the peak with the largest number of pixels as the main peak, and the grayscale level corresponding to the peak value of the main peak as the main peak grayscale level; Among the peaks other than the main peak, the peak with the second highest number of pixels and the corresponding gray level in the low gray area is selected as the secondary peak, and the gray level of the secondary peak corresponding to the peak is the secondary peak gray level.
Citation Information
Patent Citations
Meat quality quantitative analysis and evaluation method based on three-dimensional texture characteristics
CN110097537A
Paper box defect detection method based on artificial intelligence
CN114387274A
Metal surface rusty spot detection method fused with multi-direction multi-element universe local segmentation
CN117115075A
Mineral casting defect detection method based on artificial intelligence
CN117152180A
Road construction quality detection method and system based on artificial intelligence
CN117173184A
