An image processing-based method and system for grading the quality of pineapples and a medium

By using image processing technology, combined with unsupervised clustering and convolutional neural networks, the color, size, defects, and sugar content characteristics of pineapples are analyzed, solving the problems of time-consuming, labor-intensive, and misjudgment-prone traditional manual grading, and realizing automated, accurate, and consistent evaluation of pineapple quality.

CN120490117BActive Publication Date: 2026-02-06SOUTH SUBTROPICAL CROP RES INST CHINA ACAD OF TROPICAL AGRI SCI +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510576802.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-05-06
Publication Date
2026-02-06
Estimated Expiration
2045-05-06

AI Technical Summary

Technical Problem

Traditional manual pineapple grading methods are time-consuming and labor-intensive, highly susceptible to human factors, and difficult to accurately capture subtle appearance differences and potential internal defects, leading to uneven grading and misjudgments, which affect market value.

Method used

Using an image processing-based approach, a pineapple sample dataset was constructed. Then, using an unsupervised clustering algorithm and a convolutional neural network model, the color, size, defects, and sugar content characteristics of pineapples were analyzed to achieve automated quality assessment.

Benefits of technology

It improves the accuracy and consistency of pineapple grading, provides objective, comprehensive and reliable quality analysis, adapts to the precise evaluation of different pineapple varieties, and enhances market competitiveness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120490117B_ABST
    Figure CN120490117B_ABST
Patent Text Reader

Abstract

The application provides a pineapple quality grading method and system based on image processing and a medium, and relates to the technical field of pineapple quality grading. First, a pineapple sample data set containing different quality gradients is constructed, image group data of each sample pineapple is collected, and characteristics such as color, size, defects and sugar content of each sample pineapple are extracted. Second, an unsupervised clustering algorithm is used to cluster the characteristics of the samples to determine their quality gradients. A convolutional neural network model is constructed, image data is used as input for training, and corresponding defect features are used as labels to construct a defect detection model. Next, the image data of the pineapple to be graded is collected, the trained model is applied to obtain the defect features, and the related characteristics are analyzed. Finally, the characteristic offset index between the pineapple to be graded and the sample pineapple is calculated, and the quality gradient of the pineapple to be graded is determined according to the sample pineapple corresponding to the smallest offset.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of pineapple quality grading, in particular to a pineapple quality grading method and system based on image processing and a medium. BACKGROUND

[0002] As a popular tropical fruit, the quality of pineapple directly affects market value and consumer purchasing decisions. With the increasing demand for fruit quality from consumers, traditional manual grading methods have gradually failed to meet the needs of the modern market. This method not only takes time and effort, but is also greatly influenced by human factors, which can lead to uneven grading and misjudgment. Therefore, developing an efficient and objective pineapple quality grading technology has become an urgent need in the industry.

[0003] Manual grading is often influenced by subjective factors, and the experience and judgment of the evaluator will directly affect the results of the grading, which can lead to different quality gradients for the same batch of pineapples. Secondly, traditional visual inspection methods lack systematicness and objectivity in identifying the color, shape, and defects of pineapples. These methods often cannot accurately capture minor appearance differences and potential internal defects, and are prone to missed detection or misjudgment, or rely on subjective judgment, leading to inaccurate quality assessment. This not only affects consumer trust in the product, but can also result in high-quality pineapples being undervalued due to improper grading, thereby affecting their market value.

[0004] The above information disclosed in the background section is only used to enhance the understanding of the background of the present disclosure, and therefore it can include information that does not constitute prior art known to those of ordinary skill in the art. SUMMARY

[0005] The present application aims to provide a pineapple quality grading method and system based on image processing and a medium to solve the problems raised in the background.

[0006] To achieve the above-mentioned purpose, the present application provides the following technical solutions:

[0007] A pineapple quality grading method based on image processing, the specific steps comprising:

[0008] Step 1: Construct a pineapple sample data set, obtain the image group data of each sample pineapple and the defect features corresponding to the image group data, and analyze the relevant features of the sample pineapple based on the image group data;

[0009] Step 2: According to the image group data and corresponding defect features of the sample pineapple, use an unsupervised clustering algorithm to cluster the features of the pineapple samples, divide the quality gradient according to the clustering results, and determine the quality gradient of each sample pineapple;

[0010] Step 3: Construct a model based on a convolutional neural network, input the image group data of the sample pineapple as a feature, and train the model with the corresponding defect feature as the output to obtain a defect detection model;

[0011] Step 4: Collect image group data of the pineapple to be graded, input the image data of the pineapple to be graded in the image group data into the defect detection model, obtain the defect feature of the pineapple to be graded, and analyze the image group data of the pineapple to be graded to obtain the related features of the pineapple to be graded;

[0012] Step 5: Traverse all sample pineapples, determine the feature offset between the pineapple to be graded and the sample pineapple data mean in each quality gradient according to the related features and defect features of the pineapple to be graded and the sample pineapple, and determine the most relevant sample pineapple according to the feature offset and the quality gradient of the pineapple to be graded.

[0013] Further, obtaining the defect feature and the related feature of the sample pineapple specifically includes:

[0014] The sample pineapple data set contains sample pineapples of multiple quality gradients, including four gradients of excellent, good, medium and poor, and the image group data includes images of the sample pineapple taken from different angles and near-infrared spectrum images of the sample pineapple. The preprocessing includes noise reduction processing and weighted average processing of each group of sample pineapple images, each pixel point is subjected to Gaussian filter noise reduction, and the value of each pixel point is determined by weighted average of the values of the pixel point and other pixel points in its neighborhood;

[0015] The defect feature is the defect area. The image group data of each sample pineapple is converted into a grayscale image, the grayscale image is converted into a binary image through a preset comprehensive dynamic threshold, the pixel points below the comprehensive dynamic threshold are marked as abnormal pixel points with a value of 0, and the pixel points above the comprehensive dynamic threshold are marked as normal pixel points with a value of 255, thereby obtaining a binary image for defect detection. The number of abnormal pixel points in the binary image for defect detection is counted, and the proportion of the number of abnormal pixel points in the total number of pixel points in the image is taken as the defect area of the image. The defect area in each image is calculated, and the average value is taken as the defect area of the sample pineapple;

[0016] The related features include color features, size features and sugar content features. The image group data of the sample pineapple is converted from RGB to HSV color space, the hue, saturation and brightness data of the image converted to HSV color space are analyzed, and the color index of the image is calculated, with the formula being:

[0017]

[0018] Wherein, CI is the color index of the sample pineapple image, , , H, S, V are hue, saturation and lightness of the sample pineapple image respectively, Hmin, Smin, Vmin are minimum values of hue, saturation and lightness range respectively, Hmax, Smax, Vmax are maximum values of hue, saturation and lightness range respectively;

[0019] The color index of each image of the sample pineapple in the image set data of the sample pineapple is calculated, and the average value of the image set color index is obtained as the color feature of the sample pineapple;

