An image recognition-based intelligent detection method for agricultural product quality

By performing white balance correction and local curvature analysis on agricultural product images, standardized images are generated and suspected defect areas are extracted. This solves the problem of accurate segmentation and defect identification in complex environments for agricultural product quality inspection, and achieves high-precision quality scoring.

CN122156808APending Publication Date: 2026-06-05SHAANXI LIANTONG GENERAL STANDARD TECH SERVICE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SHAANXI LIANTONG GENERAL STANDARD TECH SERVICE CO LTD
Filing Date
2026-03-26
Publication Date
2026-06-05

Smart Images

  • Figure CN122156808A_ABST
    Figure CN122156808A_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image recognition, in particular to an intelligent agricultural product quality detection method based on image recognition, which comprises the following steps: collecting an RGB image for a target agricultural product, synchronously recording collection parameters, performing white balance correction and normalization processing on the RGB image based on the collection parameters to generate a standardized image; calculating a hue probability score based on the standardized image, introducing local curvature to generate a target agricultural product main region, extracting a suspected defect region based on the target agricultural product main region; extracting a color maturity index, a texture uniformity index and a defect area proportion index based on the target agricultural product main region and the suspected defect region, and forming a target agricultural product quality feature vector. The application deeply integrates collection parameter correction, shape curvature constraint and color temperature self-adaptive reference correction mechanisms through image recognition technology, and effectively eliminates the interference of environmental illumination, shooting distance and light source color temperature difference on the detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image recognition technology, and more specifically to an intelligent detection method for agricultural product quality based on image recognition. Background Technology

[0002] In the post-harvest processing and grading of agricultural products (such as fruits), traditional quality inspection mainly relies on manual visual inspection, which suffers from drawbacks such as low efficiency, strong subjectivity, and difficulty in standardizing. Although automated inspection technology has been introduced in recent years, existing image recognition methods still face many severe challenges in practical applications: First, agricultural products have complex surface morphologies and varying reflective properties. Existing image recognition algorithms are extremely sensitive to changes in light intensity, light source color temperature, and shooting distance in the acquisition environment, lacking an effective parameter adaptive correction mechanism. This results in poor consistency of color and texture features extracted under different environments, making false detections highly likely. Second, when faced with shadows, highlights, or background interference, traditional image recognition segmentation methods often struggle to accurately separate the main body of the agricultural product from the background and cannot effectively distinguish between real defects and natural surface spots or noise, resulting in incomplete extraction of the main body area or inaccurate defect localization. Furthermore, existing image recognition models mostly use fixed benchmarks for maturity and defect determination, ignoring the dynamic shift in color distribution of agricultural products under different batches or lighting conditions. This leads to distortion in the construction of quality feature vectors, ultimately making it impossible for the accuracy and robustness of the comprehensive quality score to meet the needs of modern intelligent grading. Summary of the Invention

[0003] The purpose of this invention is to address the problems existing in the background technology by proposing an intelligent detection method for agricultural product quality based on image recognition.

[0004] The technical solution of this invention: A method for intelligent detection of agricultural product quality based on image recognition, comprising: S1. For the target agricultural product, acquire RGB images, record the acquisition parameters simultaneously, and perform white balance correction and normalization on the RGB images based on the acquisition parameters to generate standardized images. S2. Calculate the tone probability score based on the standardized image, and introduce local curvature to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, extract the suspected defect region. S3. Extract color maturity index, texture uniformity index, and defect area ratio index based on the main area and suspected defect area of ​​the target agricultural product, and form a quality feature vector of the target agricultural product. S4. Calculate the comprehensive quality score based on the target agricultural product quality feature vector through weighted fusion, and perform intelligent detection of agricultural product quality based on the comprehensive quality score.

[0005] As a further improvement to this technical solution, in step S1, the collected parameters include at least light intensity. Sampling distance White balance coefficient .

[0006] As a further improvement to this technical solution, in step S2, a tone probability score is calculated based on a standardized image, and local curvature is introduced to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, suspected defective regions are extracted, including the following steps: S2.1. Convert the standardized image to HSV space pixel by pixel to obtain the corresponding tone components. saturation component and brightness component ; S2.2 Construct a hue threshold range based on the prior color distribution characteristics of the target agricultural product, and simultaneously introduce a hue threshold range based on the sampling distance. The constructed saturation constraint threshold forms a joint judgment condition; S2.3, Based on joint decision conditions, for each pixel in the standardized image Perform point-by-point judgment to generate an initial binary mask. ; S2.4 Calculate each pixel based on the standardized image Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. ; S2.5, Utilizing optimized masks Masking is applied to the standardized image to extract the main body region of the target agricultural product. .

[0007] As a further improvement to this technical solution, in step S2.4, each pixel is calculated based on a standardized image. Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. This includes the following steps: S2.41, For each pixel in the standardized image Build neighborhood window Statistical neighborhood window All pixels Hue distribution histogram And based on the hue distribution histogram Calculate each pixel Hue probability score ; S2.42. Apply edge detection operators to the initial binary mask. Boundary extraction is performed to obtain a set of candidate boundary pixels. The local curvature of each candidate boundary pixel is then calculated based on the set of candidate boundary pixels. And based on local curvature Construct curvature determination function ; S2.43, For each pixel Based on hue probability score With curvature determination function Generate optimized mask .