[0020] The gray-scale image of the sample pineapple is converted into a binary image again by a preset pineapple pixel point threshold, the pixel points lower than the pineapple pixel point threshold are marked as background pixel points, and the value is set to 0, the pixel points higher than the pineapple pixel point threshold are marked as pineapple pixel points, and the value is set to 255, thereby obtaining a binary image for pineapple contour detection, extracting the contour in the binary image for pineapple contour detection, traversing the extracted contour, obtaining the maximum inscribed circle of each contour, and calculating the area of the maximum inscribed circle, obtaining the area of the maximum inscribed circle of the sample pineapple in each image of the sample pineapple in the image set data of the sample pineapple, and calculating the average value as the area of the sample pineapple, taking the area of the sample pineapple as the size feature of the sample pineapple;

[0021] The sugar content of the sample pineapple is detected by near-infrared spectroscopy, the number of characteristic absorption peaks in the 900nm-2500nm spectral data range is observed, and the number of characteristic absorption peaks is regarded as a sugar feature.

[0022] Further, determining the quality gradient of each sample pineapple specifically includes:

[0023] The related features and defect features of each sample pineapple in the pineapple sample data set are extracted to form a feature vector of each sample pineapple, represented as:

[0024]

[0025] wherein, (i) is the feature vector of the i-th sample pineapple, Co(i) is the color feature of the i-th sample pineapple, Si(i) is the size feature of the i-th sample pineapple, De(i) is the defect feature of the i-th sample pineapple, and Su(i) is the sugar feature of the i-th sample pineapple;

[0026] The feature vector of each sample pineapple is standardized using a Z-score standardization method, F(i) represents the feature vector of the i-th sample pineapple after standardization, and the number of clusters is set to four, the quality gradient includes four gradients, which are excellent, good, medium and poor respectively, the feature vectors of the sample pineapples of the four known quality gradients are obtained as initial cluster centers, and the iteration step is started, for each sample point, the distance between the sample point and all cluster centers is calculated, and each sample is assigned to the nearest cluster center, and each cluster center is updated to the mean value of all samples in the current cluster, until the change of the cluster center is less than the set threshold, the clustering is completed;

[0027] According to the clustering result, the quality gradient of the sample pineapple in each cluster is divided, and the quality gradient of the initial cluster sample is marked according to the known quality gradient.

[0028] Further, obtaining the defect detection model specifically includes:

[0029] The image data of the sample pineapple in the image group data of the pineapple sample is divided into a training set, a validation set and a test set, the image data of the sample pineapple in the training set is input into the model for training, a convolutional neural network framework is selected as the training model, the corresponding defect feature is selected as the label, the learning rate, batch size and training period are set, after each epoch, the model performance is evaluated using the validation set, cross-entropy is selected as the loss function, and the threshold is set, when the cross-entropy is less than the threshold, the model training is completed, after the training is completed, the test set image is input into the trained model, and the model performance is evaluated using the precision, recall rate and F1-Score index.

[0030] Further, obtaining the defect feature and the related feature of the pineapple to be graded specifically includes:

[0031] The image group data of the pineapple to be graded is collected, and the image data of the pineapple to be graded in the image group data of the pineapple to be graded is also preprocessed, the preprocessed image data is input into the trained defect detection model, and the defect feature of the pineapple to be graded output by the model is obtained;

[0032] Similarly, the image of the pineapple to be graded is converted into an HSV color space, the color index of each image of the pineapple to be graded is calculated, and the average value is taken as the color feature of the pineapple to be graded, the maximum inscribed circle area of each image of the pineapple to be graded is obtained, and the average value is taken as the size feature of the pineapple to be graded, and the near-infrared spectrum of the pineapple to be graded is analyzed to obtain the sugar content feature of the pineapple to be graded.

[0033] Further, determining the feature offset between the pineapple to be graded and each sample pineapple specifically includes:

[0034] The characteristics and defect characteristics of the pineapple to be graded are compared with the characteristics and defect characteristics of each sample pineapple to obtain characteristic offsets, and the specific content includes:

[0035] After the calculation of the clustering is completed, the color characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the color characteristics of the sample pineapples in the corresponding cluster is taken as the color characteristics of the corresponding quality gradient sample pineapple. The color offset calculation formula is:

[0036]

[0037] wherein, is the color offset of the pineapple to be graded and the superior quality gradient sample pineapple, is the color characteristics of the superior quality gradient sample pineapple, is the color characteristics of the pineapple to be graded;

[0038] Similarly, the color offsets of the pineapple to be graded and the good quality gradient sample pineapple, the medium quality gradient sample pineapple and the poor quality gradient sample pineapple are obtained, respectively, as follows:

[0039] After the calculation of the clustering is completed, the size characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the size characteristics of the sample pineapples in the corresponding cluster is taken as the size characteristics of the corresponding quality gradient sample pineapple. The size offset calculation formula is:

[0040]

[0041] wherein, is the size offset of the pineapple to be graded and the superior quality gradient sample pineapple, is the size characteristics of the superior quality gradient sample pineapple, is the size characteristics of the pineapple to be graded;

[0042] Similarly, the size offsets of the pineapple to be graded and the good quality gradient sample pineapple, the medium quality gradient sample pineapple and the poor quality gradient sample pineapple are obtained, respectively, as follows:

[0043] After the calculation of the clustering is completed, the defect characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the defect characteristics of the sample pineapples in the corresponding cluster is taken as the defect characteristics of the corresponding quality gradient sample pineapple. The defect offset calculation formula is:

[0044]

[0045] wherein, is the defect offset of the pineapple to be graded and the superior quality gradient sample pineapple,​​ a defect feature of the good-quality gradient sample pineapple, a defect feature of the pineapple to be graded;

[0046] Similarly, the defect offset of the pineapple to be graded respectively with the good-quality gradient sample pineapple, the defect offset of the pineapple to be graded respectively with the medium-quality gradient sample pineapple, and the defect offset of the pineapple to be graded respectively with the poor-quality gradient sample pineapple are obtained, respectively as ;

[0047] After the calculation of clustering is completed, the sugar content feature of each sample pineapple in each quality gradient cluster is obtained, and the average value of the sugar content features of the sample pineapples in the corresponding cluster is taken as the sugar content feature of the corresponding quality gradient sample pineapple. The sugar content offset calculation formula is:

[0048]

[0049] wherein, the sugar content offset of the pineapple to be graded with the good-quality gradient sample pineapple, a defect feature of the good-quality gradient sample pineapple, a sugar content feature of the pineapple to be graded;

[0050] Similarly, the sugar content offset of the pineapple to be graded respectively with the good-quality gradient sample pineapple, the sugar content offset of the pineapple to be graded respectively with the medium-quality gradient sample pineapple, and the sugar content offset of the pineapple to be graded respectively with the poor-quality gradient sample pineapple are obtained, respectively as .

[0051] Further, determining the sample pineapple most relevant to the pineapple to be graded according to the feature offset includes:

[0052] By analyzing the offset between the relevant features of the pineapple to be graded and the relevant features of the good-quality, good-quality, medium-quality, and poor-quality four quality gradient sample pineapples, the feature offset index formula is:

[0053]

[0054] wherein, FSI is the feature offset index, the color offset, the size offset, the defect offset, the sugar content offset, the weight coefficients of the color offset, the size offset, the defect offset, and the sugar content offset, respectively;

[0055] Respectively calculate the feature offset indexes of the sample pineapples of the four quality gradients, i.e., the good, the fine, the medium and the poor, compared with the pineapple to be graded, sort the feature offset indexes, and take the quality gradient of the sample pineapple corresponding to the smallest feature offset index as the most relevant sample pineapple to the pineapple to be graded, and take the quality gradient corresponding thereto as the quality gradient of the pineapple to be graded.

[0056] The application further provides a pineapple quality grading method and system based on image processing.

[0057] The feature acquisition module is configured to construct a pineapple sample data set, obtain image group data of each sample pineapple and defect features corresponding to the image group data, and analyze the relevant features of the sample pineapple based on the image group data.

[0058] The sample quality determination module is configured to perform feature clustering on the pineapple samples by using an unsupervised clustering algorithm according to the image group data and the corresponding defect features of the sample pineapple, divide the quality gradients according to the clustering results, and determine the quality gradient of each sample pineapple.

[0059] The model construction module is configured to construct a model based on a convolutional neural network, input the image group data of the sample pineapple as features, input the corresponding defect features as output, train the model, and obtain a defect detection model.

[0060] The feature analysis module is configured to collect image group data of the pineapple to be graded, input the image data of the pineapple to be graded in the image group data into the defect detection model, obtain the defect features of the pineapple to be graded, and analyze the image group data of the pineapple to be graded to obtain the relevant features of the pineapple to be graded.

[0061] The quality grading module is configured to traverse all the sample pineapples, determine the feature offset between the pineapple to be graded and the sample pineapple data mean in each quality gradient according to the relevant features and the defect features of the pineapple to be graded and the sample pineapple, determine the sample pineapple most relevant to the pineapple to be graded according to the feature offset, and take the quality gradient corresponding thereto as the quality gradient of the pineapple to be graded.

[0062] The application further provides a computer readable storage medium storing a computer program, the computer program being executed by a processor to implement the pineapple quality grading method based on image processing.

[0063] In the above technical solution, the application has the following technical effects and advantages:

[0064] The present application classifies the pineapple by comprehensively analyzing the color, size, defects and sugar characteristics of the pineapple, adopts multi-angle image acquisition and advanced convolutional neural network technology to identify the defect area of the pineapple, realizes automatic and efficient quality evaluation, and significantly improves the grading accuracy and consistency. Meanwhile, the method also analyzes the characteristics of the color, size and sugar of the pineapple to be graded, and performs feature clustering and defect detection through unsupervised clustering and convolutional neural network model, thereby significantly improving the accuracy and consistency of grading. The calculation of the feature deviation index enables the pineapple to be graded to be accurately compared with the sample pineapple, so as to quantify the difference between the pineapple to be graded and the sample pineapple of different quality gradients, provide comprehensive and systematic quality analysis, and ensure that the evaluation result is objective and reliable. In addition, the present application has strong adaptability and can accurately evaluate different varieties of pineapples, thereby providing a scientific basis for quality management of the fruit industry and improving market competitiveness. BRIEF DESCRIPTION OF DRAWINGS

[0065] Figure 1 It is a whole method flowchart of the present application;

[0066] Figure 2 It is a system structure schematic diagram of the present application. DETAILED DESCRIPTION

[0067] In order to make the purpose, technical scheme and advantages of the present application more clear and obvious, the present application is further described in detail below in combination with specific embodiments.

[0068] It should be noted that, unless otherwise defined, the technical terms or scientific terms used in the present application should be understood as the usual meaning understood by those skilled in the art to which the present application belongs. The "first", "second" and similar words used in the present application do not represent any order, quantity or importance, but are only used to distinguish different components. "Include" or "contain" and similar words mean that the elements or objects before the word cover the elements or objects listed after the word and their equivalents, without excluding other elements or objects. "Connected" or "connected" and similar words are not limited to physical or mechanical connection, but can include electrical connection, whether direct or indirect. "Up", "down", "left", "right" and the like are only used to represent the relative positional relationship, when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0069] EMBODIMENT:

[0070] Please refer to Figure 1 The present application provides a technical scheme:

[0071] A pineapple quality grading method based on image processing, the specific steps comprising:

[0072] Step 1: Constructing a pineapple sample data set, obtaining image group data of each sample pineapple and defect features corresponding to the image group data, and obtaining related features of the sample pineapple based on image group data analysis;

[0073] In this embodiment, obtaining the defect features and the related features of the sample pineapple specifically includes:

[0074] The sample pineapple data set contains sample pineapples of multiple quality gradients, including four gradients of excellent, good, medium, and poor. The image group data includes images taken from different angles of the sample pineapple, at least four images, respectively, images taken from the front, back, left, and right of the pineapple, and collected under the same shooting conditions. The preprocessing includes noise reduction processing and weighted average processing of each image group. Each pixel point is denoised by a Gaussian filter to remove irrelevant factors that interfere with the grading effect of the image. Then, the value of each pixel point is processed, and the value of each pixel point is determined by the weighted average of the values of the pixel point and other pixel points in its neighborhood.

[0075] The defect feature is the defect area. The image group data of each sample pineapple is converted into a grayscale image, and the grayscale formula is:

[0076]

[0077] wherein, is the grayscale value of pixel point i, and the value range is between for an 8-bit image, are the red, green, and blue channel pixel point values of pixel point i in the image of the pineapple to be graded, respectively.

[0078] The grayscale image is converted into a binary image by a preset comprehensive dynamic threshold. Pixel points below the comprehensive dynamic threshold are marked as abnormal pixel points with a value of 0, and pixel points above the comprehensive dynamic threshold are marked as normal pixel points with a value of 255, thereby obtaining a binary image for defect detection. The number of abnormal pixel points in the binary image for defect detection is counted, and the proportion of the number of abnormal pixel points in the total number of pixel points in the image is taken as the defect area of the image. The defect area in each image is calculated, and the average value is taken as the defect area of the sample pineapple.

[0079] Multiple different light conditions are selected for experiments. Different light intensities can be achieved using devices such as light fixtures and reflectors to adjust the light source. Images of the sample pineapple are taken under each light condition, and the shooting conditions are determined to be consistent, such as distance, angle, and background. The light intensity of each shooting is recorded using a light meter, and the photos taken are integrated into sample data. There are at least 5-10 images under each light condition.

[0080] Calculate the mean and standard deviation of the grayscale values ​​for each image to preliminarily determine the dynamic threshold. The formula is as follows:

[0081]