[0008] As a further improvement to this technical solution, in S2.43, based on the hue probability score... With curvature determination function Generate optimized mask This includes the following steps: Hue probability score Apply normalization constraints and simultaneously adjust the curvature determination function. Preserving the binary form, for each pixel In its neighborhood Internal calculation of curvature consistency weight Based on hue probability score With curvature determination function And combined with curvature consistency weight Calculate pixels Probability of belonging to the main body of the target agricultural product Based on probability Generate optimized mask .

[0009] As a further improvement to this technical solution, in step S2, based on the main area of ​​the target agricultural product, the suspected defect area is extracted, including the following steps: S2.6, Target agricultural product main areas The hue components are statistically analyzed to calculate the reference hue for defect detection. This forms a local color reference. S2.7, Target agricultural product main areas Each pixel Based on reference hue Calculate hue deviation And generate a preliminary defect mask. ; S2.8, in the main areas of the target agricultural products Local grayscale features are extracted, and the initial defect mask is updated based on these local grayscale features. Generate an updated defect mask ; S2.9, Update the defect mask Applied to the main areas of target agricultural products Generate suspected defect areas .

[0010] As a further improvement to this technical solution, in step S3, color maturity index, texture uniformity index, and defect area ratio index are extracted based on the main area and suspected defect area of ​​the target agricultural product, and a quality feature vector of the target agricultural product is formed, including the following steps: S3.1, Based on the mask of the main region of the target agricultural product Masking of suspected defect areas Apply mask constraints to the standardized image to obtain a set of effective pixels containing only the subject region. and defective pixel set ; S3.2, in the set of effective pixels of the main body Extract the hue components to generate the average hue for maturity calculation. It also introduces a standard mature hue after color temperature adaptive reference correction. Calculate the color maturity index ; S3.3, in the set of effective pixels of the main body Extract the luminance component from the middle and upper parts, and then extract it into the neighborhood window. Internal calculation of local texture standard deviation Generate texture uniformity index ; S3.4, Based on defect pixel set and the set of effective pixels of the main body Pixel counts were performed separately, and the defect area ratio was calculated. ; S3.5, Color maturity index Texture uniformity index Defect area ratio index The target agricultural product quality feature vector is generated by performing uniform scale normalization processing. .

[0011] As a further improvement to this technical solution, in step S3.2, a standard mature hue after color temperature adaptive reference correction is introduced to calculate the color maturity index. This includes the following steps: S3.21, Based on the effective pixel set of the main body Computational geometric center and with the smallest circumscribed circle radius To construct a central stable region at the scale of [the scale]. ; S3.22, Based on the central stable region A dual-screening process was performed to obtain a stable lighting reference area. ; S3.23, Based on stable illumination reference region Extract the chromaticity components and calculate the statistical mean, which serves as the benchmark for color temperature shift; S3.24. Convert the RGB values ​​corresponding to the preset standard mature color tone to the L*a*b* space to generate a color reference in the mature state; S3.25. Utilizing a spatial correspondence reference mechanism, based on a stable illumination reference region. The weighted color temperature offset is constructed from the pixels within. ; S3.26, Using weighted color temperature offset The color reference in the mature state is compensated to obtain the corrected mature reference color; S3.27. Extract hue components based on the corrected mature reference color to obtain the standard mature hue after color temperature adaptive reference correction. .

[0012] As a further improvement to this technical solution, in step S3.25, a spatial correspondence reference mechanism is used, based on a stable illumination reference region. The weighted color temperature offset is constructed from the pixels within. This includes the following steps: With geometric center For reference, normalization is performed on each pixel to generate a normalized radial distance. Constructing a spatial weighting function based on normalized radial distance ; Constructing a local offset vector based on color temperature shift. ; Based on the color temperature shift benchmark, the color difference of each pixel in the color space is calculated. ; and introduce color difference Construct consistency weights for the Gaussian decay function of the independent variable ; Based on spatial weight function Consistency weight Constructing fusion weights Based on fusion weights For local offset vector Perform weighted aggregation to generate weighted color temperature offset. .

[0013] As a further improvement to this technical solution, in step S4, a comprehensive quality score is calculated based on the target agricultural product quality feature vector through weighted fusion, and intelligent detection of agricultural product quality is performed based on the comprehensive quality score, including the following steps: Based on the target agricultural product quality feature vector, a linear weighted scoring model is constructed through weighted fusion to generate a comprehensive quality score. The comprehensive quality score is divided into intervals according to a preset quality grading threshold, and the results of intelligent detection of agricultural product quality are output based on the interval division results.

[0014] Compared with the prior art, the above-mentioned technical solution of the present invention has the following beneficial technical effects: by deeply integrating image recognition technology with acquisition parameter correction, morphological curvature constraint and color temperature adaptive benchmark correction mechanism, the interference of ambient light, shooting distance and light source color temperature difference on the detection results is effectively eliminated. It realizes accurate segmentation of the main area of ​​agricultural products and robust extraction of minor defects in non-ideal complex environments, and significantly improves the quantitative accuracy of key quality characteristic indicators such as color maturity, texture uniformity and defect area ratio, thereby ensuring the objectivity and accuracy of the final quality grading score. Attached Figure Description