[0082] Where T is the initially determined dynamic threshold. The average grayscale value. The standard deviation of the grayscale value. To adjust the parameters;

[0083] Each image is denoised using a Gaussian filter and then converted to grayscale, assuming a linear relationship exists. L is the light intensity. The slope Let f(L) be the intercept, and f(L) be the light intensity influence factor. Input the light intensity value and use the initially determined dynamic threshold as the output. Use linear regression to fit the data. You can directly use library functions in Python to fit the data to determine the slope and intercept value, thereby obtaining the light intensity influence factor.

[0084] The comprehensive dynamic threshold is determined by combining the influence factors of light intensity as follows:

[0085]

[0086] in, This is a comprehensive dynamic threshold.

[0087] The relevant features include color features, size features, and sugar content features. The image data of the sample pineapple is converted from RGB to HSV color space. The hue, saturation, and brightness data of the image after conversion to HSV color space are analyzed, and the color index of the image is calculated. Specifically, this includes:

[0088] First, the RGB values ​​of the sample pineapple image are normalized to the [0,1] interval. The normalization formula is as follows:

[0089]

[0090] in, These are the normalized values ​​for the R, G, and B channels. The values ​​of the R, G, and B channels of the directly acquired sample pineapple images;

[0091] Calculate the maximum and minimum values ​​of the RGB color components for each pixel, expressed as:

[0092]

[0093] in, For the first The maximum value of the RGB color components of each pixel. For the first The minimum value of the RGB color components of each pixel;

[0094] The formula for calculating hue is as follows;

[0095]

[0096] in, For the first The hue of each pixel;

[0097]

[0098] in, The hue of the sample pineapple image. This represents the total number of pixels.

[0099] The formula for calculating saturation is as follows:

[0100]

[0101] in, For the first Saturation of each pixel;

[0102]

[0103] in, The saturation of the sample pineapple image;

[0104] The formula for calculating lightness is as follows:

[0105]

[0106] in, For the first The brightness of each pixel;

[0107]

[0108] in, The brightness of the sample pineapple.

[0109] The formula used to obtain the color index is:

[0110]

[0111] in, The color index of the sample pineapple image. These are the minimum values ​​for hue, saturation, and lightness, respectively. These represent the maximum values ​​for hue, saturation, and lightness, respectively. The minimum hue value is 0°, and the maximum value is 360°. The minimum saturation value is 0, and the maximum value is 1. The minimum lightness value is 0, and the maximum value is 1.

[0112] By converting the RGB image to HSV color space, the color characteristics of pineapples can be analyzed more effectively. The HSV model is more consistent with human visual perception than RGB, making color changes more intuitive and facilitating quantitative analysis of the appearance of pineapples. By normalizing RGB values and calculating hue, saturation, and lightness, it ensures that the analysis of each color channel is objective and consistent. This method reduces the impact of lighting changes and device differences during image acquisition on color evaluation results. The color index is a comprehensive indicator that quantifies the overall color characteristics of the pineapple image to be graded. It combines the results of hue, saturation, and lightness calculations, reflecting the richness and balance of colors in the image. The numerical range of the color index depends on the minimum and maximum values set. Higher values indicate better color characteristics, usually meaning that the pineapple has a more vibrant and mature color, providing a good visual experience for consumers. Conversely, lower values may indicate that the pineapple has a dull color and insufficient maturity, affecting market appeal. By calculating the color index, graders can quickly and objectively assess the color quality of pineapples. The automated calculation of this indicator helps improve grading efficiency and reduce the impact of human factors, thereby enhancing the market competitiveness of fruits and consumers' purchasing decisions. Hue reflects the specific properties of colors (such as red, yellow, green, etc.), and different hues have a significant impact on the appearance and market acceptance of pineapples. Changes in hue directly affect the calculation of the color index, as it is one of the components of this indicator. Saturation represents the brightness of the color, and the higher the saturation, the brighter the color. The level of saturation directly affects consumers' choices, as vibrant colors are usually more eye-catching. Lightness represents the brightness of the color, and pineapples with high lightness usually appear more attractive and mature. Changes in lightness also affect the color index because it, along with hue and saturation, determines the overall performance of the color. When hue, saturation, or lightness increases, the color index usually increases. This is because higher hue, saturation, and lightness values all represent pineapples with more vibrant and mature colors, thereby improving the overall color quality evaluation. Hue, saturation, and lightness are all positive indicators, and if these values increase, the CI will also increase, indicating that the color characteristics of the sample pineapple are more superior and the color is more vibrant.

[0113] Calculate the color index of each image in the image set data of the sample pineapple, and then calculate the average value of the color index of the image set, taking the average value as the color characteristics of the sample pineapple.

[0114] The grayscale image of the sample pineapple is converted back into a binary image by setting a preset pineapple pixel threshold. Pixels below the threshold are marked as background pixels with a value of 0, while pixels above the threshold are marked as pineapple pixels with a value of 255, thus obtaining a binary image for pineapple contour detection. Contours are extracted from this binary image using Python functions, such as `cv2.findContours`, and `RETR_EXTERNAL` is used to retrieve only the outermost contour. The extracted contours are iterated through, and the maximum inscribed circle of each contour is obtained. The area of ​​the maximum inscribed circle is calculated, and the area of ​​the maximum inscribed circle of the sample pineapple in each image in the sample pineapple image set is obtained. The average area is then used as the area of ​​the sample pineapple, and this area is used as the size feature of the sample pineapple. The pineapple pixel threshold can be obtained from a grayscale image that distinguishes between the pineapple and the background. The average pixel threshold of the pineapple region in the grayscale image can be used as the pineapple pixel threshold, or a comprehensive dynamic thresholding method can be referenced.

[0115] The sugar content of pineapple samples was detected by near-infrared spectroscopy. The number of characteristic absorption peaks in the spectral data range of 900nm-2500nm was observed, and the number of characteristic absorption peaks was regarded as the sugar content characteristic.

[0116] In the 900nm-1100nm range, the absorption characteristics are usually associated with water and can be used to assess the water content of a sample, as water content affects sugar content determination. In the 1100nm-1450nm range, carbohydrates, such as glucose and fructose, begin to show obvious absorption characteristics, and this range includes the characteristic absorption peaks of sugars. In the 1450nm-1930nm range, this region is mainly associated with the vibrational modes of carbon-hydrogen bonds, and the spectral characteristics of carbohydrates in this region can usually help distinguish different types of sugars. In the 1930nm-2500nm range, the spectrum is mainly associated with the absorption characteristics of hydroxyl groups and carbon-hydrogen bonds, and also includes the characteristic absorption signals of sugars, making it suitable for quantitative analysis. Generally, high-quality pineapples contain more than 4 characteristic absorption peaks, good-quality pineapples contain 3 characteristic absorption peaks, medium-quality pineapples contain a maximum of 2 characteristic absorption peaks, and poor-quality pineapples contain a maximum of 1 characteristic absorption peak.

[0117] Step 2: Based on the image group data of the sample pineapples and the corresponding defect features, use an unsupervised clustering algorithm to perform feature clustering on the pineapple samples, divide the quality gradient according to the clustering results, and determine the quality gradient of each sample pineapple.

[0118] In this embodiment, determining the quality gradient of each pineapple sample specifically includes:

[0119] The relevant features and defect features of each sample pineapple in the pineapple sample data set are extracted to form a feature vector of each sample pineapple, denoted as:

[0120]

[0121] wherein, (i) is the feature vector of the i-th sample pineapple, Co(i) is the color feature of the i-th sample pineapple, Si(i) is the size feature of the i-th sample pineapple, De(i) is the defect feature of the i-th sample pineapple, and Su(i) is the sugar content feature of the i-th sample pineapple;

[0122] The feature vector of each sample pineapple is standardized using the Z-score standardization method, and F(i) represents the feature vector of the i-th sample pineapple after standardization;

[0123] The quality gradient includes four gradients, namely excellent, good, medium and poor, and is set to four clustering numbers. The feature vectors of the sample pineapples of the four known quality gradients are obtained as initial clustering centers, and the iteration step is started. For each sample point, the distance from all clustering centers is calculated, and the Euclidean distance can be used. The distance formula is represented as:

[0124]

[0125] wherein, is the clustering center to which the sample is assigned, is the x-th sample, and k is the clustering center index, wherein k∈[1, 4];

[0126] Each sample is assigned to the nearest clustering center, i.e. the clustering center with the smallest distance. Each clustering center is updated to the mean value of all samples in the current cluster, until the change of the clustering center is less than the set threshold, and the clustering is completed;

[0127] The update rule is:

[0128]

[0129] wherein, is the number of samples in the clustering k, is the sample point of the data clustering k;

[0130] The following conditions can be used to judge convergence:

[0131]

[0132] wherein, is the clustering center before updating, is the clustering center after updating, a set threshold value;

[0133] According to the clustering result, the quality gradient of the sample pineapple in each cluster is divided, and the quality gradient label of the known initial clustering sample is marked.

[0134] Here, the sample pineapple of the four quality gradients can be determined by experts.

[0135] Step 3: Construct a model based on a convolutional neural network, input the image group data of the sample pineapple as a feature, and train the model with the corresponding defect feature as the output to obtain a defect detection model;

[0136] In this embodiment, obtaining the defect detection model specifically includes:

[0137] The image data of the sample pineapple in the image group data of the pineapple sample is divided into a training set, a validation set and a test set, the image data of the sample pineapple in the training set is input into the model for training, a convolutional neural network framework is selected as the training model, the corresponding defect feature is used as a label, a learning rate, a batch size and a training period are set, the learning rate is set to 0.001, the batch size is set to 32, and the training period is set to 50, after each epoch, the model performance is evaluated using the validation set, cross-entropy is selected as the loss function, and a threshold value is set, when the cross-entropy is less than the threshold value, it indicates that the model training is completed, the threshold value can be set to 0.1, after the training is completed, the test set image is input into the trained model, and the model performance is evaluated using the precision, recall rate and F1-Score indicators, when the accuracy rate is 0.75 or higher, it is considered that the model performance is good, when the recall rate is 0.8 or higher, it is considered that the model performance is good, when the F1-Score is 0.7 or higher, it is considered that the model performance is good, if the precision, recall rate and F1-Score of the model are all good or above, it is considered that the model is an excellent model, if the evaluation indicators are all lower than the good indicators, consider increasing the data amount to retrain the model.

[0138] Step 4: Collect image group data of the pineapple to be graded, input the image data of the pineapple to be graded in the image group data into the defect detection model, obtain the defect feature of the pineapple to be graded, and analyze the image group data of the pineapple to be graded to obtain the related features of the pineapple to be graded;

[0139] In this embodiment, obtaining the defect feature and the related feature of the pineapple to be graded specifically includes:

[0140] The image group data of the pineapple to be graded is collected, and the image data of the pineapple to be graded is collected from at least four directions of front, rear, left and right, the image group data of the pineapple to be graded is preprocessed by Gaussian filtering and weighted average, the preprocessed image data is input into the trained defect detection model, and the defect features of the pineapple to be graded output by the model are obtained;

[0141] Similarly, the image of the pineapple to be graded is converted into an HSV color space, the color index of each pineapple to be graded image is calculated, and the average value is taken as the color feature of the pineapple to be graded. The maximum inscribed circle area of each image in the pineapple to be graded image is obtained, and the average value is taken as the size feature of the pineapple to be graded. The near-infrared spectrum of the pineapple to be graded is analyzed to obtain the sugar content feature of the pineapple to be graded.

[0142] Step 5: All sample pineapples are traversed, the feature offset between the pineapple to be graded and the sample pineapple data mean in each quality gradient is determined according to the related features and defect features of the pineapple to be graded and the sample pineapple, and the sample pineapple most related to the pineapple to be graded is determined according to the feature offset, and the corresponding quality gradient is taken as the quality gradient of the pineapple to be graded.

[0143] In this embodiment, the feature offset between the pineapple to be graded and each sample pineapple specifically includes:

[0144] All sample pineapples are traversed, and the related features and defect features of the pineapple to be graded are compared with the related features and defect features of each sample pineapple to obtain the feature offset, and the specific content includes:

[0145] After the calculation of clustering is completed, the color features of each sample pineapple in each quality gradient cluster are calculated, the average value of the color features of the sample pineapples in the corresponding cluster is taken as the color feature of the sample pineapple of the corresponding quality gradient, and the color offset calculation formula is:

[0146]

[0147] Among them, is the color offset of the pineapple to be graded and the sample pineapple of the excellent quality gradient, is the color feature of the sample pineapple of the excellent quality gradient, is the color feature of the pineapple to be graded;

[0148] Similarly, the color offset of the pineapple to be graded and the sample pineapple of the good quality gradient, the color offset of the sample pineapple of the medium quality gradient, and the color offset of the sample pineapple of the poor quality gradient are obtained, respectively ;

[0149] After the calculation of clustering, the size characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the size characteristics of the sample pineapple in the corresponding cluster is taken as the size characteristics of the corresponding quality gradient sample pineapple. The size offset calculation formula is:

[0150]

[0151] wherein, is the size offset of the pineapple to be graded and the superior quality gradient sample pineapple, is the size characteristics of the superior quality gradient sample pineapple, is the size characteristics of the pineapple to be graded;

[0152] Similarly, the size offset of the pineapple to be graded and the good quality gradient sample pineapple, the size offset of the pineapple to be graded and the medium quality gradient sample pineapple, and the size offset of the pineapple to be graded and the poor quality gradient sample pineapple are obtained, respectively,

[0153] After the calculation of clustering, the defect characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the defect characteristics of the sample pineapple in the corresponding cluster is taken as the defect characteristics of the corresponding quality gradient sample pineapple. The defect offset calculation formula is:

[0154]

[0155] wherein, is the defect offset of the pineapple to be graded and the superior quality gradient sample pineapple, is the defect characteristics of the superior quality gradient sample pineapple, is the defect characteristics of the pineapple to be graded;

[0156] Similarly, the defect offset of the pineapple to be graded and the good quality gradient sample pineapple, the defect offset of the pineapple to be graded and the medium quality gradient sample pineapple, and the defect offset of the pineapple to be graded and the poor quality gradient sample pineapple are obtained, respectively,

[0157] After the calculation of clustering, the sugar content characteristics of each sample pineapple in each quality gradient cluster are obtained, and the average value of the sugar content characteristics of the sample pineapple in the corresponding cluster is taken as the sugar content characteristics of the corresponding quality gradient sample pineapple. The sugar content offset calculation formula is:

[0158]

[0159] wherein, is the sugar content offset of the pineapple to be graded and the superior quality gradient sample pineapple, is the defect characteristics of the superior quality gradient sample pineapple, is the sugar content characteristics of the pineapple to be graded;

[0160] ​​Similarly, the sugar deviation of the to-be-graded pineapple and the good-quality gradient sample pineapple, the sugar deviation of the medium-quality gradient sample pineapple, and the sugar deviation of the poor-quality gradient sample pineapple are obtained, respectively, as .

[0161] In this embodiment, the sample pineapple most relevant to the to-be-graded pineapple is determined according to the feature deviation, and the sample pineapple most relevant to the to-be-graded pineapple specifically includes:

[0162] By analyzing the deviation between the relevant features of the to-be-graded pineapple and the relevant features of the good-quality, good-quality, medium-quality, and poor-quality gradient sample pineapples, the feature deviation index formula is calculated as:

[0163]

[0164] wherein, FSI is the feature deviation index, is the color deviation, is the size deviation, is the defect deviation, is the sugar deviation, are weight coefficients of the color deviation, the size deviation, the defect deviation, and the sugar deviation, .

[0165] The feature deviation index of the to-be-graded pineapple compared with the good-quality, good-quality, medium-quality, and poor-quality gradient sample pineapples is calculated, respectively. The quality gradient of the sample pineapple corresponding to the smallest feature deviation index is regarded as the sample pineapple most relevant to the to-be-graded pineapple, and the quality gradient corresponding thereto is regarded as the quality gradient of the to-be-graded pineapple.

[0166] FSI is a comprehensive index, reflecting the overall deviation of the to-be-graded pineapple in color, size, defect, and sugar. It quantifies the difference between the to-be-graded pineapple and the standard sample (good-quality, good-quality, medium-quality, and poor-quality gradient) in these four features through weighted summation. When comparing the four features with the good-quality gradient sample pineapple, the smaller the FSI value, the closer the features of the to-be-graded pineapple to the good-quality gradient sample, and the higher the quality. Conversely, the larger the FSI value, the farther the features of the to-be-graded pineapple from the good-quality gradient sample, and the lower the quality. Similarly, when comparing the four features with the good-quality, medium-quality, and poor-quality gradient sample pineapples, the smaller the FSI value, the closer to the quality gradient, and the larger the FSI value, the farther from the quality gradient.

[0167] The offset of the relevant features represents the offset of the pineapple to be graded in each relevant feature relative to the different quality samples. Color affects visual quality, and consumers' first impression of fruit often depends on color, and color offset reflects problems such as maturity and rot. Size offset is related to the market value and appearance appeal of the fruit, and size deviation will affect market acceptance. Defect offset directly affects the edibility and safety of the fruit, and the increase of defects means the decrease of product quality. Sugar offset affects the taste and flavor of the fruit, and fruits with high sugar content are usually more popular.

[0168] In the comparison of the relevant features of the sample pineapple of the superior quality gradient, when the offset of the relevant features of the pineapple to be graded increases, the corresponding feature offset index also increases, indicating that the pineapple to be graded deviates from the superior quality gradient. Similarly, in the comparison of the relevant features of the sample pineapple of the good quality gradient, when the offset of the relevant features of the pineapple to be graded increases, the corresponding feature offset index also increases, indicating that the pineapple to be graded deviates from the good quality gradient. In the comparison of the relevant features of the sample pineapple of the medium quality gradient, when the offset of the relevant features of the pineapple to be graded increases, the corresponding feature offset index also increases, indicating that the pineapple to be graded deviates from the medium quality gradient. In the comparison of the relevant features of the sample pineapple of the poor quality gradient, when the offset of the relevant features of the pineapple to be graded increases, the corresponding feature offset index also increases, indicating that the pineapple to be graded deviates from the poor quality gradient. Conversely, if the offset of the relevant features of the pineapple to be graded decreases, the corresponding feature offset index will also decrease, indicating that the pineapple to be graded is closer to the quality gradient of the sample pineapple currently compared, and therefore the quality gradient of the sample pineapple corresponding to the minimum feature offset index is taken as the quality gradient of the pineapple to be graded.

[0169] The presence or absence of defect features directly determines the edibility and safety of the fruit. Any obvious defect (such as rot, disease spot, insect damage, etc.) will affect the consumer's willingness to buy and trust in food safety, and the corresponding quality gradient will also decrease a lot. Defects are the primary factor affecting fruit quality, and any defect will cause the product to be directly considered unqualified, so it is set to the highest weight. Color not only relates to the maturity and taste of the fruit, but also directly affects the first impression of consumers. Good color is usually associated with better flavor and quality. Although color plays an important role in consumers' choices, if the fruit has significant defects, consumers will usually prioritize the impact of defects, so its weight should be lower than the defect offset. Size affects the market standards of the fruit and to some extent affects the sales price and consumers' purchase decisions, so it is set to a lower weight. Sugar affects the taste and flavor of the fruit, but consumers cannot directly observe the sugar content when selecting, so it is set to the lowest weight.

[0170] Please refer to Figure 2The application further provides a pineapple quality grading method and system based on image processing.

[0171] The feature acquisition module is configured to construct a pineapple sample data set, obtain image group data of each sample pineapple and defect features corresponding to the image group data, and obtain relevant features of the sample pineapple based on image group data analysis;

[0172] The sample quality determination module is configured to perform feature clustering on the pineapple samples by using an unsupervised clustering algorithm according to the image group data and the corresponding defect features of the sample pineapples, divide quality gradients according to the clustering results, and determine the quality gradient of each sample pineapple.

[0173] The model construction module is configured to construct a model based on a convolutional neural network, input the image group data of the sample pineapples as features, and input the corresponding defect features as output to train the model, thereby obtaining a defect detection model.

[0174] The feature analysis module is configured to collect image group data of the pineapple to be graded, input the image data of the pineapple to be graded in the image group data into the defect detection model, obtain the defect features of the pineapple to be graded, and analyze the image group data of the pineapple to be graded to obtain the relevant features of the pineapple to be graded.