[0015] Figure 1 This is a flowchart of the overall method of the present invention. Detailed Implementation

[0016] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0017] Example: Please refer to Figure 1 As shown, this embodiment provides an intelligent detection method for agricultural product quality based on image recognition, including the following steps: S1. For the target agricultural product (in this embodiment, the target agricultural product is fruit), RGB images are acquired under standard lighting conditions, and acquisition parameters are recorded simultaneously. Based on the acquisition parameters, white balance correction and normalization processing are performed on the RGB images to eliminate ambient light interference and generate standardized images. Specifically, after acquiring the RGB image of the target agricultural product, the white balance coefficient recorded during acquisition is first used as the basis for the process. The three color channels of the RGB image are proportionally corrected by weighting the R, G, and B components of each pixel to obtain a preliminary white balance corrected image; subsequently, the image is combined with the ambient light intensity. (After normalization) ,in (Using the reference light intensity), construct a brightness normalization factor. Illumination compensation is applied to the overall brightness of the corrected image to reduce the impact of different lighting conditions on color measurement; further, the acquisition distance is introduced. By utilizing the influence of distance on image brightness attenuation and contrast changes, distance consistency correction is performed on the image to maintain relatively stable color distribution at different shooting distances. Finally, global normalization is applied to the corrected image to uniformly map the pixel values ​​of each channel to a standard range, generating a standardized image. (In the formula, For the RGB image of the target agricultural product, For reference distance, For the Hadamard product, i.e., for The R, G, and B color channels are multiplied by their respective white balance correction coefficients: , , ; The light response coefficient is used to control the light compensation intensity, and its value range is based on experimental calibration results under different lighting conditions (200~2000 lux). (This is the distance attenuation coefficient, used to adjust the degree of influence of distance on image brightness, obtained by fitting the imaging attenuation curve within the distance range of 10~100cm). The parameters collected should include at least light intensity. Sampling distance White balance coefficient .

[0018] S2. Calculate the tone probability score based on the standardized image, and introduce local curvature to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, extract the suspected defect region. In this embodiment, a tone probability score is calculated based on a standardized image, and local curvature is introduced to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, suspected defective regions are extracted, including the following steps: S2.1. Convert the standardized image to HSV space pixel by pixel to obtain the corresponding tone components. saturation component and brightness component Among them, the hue component (or normalized to [0,1]), used to characterize the dominant color information of agricultural product skin; specifically: when converting the standardized image to HSV space pixel by pixel, firstly, the RGB three channel values ​​of each pixel are uniformly scaled to make them within the same numerical range; then, for each pixel, the values ​​of its three channels are compared to determine the maximum value, minimum value, and the difference between the two, which are used to characterize the brightness range and color change amplitude of the pixel; based on this, according to the color type corresponding to the maximum channel, the hue component of the pixel is calculated according to the preset segmentation rules to reflect its dominant color attribute; at the same time, the saturation component is calculated using the proportional relationship between the maximum value and the difference, which is used to characterize the purity of the color; finally, the maximum value of the three channels is directly used as the brightness component, thereby obtaining the brightness information of the corresponding pixel; by performing the above conversion process on all pixels in the image one by one, the hue component, saturation component, and brightness component of the standardized image in HSV space are finally obtained, providing a basis for subsequent color analysis and region segmentation; S2.2 Construct a hue threshold range based on the prior color distribution characteristics of the target agricultural product (fruit) (e.g., apples are reddish, bananas are yellowish). At the same time, a method based on the sampling distance is introduced. Constructed saturation constraint threshold ( This is used to suppress interference from low-saturation backgrounds (such as grayscale and shadow areas) and form a joint judgment condition: This judgment condition achieves a dual constraint on the color consistency and purity of the target area; specifically, after completing the HSV space conversion, a preset hue threshold range is established. , To set the lower limit of the preset color tone, To preset the upper limit of hue, for example, the hue of red apple varieties is mainly distributed between 0° and 10° (in the HSV space, 0° corresponds to red), therefore, the upper limit of hue can be set. Set to 0°, It can be set to 10°; the hue distribution of yellow bananas is between 30° and 60°, so it can be set to... , (Can be set to 60°); then combined with the acquisition distance. For the preset saturation threshold (This is used to distinguish the main subject of the target agricultural product from the low-saturation background (such as shadows, reflections, packaging materials, etc.), derived from prior experimental data, with values ​​ranging from 0.2 to 0.5) Modulation is performed using a linear scaling relationship. ( (The distance modulation coefficient is obtained by fitting the measured attenuation rate of saturation at different acquisition distances (15~60cm)) An adaptive saturation constraint is constructed to compensate for the color saturation attenuation caused by increasing distance, thereby avoiding misjudging distant or weak contrast areas as targets; within the obtained hue threshold range... With modulated saturation threshold Then, for each pixel in the image A joint judgment condition is constructed: when its hue component falls into the range and its saturation is greater than the threshold, it is judged as a target pixel; otherwise, it is regarded as a background or interference area, thereby achieving stable separation of the target agricultural product area under different acquisition environments. S2.3, Based on joint decision conditions, for each pixel in the standardized image Perform point-by-point judgment to identify pixels that meet the joint judgment conditions. Assign a value of 1 if necessary, otherwise assign a value of 0 to generate the initial binary mask. The initial binary mask Achieve initial separation between the target agricultural product and its background; S2.4 Calculate each pixel based on the standardized image Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. ; In this embodiment, step S2.4 addresses the problems of inaccurate boundary recognition and internal voids caused by uneven lighting, local color variations, and complex surface morphology during the segmentation of agricultural product images. Specifically, after obtaining an initial binary mask through a color threshold, the surface of agricultural products may be affected by shadows, highlights, slight color spots, or defects, causing the segmented target area boundary to appear jagged, broken, or containing holes that are mistakenly identified as background. This invention introduces a hue probability score based on a standardized image to evaluate the probability that each pixel belongs to the color of the target agricultural product within a local neighborhood, thus overcoming the limitations of a global color threshold. Simultaneously, by combining local curvature features, curvature constraints are used to filter out smooth and reasonable boundary pixels, suppressing false boundaries caused by noise or minor defects. This preserves the true defect contours while correcting the boundaries of the initial mask and enhancing the consistency within the region, laying a refined foundation for accurate defect extraction. Compared to segmentation methods based solely on color or edges, this invention significantly improves the robustness and accuracy of segmentation in complex scenarios such as non-ideal lighting, local surface defects, and varietal color variations, providing a more reliable basis for subsequent quality feature extraction and intelligent rating. Each pixel is calculated based on a standardized image. Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. This includes the following steps: S2.41, For each pixel in the standardized image Build neighborhood window (radius It can be set according to the target size (e.g.) (pixels), statistical neighborhood window All pixels Hue distribution histogram (Statistical neighborhood window) The inner hue component falls within the hue threshold range constructed in step S2.2. (pixels within), and based on the hue distribution histogram Calculate each pixel Hue probability score This is used to measure the probability that a pixel belongs to the target color tone; specifically, it involves processing each pixel in a normalized image. At this time, first, taking that pixel as the center, according to the preset radius... Build neighborhood window The window size can be set according to the size of the target agricultural product (e.g., 3-5 pixels) to capture local color information; then, the hue components of all pixels within the window are counted and a hue histogram is constructed. (First, traverse the neighboring windows) For each pixel within the range, read its hue component and determine its hue threshold range. The values ​​are mapped to corresponding histogram intervals; then, the number of pixels falling into each hue threshold interval is counted to form a frequency distribution; finally, the frequencies are normalized so that the value of each interval in the histogram represents the probability or relative frequency of that hue occurring in its neighborhood, thus obtaining a hue histogram reflecting the local hue distribution. This reflects the frequency distribution of different hues in a local area; the histogram of this hue... Normalization is performed so that the value in each interval represents the probability of that hue occurring in the neighborhood. Then, the histogram interval corresponding to the hue component of that pixel is determined (the histogram itself consists of several intervals; for example, the range of hue component values ​​is divided into intervals at fixed intervals z, each interval corresponding to a continuous range of hue values). The normalized probability value of that interval is read as the hue probability score of that pixel. This score characterizes the degree of matching between the pixel's hue and the local dominant hue, providing a foundation for subsequent color-based target region optimization; S2.42. Apply edge detection operators to the initial binary mask. Boundary extraction is performed (e.g., using the Sobel operator) to obtain a set of candidate boundary pixels. The local curvature of each candidate boundary pixel is then calculated based on this set. (Specifically: for the initial binary mask) When performing boundary extraction, the gradients of the mask in the horizontal and vertical directions are first calculated using an edge detection operator (such as the Sobel operator). A threshold is applied to the gradient magnitude of each pixel, and pixels with significant gradients are identified as boundary pixels, thus obtaining a set of candidate boundary pixels. Then, for each candidate boundary pixel in the set, the curvature of the pixel is calculated using a second-order difference method based on its neighboring boundary pixels. This curvature reflects the degree of bending of the boundary at that point; by traversing the entire candidate boundary set, the local curvature value of each boundary pixel can be obtained, providing a basis for subsequent boundary selection and mask optimization based on curvature constraints, and according to the constraint conditions ( This represents the lower limit threshold of local curvature. (Representing the upper limit threshold of local curvature) to filter smooth and reasonable boundary pixels, and based on local curvature Construct curvature determination function It is used to filter out smooth and reasonable boundary pixels and eliminate overly curved or isolated noise points, thereby ensuring the continuity and morphological authenticity of the mask contour. S2.43, For each pixel Based on hue probability score With curvature determination function Generate optimized mask ; Furthermore, based on hue probability scores With curvature determination function Generate optimized mask This includes the following steps: Hue probability score Apply normalization constraints and simultaneously adjust the curvature determination function. Preserve the binary form (0 or 1) for each pixel. In its neighborhood Internal calculation of curvature consistency weight (Used to measure the continuity of the boundary structure around the pixel, avoiding interference from isolated noise points on the fusion result, where, For neighborhood windows The total number of pixels within the window, i.e., the window area, is used to normalize the summation result. For pixels, For the curvature determination function, the pixels within the neighborhood window The value of is in binary form (0 or 1), based on the hue probability score. With curvature determination function And combined with curvature consistency weight Calculate pixels Probability of belonging to the main body of the target agricultural product (If pixel) If it belongs to the candidate boundary pixel set, then ( The weights are calculated using the formula [0,1], where the curvature of the candidate boundary point is noise or an isolated point. When the probability of a point is suppressed to 0, edge trimming is achieved. If the pixel... For pixels not belonging to the candidate boundary pixel set (i.e., located within the main body of the agricultural product), their comprehensive probability is determined directly using local tone distribution characteristics, let... To ensure the integrity of the main agricultural product area and avoid internal voids, based on probability. Generate optimized mask ( In this embodiment, to preset the mask threshold, This allows for refined correction of the initial segmented regions, thereby improving the accuracy of extracting the main components of the target agricultural product. S2.5, Utilizing optimized masks Masking is applied to the standardized image to extract the main body region of the target agricultural product. .

[0019] Furthermore, based on the main area of ​​the target agricultural product, suspected defective areas are extracted, including the following steps: S2.6, Target agricultural product main areas The hue components are statistically analyzed to calculate the reference hue for defect detection. ( Target agricultural product main area The total number of pixels within the area is used to form a local color baseline for identifying abnormal deviations; specifically, each pixel is traversed and its hue information is extracted, then the average hue of all pixels is calculated as the reference hue. It is used to determine whether each pixel deviates from the normal tone, thereby identifying potential defect areas; S2.7, Target agricultural product main areas Each pixel Based on reference hue Calculate hue deviation And generate a preliminary defect mask. Specifically, this refers to the hue deviation. and deviation threshold (Based on statistical comparisons of the differential distribution of normal skin tone with typical defect tones (rot, bruises, insect spots), and saturation was also checked.) Is it below the saturation constraint threshold? If any condition is met, the pixel is considered to have a color anomaly and is marked as 1 in the preliminary defect mask; otherwise, it is marked as 0. By traversing all main pixels, a binary preliminary defect mask reflecting the distribution of potential defect pixels can be formed. This provides a foundation for subsequent texture analysis and defect mask updates; S2.8, in the main areas of the target agricultural products Extracting local grayscale features The initial defect mask is updated based on local grayscale features. Generate an updated defect mask Specifically, this refers to the main areas where the target agricultural products are grown. First, select the window size centered on each pixel. Construct a local neighborhood and extract the grayscale features of that local neighborhood. For example, local standard deviation, to quantify the uniformity of texture around a pixel; then... With preset feature threshold Compare, if If a pixel exhibits abnormal local contrast, it is determined to have texture abnormalities and is marked as a potential defect pixel in the defect mask. Finally, this marking result is compared with the initial defect mask. Perform a logical OR operation to update and generate a new defect mask. This allows for a more comprehensive identification of defect areas by taking into account both color and texture anomalies. S2.9, Update the defect mask Applied to the main areas of target agricultural products Generate suspected defect areas .

[0020] S3. Extract color maturity index, texture uniformity index, and defect area ratio index based on the main area and suspected defect area of ​​the target agricultural product, and form a quality feature vector of the target agricultural product. In this embodiment, the color maturity index, texture uniformity index, and defect area ratio index are extracted to form a quality feature vector of the target agricultural product, including the following steps: S3.1, Based on the mask of the main region of the target agricultural product Masking of suspected defect areas Apply mask constraints to the standardized image to obtain a set of effective pixels containing only the subject region. and defective pixel set ; S3.2, in the set of effective pixels of the main body Extract the hue components to generate the average hue for maturity calculation. It also introduces a standard mature hue after color temperature adaptive reference correction. Calculate the color maturity index ( (representing the Min-Max normalization function). This index reflects the overall ripeness of the fruit; the closer the value is to 0, the closer it is to the standard ripeness. In this embodiment, step S3.2 mainly addresses the systematic bias that arises when directly using a fixed maturity hue standard to assess color maturity due to differences in light source color temperature, fluctuations in light intensity, and uneven color distribution on the surface of agricultural products under different acquisition environments. Specifically, in practical applications of agricultural product quality testing, image acquisition may be under natural light, artificial light, or mixed lighting conditions. The color temperature of different light sources will cause agricultural products of the same maturity to exhibit significant color differences in the image. If a pre-set fixed maturity hue is used as a reference standard, normally ripe fruits may be misjudged as underripe or overripe due to light offset. This paper introduces an adaptive color temperature reference correction method. It extracts a stable, uniformly lit, and defect-free region (such as the central area) from the main body of the agricultural product as a color temperature reference. This dynamically constructs the color temperature offset under the current acquisition environment and adaptively corrects the preset standard mature hue, ensuring that the color maturity index truly reflects the maturity state of the agricultural product itself, rather than the apparent color affected by lighting. A stable region is constructed using the geometric center and the minimum circumcircle radius. Brightness filtering and Mahalanobis distance in L*a*b* space are used as dual constraints to effectively eliminate highlights, shadows, and potentially defective pixels, ensuring the reliability of the reference region. Secondly, a spatial weight is constructed based on normalized radial distance, combined with color difference consistency weight, to weighted aggregate local color temperature offsets. This makes the color temperature correction not only globally stable but also more focused on the lighting information of the central stable region. Finally, the corrected mature reference color is converted to HSV space to obtain a dynamic standard mature hue. Among them, the standard mature hue after color temperature adaptive reference correction is introduced to calculate the color maturity index. This includes the following steps: S3.21, Based on the effective pixel set of the main body Calculating the geometric center of the fruit and with the smallest circumscribed circle radius To construct a central stable region at the scale of [the scale]. ( (Base radius); specifically: within the effective pixel area of ​​the main body. First, calculate the average coordinates of all pixels to obtain the geometric center of the fruit. Then, using this geometric center as the center, take a certain proportion of the radius of the smallest circumcircle as the radius and draw a circular area in the main body area. This circular area is the central stable area, which is used to select pixels with uniform lighting and stable shape as color temperature references. S3.22, Based on the central stable region A dual-screening process was performed to obtain a stable lighting reference area. ( (For a stable region with uniform illumination and no defects); specifically: calculation The average value of the luminance components of all pixels within the range with standard deviation Filter brightness at Within the specified range, pixels that are too dark (shadows) and too bright (highlights) are excluded to obtain a brightness-stable subset. ;exist Within this process, pixels are converted to the L*a*b* color space, and calculations are performed. and mean of components The covariance matrix is ​​used to filter pixels with smaller color deviations based on Mahalanobis distance. ,in, Represents the red-green color component. Indicates the yellow-blue hue component. Mahalanobis distance threshold (e.g.) ), used to remove pixels with abnormal colors (such as possible small defects or spots) without relying on explicit detection of defects; S3.23, Based on stable illumination reference region Extract the chromaticity components and calculate their statistical mean, which serves as the benchmark for color temperature shift. In the formula, For pixels In the L*a*b* color space, the a* component represents the red and green components of that pixel. For pixels In the L*a*b* color space, the b* component represents the yellow and blue components of that pixel; S3.24. Convert the RGB values ​​corresponding to the preset standard mature color tone to the L*a*b* space to generate the color reference in the mature state. Specifically, the process involves linearizing the RGB values ​​corresponding to a preset standard ripening hue (referring to the standard color that the peel of a specific fruit or agricultural product should have under ideal ripening conditions, defined in RGB or L*a*b* value form; the standard ripening hue varies for different fruits, for example: apple (red variety): R≈200–220, G≈30–50, B≈30–50) (removing gamma correction), then mapping the linear RGB values ​​to the CIE 1931 XYZ space using the standard RGB to XYZ color space conversion formula, and finally converting the XYZ values ​​to L*a*b* values ​​according to the CIE L*a*b* color space definition formula, extracting the a* and b* components to obtain the color reference under ripening conditions. This color standard is used to represent the red, green, yellow, and blue hues of the target fruit under ideal ripeness, providing a reference for subsequent color temperature correction; S3.25. Utilizing a spatial correspondence reference mechanism, based on a stable illumination reference region. The weighted color temperature offset is constructed from the pixels within. ; Spatial correspondence reference mechanism based on stable illumination reference region Weighted color temperature offset This invention aims to address the distortion in maturity feature extraction caused by fluctuations in light source color temperature, uneven spatial distribution of illumination, and local color anomalies on the surface of agricultural products under actual collection environments. The spatial correspondence reference mechanism dynamically extracts pixels with stable illumination and consistent color from the geometric center region inside the agricultural product as a color temperature reference. It introduces normalized radial distance to construct spatial weights and uses color difference consistency weights to suppress defects and noise interference, thereby achieving weighted aggregation of local color temperature offsets. This allows for adaptive correction of preset standard mature hues, enabling the color maturity index to accurately reflect the inherent maturity state of agricultural products under real lighting conditions. Compared with existing technologies, this significantly improves the robustness and accuracy of cross-light source and cross-batch detection. Furthermore, by utilizing a spatial correspondence reference mechanism, based on a stable illumination reference region... The weighted color temperature offset is constructed from the pixels within. This includes the following steps: With geometric center For reference, normalization is performed on each pixel to generate a normalized radial distance. Constructing a spatial weighting function based on normalized radial distance (In the formula, The value should be a very small positive number to prevent the weight from being zero or divisible by zero. (This is a spatial weighting scale parameter used to control the rate at which the weights decay with distance). Reference based on color temperature shift Constructing local offset vectors ; Reference based on color temperature shift For each pixel, calculate its position. – Color difference in color space This is used to characterize the consistency of the pixel with respect to the overall color distribution; and color difference is introduced. Construct consistency weights for the Gaussian decay function of the independent variable By setting the color difference tolerance parameter Abnormal pixels that deviate significantly from the reference color are exponentially suppressed, thereby reducing the interference of local noise, defective areas and lighting anomalies on the overall color temperature estimation, and realizing adaptive screening and weighted constraints on effective pixels. Based on spatial weight function Consistency weight Constructing fusion weights Based on fusion weights For local offset vector Perform weighted aggregation to generate weighted color temperature offset. ; S3.26, Using weighted color temperature offset Color reference in mature state Compensation is performed to obtain the corrected mature reference color. ; S3.27, Based on the corrected mature reference color Extracting the hue components yields the standard mature hue after color temperature adaptive reference correction. Specifically, this involves adjusting the corrected mature reference color. Combined with the corresponding luminance component, a complete L*a*b* representation is formed. Then, according to the conversion relationship from L*a*b* to the HSV color space, the L*a*b* value is mapped to three components: hue, saturation, and luminance. The hue component is extracted and used as the standard mature hue after color temperature adaptive reference correction. This standard mature color tone can reflect the ideal mature color of fruit under actual collection conditions and after light offset correction, providing an adaptive reference for subsequent calculation of color maturity index; S3.3, in the set of effective pixels of the main body Extracting the brightness component from the middle and upper parts and in the neighborhood window Internal calculation of local texture standard deviation Generate texture uniformity index , The main effective pixel set Mid-luminance component The global standard deviation is used to normalize local texture fluctuations, making texture uniformity indices comparable across different brightness ranges. The global standard deviation is the local texture standard deviation, i.e., the standard deviation within the set of effective pixels of the main subject. In the mean, the local texture standard deviation for each pixel Statistical analysis is performed to calculate the standard deviation of these local standard deviations, which is used to measure the consistency of local texture fluctuations across the entire region. S3.4, Based on defect pixel set and the set of effective pixels of the main body Pixel counting is performed separately. , And calculate the defect area ratio index. ; S3.5, Color maturity index Texture uniformity index Defect area ratio index Perform uniform scale normalization (such as Min-Max or Z-score) to eliminate dimensional differences and generate the target agricultural product quality feature vector. (In the formula, To standardize the color maturity index after scaling, To standardize the texture uniformity index after scale normalization, (This refers to the defect area ratio index after standardization).

[0021] S4. Calculate the comprehensive quality score based on the target agricultural product quality feature vector through weighted fusion, and perform intelligent detection of agricultural product quality based on the comprehensive quality score; In this embodiment, a comprehensive quality score is calculated based on the target agricultural product quality feature vector through weighted fusion, and intelligent detection of agricultural product quality is performed based on the comprehensive quality score, including the following steps: Based on the target agricultural product quality feature vector, a comprehensive quality score is generated through weighted fusion using preset weights. The comprehensive quality score is then divided into intervals according to preset quality grading thresholds, and the intelligent detection results of agricultural product quality are output based on the interval division results. Specifically: based on the target agricultural product quality feature vector... Using preset weights The overall quality score is obtained by performing a weighted summation. , In the formula, As a weight for color maturity, As a weight for texture uniformity, The weighting is based on the percentage of defective area; according to the preset quality grading threshold range, the comprehensive score of each agricultural product is mapped to the corresponding quality grade: if The quality grade of the agricultural product is determined to be "excellent"; if The quality grade of the agricultural product is determined to be "good"; if The quality grade of the agricultural product is determined to be "medium"; if The system determines the quality grade of agricultural products as "poor" and outputs intelligent detection results, including: the overall quality score of each agricultural product. The system provides quality grades and corresponding defect feature statistics (such as color maturity, texture uniformity, and defect percentage), enabling a complete automated process from feature extraction to scoring and grade determination.

[0022] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings. However, the present invention is not limited thereto. Various changes can be made within the scope of knowledge possessed by those skilled in the art without departing from the spirit of the present invention.

Claims

1. A method for intelligent detection of agricultural product quality based on image recognition, characterized in that, include: S1. For the target agricultural product, acquire RGB images, record the acquisition parameters simultaneously, and perform white balance correction and normalization on the RGB images based on the acquisition parameters to generate standardized images. S2. Calculate the tone probability score based on the standardized image, and introduce local curvature to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, extract the suspected defect region. S3. Extract color maturity index, texture uniformity index, and defect area ratio index based on the main area and suspected defect area of ​​the target agricultural product, and form a quality feature vector of the target agricultural product. S4. Calculate the comprehensive quality score based on the target agricultural product quality feature vector through weighted fusion, and perform intelligent detection of agricultural product quality based on the comprehensive quality score.

2. The intelligent detection method for agricultural product quality based on image recognition according to claim 1, characterized in that, In step S1, the collected parameters include at least light intensity. Sampling distance White balance coefficient .

3. The intelligent detection method for agricultural product quality based on image recognition according to claim 1, characterized in that, In step S2, a tone probability score is calculated based on a standardized image, and local curvature is introduced to generate the main body region of the target agricultural product. Based on the main body region of the target agricultural product, suspected defective regions are extracted, including the following steps: S2.

1. Convert the standardized image to HSV space pixel by pixel to obtain the corresponding tone components. saturation component and brightness component ; S2.2 Construct a hue threshold range based on the prior color distribution characteristics of the target agricultural product, and simultaneously introduce a hue threshold range based on the sampling distance. The constructed saturation constraint threshold forms a joint judgment condition; S2.3, Based on joint decision conditions, for each pixel in the standardized image Perform point-by-point judgment to generate an initial binary mask. ; S2.4 Calculate each pixel based on the standardized image Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. ; S2.5, Utilizing optimized masks Masking is applied to the standardized image to extract the main body region of the target agricultural product. .

4. The intelligent detection method for agricultural product quality based on image recognition according to claim 3, characterized in that, In step S2.4, each pixel is calculated based on the standardized image. Hue probability score And combined with local curvature to the initial binary mask Perform boundary correction and region consistency enhancement to generate an optimized mask. This includes the following steps: S2.41, For each pixel in the standardized image Build neighborhood window Statistical neighborhood window All pixels Hue distribution histogram And based on the hue distribution histogram Calculate each pixel Hue probability score ; S2.

42. Apply edge detection operators to the initial binary mask. Boundary extraction is performed to obtain a set of candidate boundary pixels. The local curvature of each candidate boundary pixel is then calculated based on the set of candidate boundary pixels. And based on local curvature Construct curvature determination function ; S2.43, For each pixel Based on hue probability score With curvature determination function Generate optimized mask .

5. The intelligent detection method for agricultural product quality based on image recognition according to claim 4, characterized in that, In S2.43, based on hue probability score With curvature determination function Generate optimized mask This includes the following steps: Hue probability score Apply normalization constraints and simultaneously adjust the curvature determination function. Preserving the binary form, for each pixel In its neighborhood Internal calculation of curvature consistency weight Based on hue probability score With curvature determination function And combined with curvature consistency weight Calculate pixels Probability of belonging to the main body of the target agricultural product Based on probability Generate optimized mask .

6. The intelligent detection method for agricultural product quality based on image recognition according to claim 1, characterized in that, In step S2, based on the main area of ​​the target agricultural product, suspected defective areas are extracted, including the following steps: S2.6, Target agricultural product main areas The hue components are statistically analyzed to calculate the reference hue for defect detection. This forms a local color reference. S2.7, Target agricultural product main areas Each pixel Based on reference hue Calculate hue deviation And generate a preliminary defect mask. ; S2.8, in the main areas of the target agricultural products Local grayscale features are extracted, and the initial defect mask is updated based on these local grayscale features. Generate an updated defect mask ; S2.9, Update the defect mask Applied to the main areas of target agricultural products Generate suspected defect areas .

7. The intelligent detection method for agricultural product quality based on image recognition according to claim 1, characterized in that, In step S3, color maturity index, texture uniformity index, and defect area ratio index are extracted based on the main area and suspected defect area of ​​the target agricultural product, and a quality feature vector of the target agricultural product is formed, including the following steps: S3.1, Based on the mask of the main region of the target agricultural product Masking of suspected defect areas Apply mask constraints to the standardized image to obtain a set of effective pixels containing only the subject region. and defective pixel set ; S3.2, in the set of effective pixels of the main body Extract the hue components to generate the average hue for maturity calculation. It also introduces a standard mature hue after color temperature adaptive reference correction. Calculate the color maturity index ; S3.3, in the set of effective pixels of the main body Extract the luminance component from the middle and upper parts, and then extract it into the neighborhood window. Internal calculation of local texture standard deviation Generate texture uniformity index ; S3.4, Based on defect pixel set and the set of effective pixels of the main body Pixel counts were performed separately, and the defect area ratio was calculated. ; S3.5, Color maturity index Texture uniformity index Defect area ratio index The target agricultural product quality feature vector is generated by performing uniform scale normalization processing. .

8. The intelligent detection method for agricultural product quality based on image recognition according to claim 7, characterized in that, In step S3.2, the standard mature hue after color temperature adaptive reference correction is introduced to calculate the color maturity index. This includes the following steps: S3.21, Based on the effective pixel set of the main body Computational geometric center and with the smallest circumscribed circle radius To construct a central stable region at the scale of [the scale]. ; S3.22, Based on the central stable region A dual-screening process was performed to obtain a stable lighting reference area. ; S3.23, Based on stable illumination reference region Extract the chromaticity components and calculate the statistical mean, which serves as the benchmark for color temperature shift; S3.

24. Convert the RGB values ​​corresponding to the preset standard mature color tone to the L*a*b* space to generate a color reference in the mature state; S3.

25. Utilizing a spatial correspondence reference mechanism, based on a stable illumination reference region. The weighted color temperature offset is constructed from the pixels within. ; S3.26, Using weighted color temperature offset The color reference in the mature state is compensated to obtain the corrected mature reference color; S3.

27. Extract hue components based on the corrected mature reference color to obtain the standard mature hue after color temperature adaptive reference correction. .

9. The intelligent detection method for agricultural product quality based on image recognition according to claim 8, characterized in that, In step S3.25, a spatial correspondence reference mechanism is used, based on a stable illumination reference region. The weighted color temperature offset is constructed from the pixels within. This includes the following steps: With geometric center For reference, normalization is performed on each pixel to generate a normalized radial distance. Constructing a spatial weighting function based on normalized radial distance ; Constructing a local offset vector based on color temperature shift. ; Based on the color temperature shift benchmark, the color difference of each pixel in the color space is calculated. ; and introduce color difference Construct consistency weights for the Gaussian decay function of the independent variable ; Based on spatial weight function Consistency weight Constructing fusion weights Based on fusion weights For local offset vector Perform weighted aggregation to generate weighted color temperature offset. .

10. The intelligent detection method for agricultural product quality based on image recognition according to claim 1, characterized in that, In step S4, a comprehensive quality score is calculated based on the target agricultural product quality feature vector through weighted fusion, and intelligent detection of agricultural product quality is performed based on the comprehensive quality score, including the following steps: Based on the target agricultural product quality feature vector, a linear weighted scoring model is constructed through weighted fusion to generate a comprehensive quality score. The comprehensive quality score is divided into intervals according to a preset quality grading threshold, and the results of intelligent detection of agricultural product quality are output based on the interval division results.