[0175] The quality grading module is configured to traverse all the sample pineapples, determine the feature offset between the pineapple to be graded and the sample pineapple data mean according to the relevant features and the defect features of the pineapple to be graded and the sample pineapples, determine the sample pineapple most relevant to the pineapple to be graded according to the feature offset, and take the quality gradient corresponding to the sample pineapple as the quality gradient of the pineapple to be graded.

[0176] The application further provides a computer readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the pineapple quality grading method based on image processing.

[0177] The above formulas are dimensionless numerical calculations, and the formulas are obtained by software simulation of a large amount of data to obtain a formula of the nearest real situation, and the preset parameters in the formula are set by a person skilled in the art according to the actual situation.

[0178] The above-described embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented by software, the above-described embodiments can be implemented in whole or in part in the form of a computer program product. A person of ordinary skill in the art can be aware that units and algorithm steps of the examples described in connection with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether the functions are performed by hardware or software depends on the specific application and design constraints of the technical solutions.

[0179] The units described as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, and can be located in one place or distributed on multiple network units. Part or all of the units can be selected to achieve the purpose of the embodiments according to actual needs.

[0180] The above describes only specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered within the protection scope of the present application.

Claims

1. A method for grading the quality of pineapples based on image processing, characterized by, The specific steps include: Step 1: Constructing a pineapple sample data set, obtaining image group data of each sample pineapple and defect features corresponding to the image group data, and obtaining related features of the sample pineapple based on image group data analysis; the image group data includes images of the sample pineapple taken from different angles and near-infrared spectrum images of the sample pineapple; the defect features are defect areas; the related features include color features, size features, and sugar content features; Step 2: According to the image group data and corresponding defect features of the sample pineapple, using an unsupervised clustering algorithm to cluster the features of the pineapple sample, dividing the quality gradient according to the clustering results, and determining the quality gradient of each sample pineapple; Step 3: Constructing a model based on a convolutional neural network, inputting the image group data of the sample pineapple as features, and training the model with corresponding defect features as output to obtain a defect detection model; Step 4: Collecting image group data of the pineapple to be graded, inputting the image data of the pineapple to be graded in the image group data into the defect detection model, obtaining the defect features of the pineapple to be graded, and analyzing the image group data of the pineapple to be graded to obtain the related features of the pineapple to be graded; Step 5: Traversing all sample pineapples, determining the feature offset between the pineapple to be graded and the sample pineapple data mean in each quality gradient according to the related features and defect features of the pineapple to be graded and the sample pineapple, and determining the sample pineapple most relevant to the pineapple to be graded according to the feature offset, and taking the corresponding quality gradient as the quality gradient of the pineapple to be graded; The feature offset between the pineapple to be graded and each sample pineapple is determined, which includes: Traversing all sample pineapples, comparing the related features and defect features of the pineapple to be graded with the related features and defect features of each sample pineapple to obtain the feature offset, which includes: After clustering, the color features of the sample pineapples in each quality gradient are calculated, and the average value of the color features of all sample pineapples in the same quality gradient is taken as the color feature of the sample pineapple in that quality gradient, and the color offset is calculated as: wherein, is the color shift of the pineapple to be graded and the color characteristics of the high quality gradient sample pineapple, is the color characteristics of the high quality gradient sample pineapple, is the color characteristics of the pineapple to be graded; Similarly, the color deviation of the to-be-graded pineapple and the good-quality gradient sample pineapple, the color deviation of the medium-quality gradient sample pineapple, and the color deviation of the poor-quality gradient sample pineapple are obtained, respectively, as ; After clustering, the size features of the sample pineapples in each quality gradient are calculated, and the average value of the size features of all sample pineapples in the same quality gradient is taken as the size feature of the sample pineapple in that quality gradient, and the size offset is calculated as: wherein, is a size offset for the pineapple to be graded and the premium quality gradient sample pineapple, is a size characteristic of the premium quality gradient sample pineapple, is a size characteristic of the pineapple to be graded; Similarly, the size offset of the to-be-graded pineapple and the good quality gradient sample pineapple, the size offset of the medium quality gradient sample pineapple and the size offset of the poor quality gradient sample pineapple are obtained respectively, which are ; After clustering, the defect features of the sample pineapples in each quality gradient are calculated, and the average value of the defect features of all sample pineapples in the same quality gradient is taken as the defect feature of the sample pineapple in that quality gradient, and the defect offset is calculated as: wherein, is a defect bias for the pineapple to be graded and the good quality gradient sample pineapple, is a defect feature of the good quality gradient sample pineapple, is a defect feature of the pineapple to be graded; Similarly, the defect offset of the to-be-graded pineapple and the defect offset of the good-quality gradient sample pineapple, the defect offset of the medium-quality gradient sample pineapple and the defect offset of the poor-quality gradient sample pineapple are obtained, respectively, as ; After clustering, the sugar content features of the sample pineapples in each quality gradient are calculated, and the average value of the sugar content features of all sample pineapples in the same quality gradient is taken as the sugar content feature of the sample pineapple in that quality gradient, and the sugar content offset is calculated as: wherein, is a sugar deviation of the pineapple to be graded from the sugar of the premium quality gradient sample pineapple, is a defect feature of the premium quality gradient sample pineapple, is a sugar feature of the pineapple to be graded; Similarly, the sugar deviation of the to-be-graded pineapple and the good-quality gradient sample pineapple, the sugar deviation of the medium-quality gradient sample pineapple, and the sugar deviation of the poor-quality gradient sample pineapple are obtained, respectively, as .

2. A method of classifying the quality of pineapples based on image processing according to claim 1, characterized in that, The defect features and related features of the sample pineapple are obtained, which include: The sample pineapple data set contains sample pineapples of multiple different quality gradients, including four gradients of excellent, good, medium and poor; the preprocessing includes noise reduction processing and weighted average processing on the image of each group of sample pineapples, each pixel point is subjected to Gaussian filter noise reduction, and the value of each pixel point is determined by weighted average of the value of the pixel point and other pixel points in the neighborhood of the pixel point; The image group data of each sample pineapple is converted into a gray-scale image, the gray-scale image is converted into a binary image through a preset comprehensive dynamic threshold, the pixel points lower than the comprehensive dynamic threshold are marked as abnormal pixel points and the value is set to 0, the pixel points higher than the comprehensive dynamic threshold are marked as normal pixel points and the value is set to 255, so as to obtain a binary image for defect detection, the number of abnormal pixel points in the binary image for defect detection is counted, and the proportion of the number of abnormal pixel points in the total number of pixel points of the image is taken as the defect area of the image, and the defect area in each image is calculated, and the average value is taken as the defect area of the sample pineapple; The image group data of the sample pineapple is converted from RGB to HSV color space, the hue, saturation and lightness data of the image converted to HSV color space are analyzed, and the color index of the image is calculated, and the formula is: wherein CI is a color index of the sample pineapple image, , , H, S, and V are hue, saturation, and lightness of the sample pineapple image, respectively, Hmin, Smin, and Vmin are minimum values of the hue, saturation, and lightness ranges, respectively, Hmax, Smax, and Vmax are maximum values of the hue, saturation, and lightness ranges, respectively. The color index of each image of the sample pineapple in the image group data of the sample pineapple is calculated, and the average value of the color index of the image group is calculated, and the average value is taken as the color feature of the sample pineapple; The gray-scale image of the sample pineapple is converted into a binary image again through a preset pineapple pixel point threshold, the pixel points lower than the pineapple pixel point threshold are marked as background pixel points and the value is set to 0, and the pixel points higher than the pineapple pixel point threshold are marked as pineapple pixel points and the value is set to 255, so as to obtain a binary image for pineapple contour detection, the contours in the binary image for pineapple contour detection are extracted, each contour is traversed to obtain the maximum inscribed circle of each contour, and the area of the maximum inscribed circle is calculated, the area of the maximum inscribed circle of the sample pineapple in each image of the sample pineapple in the image group data of the sample pineapple is obtained, and the average value is calculated as the area of the sample pineapple, and the area of the sample pineapple is taken as the size feature of the sample pineapple; The sugar content of the sample pineapple is detected by near-infrared spectroscopy, the number of characteristic absorption peaks in the range of 900nm-2500nm spectral data is observed, and the number of characteristic absorption peaks is regarded as the sugar feature.

3. The method for pineapple quality grading based on image processing according to claim 1, characterized in that, Determining the quality gradient of each sample pineapple specifically includes: The related features and defect features of each sample pineapple in the pineapple sample data set are extracted to form a feature vector of each sample pineapple, which is represented as: wherein, (i) is the feature vector of the i-th sample pineapple, Co(i) is the color feature of the i-th sample pineapple, Si(i) is the size feature of the i-th sample pineapple, De(i) is the defect feature of the i-th sample pineapple, and Su(i) is the sugar content feature of the i-th sample pineapple. The feature vector of each sample pineapple is standardized by using a Z-score standardization method, F(i) represents the feature vector of the i-th sample pineapple after standardization, and four cluster numbers are set, the quality gradient includes four gradients, which are excellent, good, medium and poor respectively, the feature vectors of the sample pineapples of the four known quality gradients are obtained as initial cluster centers, and the iteration step is started, for each sample point, the distance between the sample point and all cluster centers is calculated, and each sample is assigned to the nearest cluster center, and each cluster center is updated as the mean value of all samples in the current cluster, until the change of the cluster center is less than the set threshold, the clustering is completed; According to the clustering result, the quality gradient of the sample pineapple in each cluster is divided, and the quality gradient of the known initial cluster sample is marked.

4. The method for pineapple quality grading based on image processing according to claim 1, characterized in that, The defect detection model is obtained, specifically including: The image data of the sample pineapple in the image group data of the pineapple sample is divided into a training set, a validation set and a test set, the image data of the sample pineapple in the training set is input into the model for training, a convolutional neural network framework is selected as the training model, the corresponding defect feature is selected as the label, the learning rate, batch size and training period are set, after each epoch, the model performance is evaluated using the validation set, cross-entropy is selected as the loss function, and the threshold is set, when the cross-entropy is less than the threshold, the model training is completed, and after the training is completed, the test set image is input into the trained model, and the model performance is evaluated using the precision, recall rate and F1-Score index.

5. The method for pineapple quality grading based on image processing according to claim 1, characterized in that, The defect feature and the related feature of the pineapple to be graded are obtained, specifically including: The image group data of the pineapple to be graded is collected, and the image data of the pineapple to be graded in the image group data of the pineapple to be graded is also preprocessed, the preprocessed image data is input into the trained defect detection model, and the defect feature of the pineapple to be graded output by the model is obtained; The image of the pineapple to be graded is also converted into an HSV color space, the color index of each image of the pineapple to be graded is calculated, and the average value is taken as the color feature of the pineapple to be graded, the maximum inscribed circle area of each image of the pineapple to be graded is obtained, and the average value is taken as the size feature of the pineapple to be graded, and the near-infrared spectrum of the pineapple to be graded is analyzed to obtain the sugar content feature of the pineapple to be graded.

6. The method for pineapple quality grading based on image processing according to claim 1, characterized in that, The sample pineapple most related to the pineapple to be graded is determined according to the feature offset, specifically including: The offset between the related features of the pineapple to be graded and the related features of the sample pineapples of the four quality gradients, excellent, good, medium and poor, is analyzed, and the feature offset index formula is calculated as follows: wherein FSI is a feature shift index, is a color shift amount, is a size shift amount, is a defect shift amount, is a sugar shift amount, are weight coefficients of the color shift amount, the size shift amount, the defect shift amount, and the sugar shift amount, respectively. The feature offset index of the pineapple to be graded compared with the sample pineapples of the four quality gradients, excellent, good, medium and poor, is calculated respectively, the feature offset index is sorted, the quality gradient of the sample pineapple corresponding to the smallest feature offset index is regarded as the sample pineapple most related to the pineapple to be graded, and the quality gradient corresponding thereto is taken as the quality gradient of the pineapple to be graded.

7. A pineapple quality grading system based on image processing, characterized by, The pineapple quality grading system based on image processing is used to realize the pineapple quality grading method based on image processing according to any one of claims 1-6, comprising: The feature acquisition module is configured to construct a pineapple sample data set, obtain image group data of each sample pineapple and defect features corresponding to the image group data, and analyze the image group data to obtain related features of the sample pineapple; The sample quality determination module is configured to perform feature clustering on the pineapple samples by using an unsupervised clustering algorithm according to the image group data and the corresponding defect features of the sample pineapples, divide quality gradients according to a clustering result, and determine a quality gradient of each sample pineapple; The model construction module is configured to construct a model based on a convolutional neural network, input the image group data of the sample pineapples as features, input the corresponding defect features as output, train the model, and obtain a defect detection model; The feature analysis module is configured to collect image group data of a pineapple to be graded, input image data of the pineapple to be graded in the image group data into the defect detection model, obtain defect features of the pineapple to be graded, and analyze the image group data of the pineapple to be graded to obtain related features of the pineapple to be graded; The quality grading module is configured to traverse all the sample pineapples, determine feature offset conditions between the pineapple to be graded and sample pineapple data mean values in each quality gradient according to the related features and the defect features of the pineapple to be graded and the sample pineapples, determine a sample pineapple most relevant to the pineapple to be graded according to the feature offset conditions, and take a quality gradient of the sample pineapple as a quality gradient of the pineapple to be graded.

8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program, when executed by the processor, implements the pineapple quality grading method based on image processing according to any one of claims 1-6.

Citation Information

Patent Citations

  • Hyperspectrum-based fruit quality detection method, equipment and medium

    CN112974303A

  • Design and development of digital fruit and spices quality identification technology

    IN202431052021A