Apple quality analysis and evaluation method based on image recognition

By greying and partitioning the Apple surface image, optimizing the grayscale value and calculating the color uniformity index, the problem of inaccurate Apple quality assessment in the existing technology is solved, and a more accurate Apple quality assessment is achieved.

CN118691690BActive Publication Date: 2024-11-08SHAANXI MEIMEIJIAYUAN AGRI TECH DEV CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411155116.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-22
Publication Date
2024-11-08
Estimated Expiration
2044-08-22

AI Technical Summary

Technical Problem

The prior art is difficult to accurately evaluate the quality of apples, especially for good quality apples, because the peel is smooth and flawless, and the color is bright and uniform, resulting in the image segmentation results being unable to accurately determine their quality level.

Method used

By acquiring the image of the apple surface, a square window is constructed, partitioned according to the distribution characteristics of the skin hole, divided normal points and abnormal points, optimized grayscale values, calculate the uniform grayscale distribution index, and then obtain the overall uniform color index. Evaluate the quality of Apple.

Benefits of technology

It improves the accuracy of Apple's quality level classification, can accurately evaluate Apple's quality based on the uniformity of the surface color of the apple, and enhances the reliability of quality evaluation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118691690B_ABST
    Figure CN118691690B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of image processing technology, and in particular to an apple quality analysis and evaluation method based on image recognition. The method targets apples of the same batch, obtains a grayscale image of each apple according to a surface image of the apple, performs adaptive division according to distribution characteristics of a lenticel area in each grayscale image to obtain an optimal table, divides each grayscale image into a plurality of partitions based on the optimal table, obtains a grayscale distribution uniformity index of each partition according to the grayscale values ​​of pixels in the partition, obtains an overall color uniformity index of each grayscale image according to the grayscale distribution uniformity index of each partition, and determines the quality grade of the apple according to the overall color uniformity index of each grayscale image, thereby improving the accuracy of apple quality grade classification according to the surface image of the apple.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image processing, and in particular to an apple quality analysis and evaluation method based on image recognition. Background Art

[0002] Apples are an everyday fruit. As people's quality of life improves, their requirements for food quality continue to rise. When buying apples, people tend to prefer good quality apples. Moreover, the seeds of good quality apples are more likely to grow good quality apples. Therefore, it is necessary to analyze and evaluate the quality of apples in the orchard.

[0003] In the prior art, when evaluating the quality of apples, image segmentation and processing technology is used to determine whether the apples have obvious defects, and then the quality grade of the apples is determined based on the uniformity of the surface color in the area after image segmentation.

[0004] However, since the skin of good quality apples is smooth and flawless, the color is bright and uniform, the color changes on the corresponding apple surface are relatively subtle, and there are no obvious edge points, and the overall grayscale values ​​are very close, it is impossible to use the results of image segmentation to accurately determine the quality grade of the apples.

[0005] Therefore, how to improve the accuracy of grading apple quality based on apple surface images has become an urgent problem to be solved. Summary of the invention

[0006] In view of this, an embodiment of the present invention provides an apple quality analysis and evaluation method based on image recognition to solve the problem of how to improve the accuracy of grading apple quality based on apple surface images.

[0007] An embodiment of the present invention provides an apple quality analysis and evaluation method based on image recognition, the method comprising the following steps:

[0008] For apples of the same batch, respectively obtain a surface image of each apple, perform grayscale processing on each surface image, and obtain a corresponding grayscale image;

[0009] Constructing a square window containing an apple in each of the grayscale images, obtaining an optimal table for dividing all the square windows according to the lenticel distribution characteristics in each of the square windows, and dividing each of the square windows into a plurality of partitions according to the optimal table;

[0010] For any partition in any square window, the pixels in the partition are divided into a normal point set and an abnormal point set, the grayscale value of each pixel in the abnormal point set is optimized to obtain the corresponding optimized grayscale value, all the optimized grayscale values ​​and the grayscale value of each pixel in the normal point set are sorted according to size to obtain the corresponding grayscale value optimization set, the grayscale distribution uniformity index of the partition is obtained according to the grayscale value optimization set, and the overall color uniformity index of the square window is obtained according to the grayscale distribution uniformity index of each partition in the square window;

[0011] The overall color uniformity index of each of the square windows is obtained, and the quality of the apples in the same batch is evaluated according to the overall color uniformity index of each of the square windows.

[0012] Preferably, constructing a square window containing an apple in each of the grayscale images comprises:

[0013] For any grayscale image, edge detection is performed on the grayscale image to obtain the edge of the apple in the grayscale image, the vertical distance between every two edge points on the apple edge is calculated respectively, the maximum vertical distance is obtained as the initial window side length, and a square window containing the apple in the grayscale image is constructed with the length of the initial window side length.

[0014] Preferably, obtaining the best table for dividing all the square windows according to the pore distribution characteristics in each of the square windows comprises:

[0015] For any square window, use threshold segmentation to obtain the pore area in the square window, divide the square window into two halves to obtain an initial table, use each cell in the initial table as an initial partition, count the number of pore areas in each of the initial partitions to obtain a pore number set, calculate the interquartile range of the pore number set, and if the interquartile range is greater than a preset range, select any two adjacent pore areas on the square window, obtain the area center points of the two adjacent pore areas respectively, calculate the distance between the area center points of the two adjacent pore areas, take the distance as a unit, reduce the side length of the initial partition by one unit to obtain the side length of the new partition, and divide the square window into N new partitions according to the side length of the new partition;

[0016] The table composed of the N new partitions is used as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, thereby obtaining the final partition side length;

[0017] Taking the side length of the final partition as the denominator and the side length of the square window as the numerator, a corresponding side length ratio is obtained; if the side length ratio is a positive integer, the square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table;

[0018] If the side length ratio is not a positive integer, the side length ratio is rounded up to obtain a target ratio, the side length of the square window is extended according to the target ratio to obtain a target square window, and the target square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table;

[0019] An adaptive square table of each square window is obtained, and an optimal table for dividing all square windows is obtained according to the adaptive square table of each square window.

[0020] Preferably, the step of obtaining an optimal table for dividing all square windows according to the adaptive square table of each square window comprises:

[0021] Counting the total number of pore areas contained in each of the adaptive square tables, taking the adaptive square table corresponding to the smallest total number of pore areas as the smallest table, and taking the adaptive square table corresponding to the largest total number of pore areas as the largest table;

[0022] For any square partition in the minimum table, calculate the distances from the center point of each pore area in the square partition to the four sides of the square partition to obtain the minimum distance, and obtain the maximum value among the minimum distances corresponding to all square partitions in the minimum table;

[0023] For any square partition in the maximum table, calculate the distances from the area center point of each pore area in the square partition to the four sides of the square partition to obtain the maximum distance, and obtain the minimum value among the maximum distances corresponding to all square partitions in the maximum table;

[0024] The maximum value and the minimum value form a partition side length interval, and if the side length of the square partition in the maximum table is within the partition side length interval, the maximum table is used as the optimal table;

[0025] If the side length of the square partition in the maximum table is not within the partition side length range, the maximum value is used as the maximum side length, and the square window corresponding to the maximum table is partitioned into squares according to the maximum side length to obtain a target table. The target table is used as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, so as to obtain the optimal partition side length, and the square window corresponding to the maximum table is partitioned according to the optimal partition side length to obtain the optimal table.

[0026] Preferably, dividing the pixel points in the partition into a normal point set and an abnormal point set includes:

[0027] According to the grayscale value of each pixel in the partition and a preset number of grayscale value intervals, respectively obtaining the grayscale value frequency corresponding to each grayscale value interval;

[0028] For any pixel point in the partition, obtain neighboring pixel points of the pixel point within a preset neighborhood range, calculate the absolute value of the difference between the grayscale value of the pixel point and the grayscale value of each of the neighboring pixel points, and normalize each of the absolute values ​​of the difference to obtain a corresponding normalized value;

[0029] The grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs is used as a weight, all normalized values ​​are weighted and then averaged to obtain a weighted difference mean of the pixel points;

[0030] Calculate the average value of the grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs as the frequency mean, take the absolute value of the difference between the grayscale value frequency of the grayscale value interval to which the grayscale value of the pixel belongs and the frequency mean as the first variable, and take the product of the weighted difference mean of the pixel and the first variable as the abnormality degree of the pixel;

[0031] Obtaining the abnormality degree of each pixel point in the partition, normalizing each abnormality degree to obtain a corresponding normalized abnormality degree value, and if the normalized abnormality degree value of any pixel point in the partition is greater than a preset abnormality value, marking the pixel point as an abnormal point to obtain an abnormal point set;

[0032] If the normalized value of the abnormality degree of any pixel point in the partition is less than or equal to the preset abnormality value, the pixel point is marked as a normal point to obtain a normal point set.

[0033] Preferably, the step of optimizing the grayscale value of each pixel in the abnormal point set to obtain the corresponding optimized grayscale value includes:

[0034] For any outlier in the outlier set, a region to be analyzed of a preset size is constructed in the partition with the outlier as the center, a ratio of the number of outliers in the region to be analyzed to the number of all pixels in the region to be analyzed is calculated as an outlier number ratio, and an average of the outlier number ratios of all outliers in the outlier set is calculated as a density;

[0035] If the density is less than a preset density threshold, any pixel in the abnormal point set is taken as a target point, and the grayscale values ​​of all pixels except the target point in the area to be analyzed where the target point is located are arranged in ascending order to obtain a grayscale value sequence, and the quartile of the grayscale value sequence is obtained as the optimized grayscale value of the target point;

[0036] If the density is greater than or equal to the preset density threshold, the grayscale value of each pixel in the abnormal point set is directly used as the optimized grayscale value.

[0037] Preferably, obtaining the grayscale distribution uniformity index of the partition according to the grayscale value optimization set includes:

[0038] Obtaining a contrast ratio according to a maximum grayscale value and a minimum grayscale value in the grayscale value optimization set, obtaining an interquartile range of grayscale values ​​according to all grayscale values ​​in the grayscale value optimization set, and taking a product of the contrast ratio and the interquartile range of grayscale values ​​as a grayscale average value of the partition;

[0039] Calculate the average value of all gray values ​​in the gray value optimization set;

[0040] The product of the grayscale uniformity value and the average value is calculated as a grayscale distribution uniformity index.

[0041] Preferably, obtaining the overall color uniformity index of the square window according to the grayscale distribution uniformity index of each partition in the square window includes:

[0042] For any row in the square window, a color uniformity curve of the corresponding row is constructed according to the grayscale distribution uniformity indexes of all the partitions of the corresponding row, wherein the abscissa of the color uniformity curve represents the position of the partition, and the ordinate represents the grayscale distribution uniformity index of each partition of the corresponding row;

[0043] Respectively obtain the angle between each two adjacent coordinate points on the color uniformity curve to obtain the angle mean of all angles, take the difference between the preset angle value and the angle mean as the angle difference, and take the ratio of the angle difference to the preset angle value as the curve smoothness;

[0044] The curve smoothness of all rows in the square window is obtained, and the overall color uniformity index of the square window is obtained according to the curve smoothness of all rows.

[0045] Preferably, obtaining the overall color uniformity index of the square window according to the curve smoothness of all the rows includes:

[0046] The curve smoothness of all rows is added to obtain a total curve smoothness value. For the curve smoothness of any row, the ratio of the curve smoothness to the total curve smoothness value is calculated as the weight of the curve smoothness. The weighted sum of the curve smoothness of all rows is performed to obtain the overall color uniformity index of the square window.

[0047] Preferably, the quality assessment of the apples in the same batch according to the overall color uniformity index of each square window includes:

[0048] For any overall color uniformity index, if the overall color uniformity index is within a preset index range, the quality of the apple corresponding to the overall color uniformity index is the quality grade corresponding to the preset index range.

[0049] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0050] The present invention obtains the surface image of each apple of the same batch, performs grayscale processing on each surface image, and obtains a corresponding grayscale image; constructs a square window containing apples in each grayscale image, obtains an optimal table for dividing all square windows according to the lenticel distribution characteristics in each square window, and divides each square window into a plurality of partitions according to the optimal table; for any partition in any square window, divides the pixel points in the partition into a normal point set and an abnormal point set, optimizes the grayscale value of each pixel point in the abnormal point set, and obtains an optimized grayscale value; sorts all the optimized grayscale values ​​and the grayscale value of each pixel point in the normal point set according to size, and obtains a corresponding grayscale value optimization set; obtains a grayscale distribution uniformity index of the partition according to the grayscale value optimization set, and obtains an overall color uniformity index of the square window according to the grayscale distribution uniformity index of each partition in the square window; obtains the overall color uniformity index of each square window, and performs quality evaluation on the apples of the same batch according to the overall color uniformity index of each square window. Among them, multiple apples from the same batch are selected, the lenticel area on the surface of each apple is counted, and the apples are partitioned according to the table method so that each lenticel can fall evenly in each table. Since the tables divided by different apples are different in size, the table corresponding to the apples with sparse lenticel area distribution and the table corresponding to the apples with dense distribution are found. The lenticel area distribution of the two tables is combined to perform table adaptation to obtain the best table. The best table is used as the standard for partitioning the same batch of apples. The color uniformity index is obtained according to the grayscale uniformity value of each cell in the table. The larger the color uniformity index, the more uniform the apple color is, and the better the quality of the corresponding apple is. Therefore, the quality grade of the apple can be determined according to the color uniformity index, thereby improving the accuracy of apple quality grading according to the surface image of the apple. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0052] Figure 1 is a method flow chart of an apple quality analysis and evaluation method based on image recognition provided in Embodiment 1 of the present invention;

[0053] Figure 2 It is a grayscale image obtained by graying the surface image of an apple provided in the first embodiment of the present invention. DETAILED DESCRIPTION

[0054] Embodiments of the present disclosure are described in detail below, and examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, but should not be understood as limiting the present disclosure.

[0055] It should be noted that the terms "first", "second", etc. in the specification of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure.

[0056] In order to illustrate the technical solution of the present invention, specific embodiments are provided below for illustration.

[0057] See also Figure 1 , is a method flow chart of an apple quality analysis and evaluation method based on image recognition provided by Embodiment 1 of the present invention, such as Figure 1 As shown, the method may include:

[0058] Step S101, for apples of the same batch, respectively obtain a surface image of each apple, perform grayscale processing on each surface image, and obtain a corresponding grayscale image;

[0059] Since the light source and shooting angle have some influence on the image of apple, the image of the surface of each apple is collected under the condition that the light source and shooting angle are the same to eliminate the influence of the environment on the surface image of each apple.

[0060] First, limit the light source position to be just above the apple stem , the shooting angle is with the fruit stalk upward and the top of the fruit stalk facing left , the bottom of the fruit stalk is at the exact center, and the surface images of the apples of the same batch are collected according to the specified conditions. Then, each collected surface image is grayed to obtain the corresponding grayscale image.

[0061] Step S102, constructing a square window containing an apple in each of the grayscale images, obtaining an optimal table for dividing all the square windows according to the pore distribution characteristics in each of the square windows, and dividing each of the square windows into a plurality of partitions according to the optimal table.

[0062] According to the lenticel characteristics of apples: the better the quality of apples, the more moderate and evenly distributed the lenticels are. Select multiple apples from the same batch, perform statistical calculations on the surface lenticels, and partition them according to the table method so that the probability of each lenticel falling evenly in each table is the same. Since the tables divided by different apples vary in size, find the table corresponding to apples with sparse lenticel area distribution and the table corresponding to apples with dense distribution. Combine the lenticel area distribution of the two tables for table adaptation to obtain a table of moderate size. This table is used as the best table for dividing the same batch of apples. The method for obtaining the best table is:

[0063] (1) Construct a square window containing an apple in each of the grayscale images.

[0064] Specifically, for any grayscale image, edge detection is performed on the grayscale image to obtain the edge of the apple in the grayscale image, the vertical distance between every two edge points on the apple edge is calculated respectively, the maximum vertical distance is obtained as the initial window side length, and a square window containing the apple in the grayscale image is constructed with the length of the initial window side length.

[0065] Among them, edge detection is an existing technology and will not be described in detail here.

[0066] It should be noted that the purpose of edge detection is to construct a minimum circumscribed square area that just contains the entire apple based on the edge of the apple in the grayscale image, that is, a square window. Similarly, obtain the square windows corresponding to all grayscale images.

[0067] (2) According to the pore distribution characteristics in each of the square windows, an optimal table for dividing all the square windows is obtained.

[0068] Specifically, for any square window, threshold segmentation is used to obtain the pore area in the square window, the square window is divided into two halves to obtain an initial table, each cell in the initial table is used as an initial partition, the number of pore areas in each of the initial partitions is counted to obtain a pore number set, and the interquartile range of the pore number set is calculated. If the interquartile range is greater than a preset range, two adjacent pore areas are randomly selected on the square window, and the regional center points of the two adjacent pore areas are respectively obtained, and the distance between the regional center points of the two adjacent pore areas is calculated. The distance is taken as a unit, and the side length of the initial partition is reduced by one unit to obtain the side length of the new partition, and the square window is divided into N new partitions according to the side length of the new partition;

[0069] The table composed of the N new partitions is used as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, thereby obtaining the final partition side length;

[0070] Taking the side length of the final partition as the denominator and the side length of the square window as the numerator, a corresponding side length ratio is obtained; if the side length ratio is a positive integer, the square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table;

[0071] If the side length ratio is not a positive integer, the side length ratio is rounded up to obtain a target ratio, the side length of the square window is extended according to the target ratio to obtain a target square window, and the target square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table;

[0072] An adaptive square table of each square window is obtained, and an optimal table for dividing all square windows is obtained according to the adaptive square table of each square window.

[0073] In one embodiment, reference Figure 2 , which is a grayscale image obtained by graying the surface image of an apple. Figure 2 In the figure, the white dotted area in the apple area is the lenticel area. Since the grayscale value of the lenticel area is significantly different from that of most of the surrounding areas, the threshold segmentation technology can be used to obtain the lenticel area.

[0074] For any square window, a threshold segmentation technique is used to obtain the pore area in the square window, wherein the threshold segmentation technique is an existing technique and will not be described in detail herein.

[0075] Divide the square window into 4 equal parts, and we get An initial table is obtained, each cell in the initial table is recorded as an initial partition, the number of pore areas in each initial partition is counted, the number of pore areas in each initial partition is arranged in ascending order to obtain a pore number set, the interquartile range of the pore number set is calculated, and the preset interval is set to 1. There is no restriction here, and the implementer can set it according to the implementation scenario. If the interquartile range of the pore number set is less than or equal to 1, the side length of the initial partition is appropriate, and the side length of the initial partition is directly used as the side length of the final partition.

[0076] If the interquartile range of the pore number set is greater than 1, then any two adjacent pore areas are randomly selected in the square window, and the regional center point of the pore area is obtained according to the coordinates of the pixel points in each pore area. The distance between the regional center points of the two adjacent pore areas is calculated, and the distance is used as a unit. The side length of the initial partition is reduced by one unit to obtain the side length of the new partition. The square window is divided into N new partitions according to the side length of the new partition. The table composed of the N new partitions is used as the initial table, and the steps of obtaining the interquartile range are repeated until the interquartile range is less than or equal to 1. At this time, each pore area in the square window can be evenly fallen in each initial partition in the initial table, and then the side length of the initial partition at this time is used as the final partition side length.

[0077] For example, there are 9 initial partitions in the initial table, and the set of pore numbers is {7, 7, 8, 9, 9, 10, 10, 10, 11}. The interquartile range is calculated: Q1 is 2.5, Q1=7.5; Q2 is 5, Q2=9; Q3 is 7.5, Q3=10, and the interquartile range is Q3-Q1=2.5. At this time, the interquartile range is greater than 1, so the initial partition is adjusted. Assuming that the distance between the center points of two adjacent pore areas is 1, the side length of the initial partition is reduced by 1 to obtain the side length of the new partition. The square window is divided into 36 new partitions according to the side length of the new partition. The table composed of these 36 new partitions is used as the initial table. At this time, the set of pore numbers in the initial table is:

[0078] {1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3}, recalculate the interquartile range: Q1 is 9.25, Q1=2; Q2 is 18.5, Q2=2; Q3 is 27.75, Q3=3, and the interquartile range is Q3-Q1=1. At this time, if the interquartile range is less than or equal to 1, the side length of the initial partition in the current initial table is used as the side length of the final partition, that is, the side length of the new partition is used as the side length of the final partition.

[0079] After obtaining the final partition side length, the square window can be evenly divided into multiple square partitions using the final partition side length. However, considering that it cannot be guaranteed that the final partition side length can divide the square window into multiple square partitions, the final partition side length is used as the denominator and the side length of the square window is used as the numerator to calculate the ratio of the final partition side length to the side length of the square window. If the ratio is a positive integer, it means that the final partition side length can evenly divide the square window into multiple square partitions. All the partitions divided by the final partition side length are used as the adaptive square table of the square window. If the ratio is not a positive integer, it means that the square window cannot be partitioned into squares according to the final partition side length, and the side length of the square window needs to be extended to ensure that the ratio is a positive integer. Specifically, the ratio is rounded up to obtain a target ratio, and the product of the target ratio and the final partition side length is used as the target side length after the side length of the square window is extended. Then, the side length of the square window is extended to the target side length to obtain the target square window. At this time, the target square window is partitioned into squares according to the final partition side length to obtain the corresponding adaptive square table.

[0080] For example, the side length of the square window is 9, and the side length of the final partition is 4. The side length of the final partition is used as the denominator and the side length of the square window is used as the numerator. The ratio of the side length of the final partition to the side length of the square window is 2.25. 2.25 is rounded up to get a target ratio of 3. The product of the target ratio 3 and the side length of the final partition 4 is 12. The side length of the square window is extended to 12 to obtain a target square window. At this time, the target square window can be divided into 9 square partitions by the side length of the final partition.

[0081] According to the above-mentioned method for obtaining the adaptive square table, the adaptive square table of all square windows is obtained. Then, according to the adaptive square table of each square window, the optimal table for dividing all square windows is obtained, which is used as the partitioning standard for the surfaces of the same batch of apples, so that each pore area of ​​each apple has the same probability of evenly falling into each partition in its optimal table.

[0082] Preferably, obtaining an optimal table for dividing all square windows according to the adaptive square table of each square window includes:

[0083] Counting the total number of pore areas contained in each of the adaptive square tables, taking the adaptive square table corresponding to the smallest total number of pore areas as the smallest table, and taking the adaptive square table corresponding to the largest total number of pore areas as the largest table;

[0084] For any square partition in the minimum table, calculate the distances from the center point of each pore area in the square partition to the four sides of the square partition to obtain the minimum distance, and obtain the maximum value among the minimum distances corresponding to all square partitions in the minimum table;

[0085] For any square partition in the maximum table, calculate the distances from the area center point of each pore area in the square partition to the four sides of the square partition to obtain the maximum distance, and obtain the minimum value among the maximum distances corresponding to all square partitions in the maximum table;

[0086] The maximum value and the minimum value form a partition side length interval, and if the side length of the square partition in the maximum table is within the partition side length interval, the maximum table is used as the optimal table;

[0087] If the side length of the square partition in the maximum table is not within the partition side length range, the maximum value is used as the maximum side length, and the square window corresponding to the maximum table is partitioned into squares according to the maximum side length to obtain a target table. The target table is used as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, so as to obtain the optimal partition side length, and the square window corresponding to the maximum table is partitioned according to the optimal partition side length to obtain the optimal table.

[0088] In one embodiment, the total number of pore areas included in each adaptive square table is counted, and the adaptive square table corresponding to the minimum total number of pore areas is used as the minimum table. For any square partition in the minimum table, the distances from the area center point of each pore area in the square partition to the four sides of the square partition are calculated to obtain the minimum distance, and the maximum value is obtained from the minimum distances corresponding to all square partitions in the minimum table. Similarly, the adaptive square table corresponding to the maximum total number of pore areas is used as the maximum table, and the minimum value is obtained from the maximum distances corresponding to all square partitions in the maximum table.

[0089] Assume that the partition side length interval is [2, 4]. If the side length of the square partition in the largest table is 4, it can be seen that 4 is just in the partition side length interval. In this case, the largest table is used as the partition standard for the apple surface, that is, the largest table is used as the best table. If the side length of the square partition in the largest table is 5, it can be seen that 5 is not in the partition side length interval. The square window corresponding to the largest table is partitioned into squares with a side length of 4 to obtain the target table. According to the steps for obtaining the interquartile range corresponding to the initial table, the interquartile range corresponding to the target table is obtained. If the interquartile range corresponding to the target table is less than or equal to 1, it means that the side length of 4 is appropriate. Then the side length of 4 is used as the best partition side length, and the square window corresponding to the best table is partitioned using the best partition side length to obtain the best table. On the contrary, if the interquartile range corresponding to the target table is greater than 1, according to the method for obtaining the final partition side length, the final partition side length corresponding to the target table is obtained as the partition side length of the best table, and then the square window corresponding to the largest table is partitioned using the best partition side length to obtain the best table.

[0090] Step S103, for any partition in any square window, divide the pixel points in the partition into a normal point set and an abnormal point set, optimize the grayscale value of each pixel point in the abnormal point set, and obtain the corresponding optimized grayscale value, sort all the optimized grayscale values ​​and the grayscale value of each pixel point in the normal point set according to size, and obtain the corresponding grayscale value optimization set, obtain the grayscale distribution uniformity index of the partition according to the grayscale value optimization set, and obtain the overall color uniformity index of the square window according to the grayscale distribution uniformity index of each partition in the square window.

[0091] After obtaining the partitions of each square window, since there may be abnormal points caused by pore areas or noise interference in the partitions of each square window, it is necessary to analyze the existence of abnormal points. Therefore, in an embodiment of the present invention, for any square window, the square window is used as the square window to be analyzed. For any partition in the square window to be analyzed, the pixels in the partition are first divided into a normal point set and an abnormal point set. Then, the gray value of each pixel in the abnormal point set is optimized, and the optimized gray value is obtained accordingly, so as to eliminate the interference of abnormal points as much as possible.

[0092] The pixels in the partition are divided into a normal point set and an abnormal point set, and the division method is:

[0093] According to the grayscale value of each pixel point in the partition and a preset number of grayscale value intervals, respectively obtaining the grayscale value frequency corresponding to each grayscale value interval;

[0094] For any pixel point in the partition, obtain neighboring pixel points of the pixel point within a preset neighborhood range, calculate the absolute value of the difference between the grayscale value of the pixel point and the grayscale value of each of the neighboring pixel points, and normalize each of the absolute values ​​of the difference to obtain a corresponding normalized value;

[0095] The grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs is used as a weight, all normalized values ​​are weighted and then averaged to obtain a weighted difference mean of the pixel points;

[0096] Calculate the average value of the grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs as the frequency mean, take the absolute value of the difference between the grayscale value frequency of the grayscale value interval to which the grayscale value of the pixel belongs and the frequency mean as the first variable, and take the product of the weighted difference mean of the pixel and the first variable as the abnormality degree of the pixel;

[0097] Obtaining the abnormality degree of each pixel point in the partition, normalizing each abnormality degree to obtain a corresponding normalized abnormality degree value, and if the normalized abnormality degree value of any pixel point in the partition is greater than a preset abnormality value, marking the pixel point as an abnormal point to obtain an abnormal point set;

[0098] If the normalized value of the abnormality degree of any pixel point in the partition is less than or equal to the preset abnormality value, the pixel point is marked as a normal point to obtain a normal point set.

[0099] In one embodiment, for any partition in the square window to be analyzed, the grayscale value of each pixel in the partition is obtained, and a histogram statistics of the grayscale value of each pixel in the partition is performed, wherein the horizontal axis is the grayscale value and the vertical axis is the grayscale value frequency. The grayscale values ​​are grouped according to intervals, and the interval size is set to 2. There is no restriction here, and the implementer can set it according to the implementation scenario to obtain the grayscale value frequency of each group.

[0100] For any pixel point of the partition, the preset neighborhood range is set to 8. There is no restriction here. The implementer can calculate the absolute value of the difference between the gray value of the pixel point and the gray value of the 8 neighboring pixels within its 8 neighborhood range according to the implementation scenario setting, add the 8 absolute values ​​of the difference to obtain the sum of the differences, calculate the proportion of each absolute value of the difference to the sum of the differences, and obtain the normalized value of the absolute value of the difference between the corresponding neighboring pixel point and the pixel point, that is, normalize the 8 absolute values ​​of the difference, take the gray value frequency of the group to which the gray value of each neighboring pixel point belongs as the weight, weight the 8 normalized values ​​to obtain the weighted difference, calculate the average of the 8 weighted differences as the weighted difference mean, and the formula of the weighted difference mean is:

[0101]

[0102] Among them, T represents the weighted difference mean of the pixel point, i represents the eight neighboring pixels, which are recorded as 1, 2, 3, 4, 5, 6, 7, and 8 from left to right and from top to bottom. Indicates the gray value frequency of the group to which the gray value of the i-th neighborhood pixel belongs, Represents the normalized value corresponding to the absolute value of the difference between the i-th neighborhood pixel and this pixel.

[0103] After obtaining the weighted difference mean of the pixel, the average of the grayscale frequency of the group to which the grayscale values ​​of the eight neighboring pixels belong is calculated as the frequency mean, the absolute value of the difference between the grayscale frequency of the group to which the grayscale value of the pixel belongs and the frequency mean is taken as the first variable, and the product of the weighted difference mean of the pixel and the first variable is taken as the abnormality degree of the pixel. The formula for the abnormality degree is:

[0104]

[0105] Among them, K represents the abnormality of the pixel, T represents the weighted difference mean of the pixel, Indicates the gray value frequency of the group to which the gray value of the pixel belongs. represents the frequency mean, Represents the absolute value symbol.

[0106] Similarly, the degree of abnormality of each pixel in the partition is obtained, and the degree of abnormality of each pixel is subjected to Min-Max normalization processing to obtain the corresponding normalized value of the degree of abnormality, so that the normalized value of the degree of abnormality of each pixel is within [0, 1]. Among them, Min-Max normalization is an existing technology and will not be repeated here.

[0107] It should be noted that the smaller the normalized value of the abnormality level is, the closer the grayscale value of the corresponding pixel is to the surrounding neighborhood pixels, and the greater the probability that the pixel is a normal point. The larger the normalized value of the abnormality level is, the more obvious the difference in grayscale value between the corresponding pixel and the surrounding neighborhood pixels is, and the greater the probability that the pixel is an abnormal point.

[0108] The preset abnormal value is set to 0.6. There is no restriction here. The implementer can set it according to the implementation scenario. If the normalized value of the abnormal degree is greater than 0.6, the corresponding pixel point is marked as an abnormal point to obtain an abnormal point set. If the normalized value of the abnormal degree is less than or equal to 0.6, the corresponding pixel point is marked as a normal point to obtain a normal point set.

[0109] Among them, the gray value of each pixel in the abnormal point set is optimized, and the corresponding optimized gray value is obtained. The optimization method is:

[0110] For any outlier in the outlier set, a region to be analyzed of a preset size is constructed in the partition with the outlier as the center, a ratio of the number of outliers in the region to be analyzed to the number of all pixels in the region to be analyzed is calculated as an outlier number ratio, and an average of the outlier number ratios of all outliers in the outlier set is calculated as a density;

[0111] If the density is less than a preset density threshold, any pixel in the abnormal point set is taken as a target point, and the grayscale values ​​of all pixels except the target point in the area to be analyzed where the target point is located are arranged in ascending order to obtain a grayscale value sequence, and the quartile of the grayscale value sequence is obtained as the optimized grayscale value of the target point;

[0112] If the density is greater than or equal to the preset density threshold, the grayscale value of each pixel in the abnormal point set is directly used as the optimized grayscale value.

[0113] In one embodiment, for any outlier in the outlier set, a preset size of the area to be analyzed is set as Grid, there is no restriction here, implementers can set it according to the implementation scenario, and build it with the abnormal point as the center in this partition Grid, calculate the ratio of the number of outliers in the grid to the number of all pixels in the grid as the outlier number ratio, and calculate the average of the outlier number ratios of all outliers in the outlier set as the density;

[0114] The preset density threshold is set to 0.2. There is no restriction here. The implementer can set it according to the implementation scenario. If the density is less than 0.2, the abnormal point set is a non-quality abnormality. The non-quality abnormality is caused by the apple's own factors such as the pores. Such abnormal points are generally evenly and discretely distributed on the surface of the apple, and numerical optimization is required to minimize the impact on the calculation of the grayscale uniform distribution index. Therefore, it is necessary to perform numerical optimization on each abnormal point in the abnormal point set, take any pixel point in the abnormal point set as the target point, sort the grayscale values ​​of all pixels except the target point in the grid where the target point is located from small to large, calculate the Q2 value in the quartile of the sorted grayscale value, and use the Q2 value as the optimized grayscale value of the target point. Similarly, the optimized grayscale value of each pixel in the abnormal point set is obtained.

[0115] If the density is greater than or equal to 0.2, the abnormal point set is a quality anomaly. Quality anomalies are abnormal points caused by defects. Such abnormal points are generally distributed more concentratedly, and most of them are concentrated in a local area. Since quality anomalies need to be detected, quality anomalies do not need to be numerically optimized, and the grayscale value of each pixel in the abnormal point set is directly used as the optimized grayscale value.

[0116] All optimized gray values ​​and the gray value of each pixel in the normal point set are sorted in ascending order to obtain the optimized gray value set of the partition. Similarly, the optimized gray value set of each partition in the square window to be analyzed is obtained.

[0117] Furthermore, after optimizing the grayscale of the partitions, considering that good quality apples have uniform color and similar grayscale values, the interquartile range of the grayscale values ​​of each partition is used to represent the difference in grayscale values. At the same time, images with uniform color have the characteristic of low contrast. The grayscale contrast in each partition is calculated, and the grayscale distribution uniformity index of each partition is calculated based on the interquartile range of the grayscale values ​​and the grayscale contrast. Then, the overall color uniformity index of each square window is obtained based on the grayscale distribution uniformity index of each partition.

[0118] Among them, the grayscale distribution uniformity index of each partition is calculated by the interquartile range of the grayscale value and the grayscale contrast, including:

[0119] Obtaining a contrast ratio according to a maximum grayscale value and a minimum grayscale value in the grayscale value optimization set, obtaining an interquartile range of grayscale values ​​according to all grayscale values ​​in the grayscale value optimization set, and taking a product of the contrast ratio and the interquartile range of grayscale values ​​as a grayscale average value of the partition;

[0120] Calculate the average value of all gray values ​​in the gray value optimization set;

[0121] The product of the grayscale uniformity value and the average value is calculated as a grayscale distribution uniformity index.

[0122] In one embodiment, for any partition in the square window to be analyzed, the contrast is obtained based on the maximum grayscale value and the minimum grayscale value in the grayscale value optimization set of the partition, the interquartile range of the grayscale value is obtained based on all grayscale values ​​in the grayscale value optimization set of the partition, and the product of the contrast and the interquartile range of the grayscale value is used as the grayscale average value of the partition.

[0123] Among them, the contrast is calculated by the Michelson contrast formula, and the contrast formula is:

[0124]

[0125] in, Indicates contrast, Represents the maximum gray value in the gray value optimization set, Indicates the minimum gray value in the gray value optimization set.

[0126] It should be noted that if the interquartile range of the gray value is less than , so the larger the interquartile range of the gray value, The larger it is, the greater the contrast is, that is, the difference in grayscale values ​​is more obvious and the distribution of grayscale values ​​is more uneven.

[0127] The product of the contrast and the interquartile range of the gray value is taken as the gray average value of the partition, and the calculation formula of the gray average value is:

[0128]

[0129] Among them, E represents the grayscale mean value, S represents the interquartile range of the grayscale value, Indicates contrast.

[0130] It should be noted that the smaller E is, the more uniform the grayscale value distribution of the partition is, and the smaller S is, the more similar the grayscale values ​​of the pixels in the partition are. The smaller it is, the smaller the difference in the grayscale values ​​of the pixels in the partition is, and the more uniform the brightness is. The value range of E is [0,1).

[0131] For example, the grayscale value optimization set of this partition is {10,10,10,11,11,12}, Q1 position is 1.75, Q1=10; Q2 position is 3.5, Q2=10.5; Q3 position is 5.23; Q3=11.23, then the interquartile range of the grayscale value of this grayscale value optimization set is S=Q3-Q1=11.23-10=1.23, the contrast is about 0.09, then the grayscale average value of this partition is , the average value of all gray values ​​in the gray value optimization set is 10.67.

[0132] The average value of all grayscale values ​​in the grayscale value optimization set of the partition is obtained, and the product of the grayscale average value of the partition and the average value is used as the grayscale distribution uniformity index of the partition. Similarly, the grayscale distribution uniformity index of each partition in the square window to be analyzed is obtained, and then the overall color uniformity index of the square window to be analyzed is obtained.

[0133] The acquisition of the overall color uniformity index of the square window to be analyzed includes:

[0134] For any row in the square window, a color uniformity curve of the corresponding row is constructed according to the grayscale distribution uniformity indexes of all the partitions of the corresponding row, wherein the abscissa of the color uniformity curve represents the position of the partition, and the ordinate represents the grayscale distribution uniformity index of each partition of the corresponding row;

[0135] Respectively obtain the angle between each two adjacent coordinate points on the color uniformity curve to obtain the angle mean of all angles, take the difference between the preset angle value and the angle mean as the angle difference, and take the ratio of the angle difference to the preset angle value as the curve smoothness;

[0136] The curve smoothness of all rows in the square window is obtained, and the overall color uniformity index of the square window is obtained according to the curve smoothness of all rows.

[0137] In one embodiment, any row in the square window to be analyzed is selected, and there is no limitation here. The implementer can select rows or columns according to the implementation scenario, and construct a color uniformity curve for the row according to the grayscale distribution uniformity index of all partitions in the row, wherein the horizontal axis represents the column number of the partition, and the vertical axis represents the grayscale distribution uniformity index of all partitions in the row.

[0138] Calculate the angle between each two adjacent coordinate points on the color uniformity curve of the row. For example, if point A and point B are two adjacent coordinate points, the calculation formula for the angle between point A and point B is:

[0139]

[0140] in, The angle between point A and point B, represents the inverse sine function, represents the ordinate of point A, represents the ordinate of point B, represents the horizontal coordinate of point A, represents the horizontal coordinate of point B, Represents the absolute value symbol.

[0141] Similarly, all angles on the color uniformity curve of the row are calculated to obtain the angle mean of all angles, the difference between the preset angle value and the angle mean is taken as the angle difference, and the ratio of the angle difference to the preset angle value is taken as the curve smoothness. The calculation formula for the curve smoothness is:

[0142]

[0143] in, Indicates the smoothness of the curve, 90 indicates the preset angle value, Represents the angle mean.

[0144] Assume that the grayscale distribution uniformity index on the color uniformity curve of this row is {1.18, 1.21, 1.19, 1.18, 1.20, 1.19, 1.18}, where the coordinates of point A are (1, 1.18) and the coordinates of point B are (2, 1.21), then the angle between point A and point B is 1.17. Similarly, all angles on the color uniformity curve of this row are calculated to obtain the angle set {1.17, 1.14, 0.57, 1.14, 0.57, 0.57}. The angle mean is obtained based on the angle set. =0.86, then the smoothness of the color uniformity curve of this row is .

[0145] Similarly, the curve smoothness of all rows in the square window to be analyzed is calculated, and the overall color uniformity index of the square window to be analyzed is obtained according to the curve smoothness of all rows.

[0146] Among them, the overall color uniformity index of the square window to be analyzed is obtained according to the curve smoothness of all rows, including:

[0147] The curve smoothness of all rows is added to obtain a total curve smoothness value. For the curve smoothness of any row, the ratio of the curve smoothness to the total curve smoothness value is calculated as the weight of the curve smoothness. The weighted sum of the curve smoothness of all rows is performed to obtain the overall color uniformity index of the square window.

[0148] The curve smoothness of all rows in the square window to be analyzed is added to obtain the total value of the curve smoothness. For the curve smoothness of any row, the ratio of the curve smoothness of the row to the total value of the curve smoothness is used as the weight of the curve smoothness of the row, where the ratio retains two decimal places. Similarly, the weights of the curve smoothness of all rows in the square window to be analyzed are obtained, and the weighted summation of the curve smoothness of all rows in the square window to be analyzed is performed, and the corresponding result is used as the overall color uniformity index of the square window to be analyzed.

[0149] Step S104, obtaining the overall color uniformity index of each of the square windows, and performing quality assessment on the apples of the same batch according to the overall color uniformity index of each of the square windows.

[0150] Since the better the quality of the apple, the more uniform the color, the larger the overall color uniformity index, therefore, the quality of each apple in the same batch is divided according to the overall color uniformity index of each square window.

[0151] Among them, the quality of each apple in the same batch is divided according to the overall color uniformity index of each square window, including:

[0152] For any overall color uniformity index, if the overall color uniformity index is within a preset index range, the quality of the apple corresponding to the overall color uniformity index is the quality grade corresponding to the preset index range.

[0153] In one implementation, the preset index ranges of the overall color uniformity index corresponding to different quality levels are set to [0.95, 1], [0.90, 0.95), [0.85, 0.90), [0.80, 0.85), [0, 0.80], respectively. There is no limitation here and the implementer can set it according to the implementation scenario.

[0154] If the overall color uniformity index of the square window is in [0.95, 1], the color of the corresponding apple is very uniform and the quality is recorded as special grade. The skin of this type of apple is smooth and flawless, the color is bright and uniform, there are no dents, and there are no wormholes.

[0155] If the overall color uniformity index of the square window is in [0.90, 0.95), the color of the corresponding apple is relatively uniform, and there may be defects in slight areas. The quality is recorded as level one. The skin of this type of apple has slight defects, the color is bright but not uniform, there are slight depressions, and there are no wormholes.

[0156] If the overall color uniformity index of the square window is in [0.85, 0.90), the color of the corresponding apple is not uniform enough, and a few partitions have defects. The quality is recorded as level 2. The skin of this type of apple has fewer defects, the color is slightly darker and uneven, there are slight depressions, and there are no wormholes.

[0157] If the overall color uniformity index of the square window is in [0.80, 0.85), the color uniformity of the corresponding apple is low, more partitions have defects, and the quality is recorded as level three. The peel of this type of apple has many defects, the color is dull and uneven, there are depressions, and there may be wormholes.

[0158] If the overall color uniformity index of the square window is in [0, 0.80), the quality of the corresponding apple is poor.

[0159] In summary, the embodiment of the present invention obtains the surface image of each apple of the same batch, performs grayscale processing on each surface image, and obtains a corresponding grayscale image; constructs a square window containing apples in each grayscale image, obtains the best table for dividing all square windows according to the pore distribution characteristics in each square window, and divides each square window into multiple partitions according to the best table; for any partition in any square window, divides the pixel points in the partition into a normal point set and an abnormal point set, optimizes the grayscale value of each pixel point in the abnormal point set, and obtains the optimized grayscale value accordingly, sorts all the optimized grayscale values ​​and the grayscale value of each pixel point in the normal point set according to size, and obtains the corresponding grayscale value optimization set; obtains the grayscale distribution uniformity index of the partition according to the grayscale value optimization set, and obtains the overall color uniformity index of the square window according to the grayscale distribution uniformity index of each partition in the square window; obtains the overall color uniformity index of each square window, and performs quality evaluation on the apples of the same batch according to the overall color uniformity index of each square window. Among them, multiple apples from the same batch are selected, the lenticel area on the surface of each apple is counted, and the apples are partitioned according to the table method so that each lenticel can fall evenly in each table. Since the tables divided by different apples are different in size, the table corresponding to the apples with sparse lenticel area distribution and the table corresponding to the apples with dense distribution are found. The lenticel area distribution of the two tables is combined to perform table adaptation to obtain the best table. The best table is used as the standard for partitioning the same batch of apples. The color uniformity index is obtained according to the grayscale uniformity value of each cell in the table. The larger the color uniformity index, the more uniform the apple color is, and the better the quality of the corresponding apple is. Therefore, the quality grade of the apple can be determined according to the color uniformity index, thereby improving the accuracy of apple quality grading according to the surface image of the apple.

[0160] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. An apple quality analysis and evaluation method based on image recognition, characterized in that: The apple quality analysis and evaluation method based on image recognition includes: For apples of the same batch, respectively obtain a surface image of each apple, perform grayscale processing on each surface image, and obtain a corresponding grayscale image; Constructing a square window containing an apple in each of the grayscale images, obtaining an optimal table for dividing all the square windows according to the lenticel distribution characteristics in each of the square windows, and dividing each of the square windows into a plurality of partitions according to the optimal table; For any partition in any square window, the pixels in the partition are divided into a normal point set and an abnormal point set, the grayscale value of each pixel in the abnormal point set is optimized to obtain the corresponding optimized grayscale value, all the optimized grayscale values ​​and the grayscale value of each pixel in the normal point set are sorted according to size to obtain the corresponding grayscale value optimization set, the grayscale distribution uniformity index of the partition is obtained according to the grayscale value optimization set, and the overall color uniformity index of the square window is obtained according to the grayscale distribution uniformity index of each partition in the square window; Obtaining an overall color uniformity index of each of the square windows, and performing quality assessment on the apples of the same batch according to the overall color uniformity index of each of the square windows; The step of obtaining an optimal table for dividing all square windows according to the pore distribution characteristics in each square window comprises: For any square window, use threshold segmentation to obtain the pore area in the square window, divide the square window into two halves to obtain an initial table, use each cell in the initial table as an initial partition, count the number of pore areas in each of the initial partitions to obtain a pore number set, calculate the interquartile range of the pore number set, and if the interquartile range is greater than a preset range, select any two adjacent pore areas on the square window, obtain the area center points of the two adjacent pore areas respectively, calculate the distance between the area center points of the two adjacent pore areas, take the distance as a unit, reduce the side length of the initial partition by one unit to obtain the side length of the new partition, and divide the square window into N new partitions according to the side length of the new partition; The table composed of the N new partitions is used as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, thereby obtaining the final partition side length; Taking the side length of the final partition as the denominator and the side length of the square window as the numerator, a corresponding side length ratio is obtained; if the side length ratio is a positive integer, the square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table; If the side length ratio is not a positive integer, the side length ratio is rounded up to obtain a target ratio, the side length of the square window is extended according to the target ratio to obtain a target square window, and the target square window is partitioned into squares according to the side length of the final partition to obtain a corresponding adaptive square table; Obtaining the adaptive square table of each of the square windows, counting the total number of pore areas contained in each of the adaptive square tables, taking the adaptive square table corresponding to the smallest total number of pore areas as the smallest table, and taking the adaptive square table corresponding to the largest total number of pore areas as the largest table; For any square partition in the minimum table, calculate the distances from the center point of each pore area in the square partition to the four sides of the square partition to obtain the minimum distance, and obtain the maximum value among the minimum distances corresponding to all square partitions in the minimum table; For any square partition in the maximum table, calculate the distances from the area center point of each pore area in the square partition to the four sides of the square partition to obtain the maximum distance, and obtain the minimum value among the maximum distances corresponding to all square partitions in the maximum table; The maximum value and the minimum value form a partition side length interval, and if the side length of the square partition in the maximum table is within the partition side length interval, the maximum table is used as the optimal table; If the side length of the square partition in the maximum table is not within the partition side length interval, the maximum value is taken as the maximum side length, and the square window corresponding to the maximum table is partitioned into squares according to the maximum side length to obtain a target table, and the target table is taken as the initial table, and the step of obtaining the interquartile range is repeated until the interquartile range is less than or equal to the preset range, and an optimal partition side length is obtained, and the square window corresponding to the maximum table is partitioned according to the optimal partition side length to obtain an optimal table; The step of optimizing the grayscale value of each pixel in the abnormal point set to obtain an optimized grayscale value includes: For any outlier in the outlier set, a region to be analyzed of a preset size is constructed in the partition with the outlier as the center, a ratio of the number of outliers in the region to be analyzed to the number of all pixels in the region to be analyzed is calculated as an outlier number ratio, and an average of the outlier number ratios of all outliers in the outlier set is calculated as a density; If the density is less than a preset density threshold, any pixel in the abnormal point set is taken as a target point, and the grayscale values ​​of all pixels except the target point in the area to be analyzed where the target point is located are arranged in ascending order to obtain a grayscale value sequence, and the quartile of the grayscale value sequence is obtained as the optimized grayscale value of the target point; If the density is greater than or equal to the preset density threshold, the grayscale value of each pixel in the abnormal point set is directly used as the optimized grayscale value; The step of obtaining the grayscale distribution uniformity index of the partition according to the grayscale value optimization set includes: Obtaining a contrast ratio according to a maximum grayscale value and a minimum grayscale value in the grayscale value optimization set, obtaining an interquartile range of grayscale values ​​according to all grayscale values ​​in the grayscale value optimization set, and taking a product of the contrast ratio and the interquartile range of grayscale values ​​as a grayscale average value of the partition; Calculate the average value of all gray values ​​in the gray value optimization set; Calculating the product of the grayscale uniformity value and the average value as a grayscale distribution uniformity index; The step of obtaining the overall color uniformity index of the square window according to the grayscale distribution uniformity index of each partition in the square window comprises: For any row in the square window, a color uniformity curve of the corresponding row is constructed according to the grayscale distribution uniformity indexes of all the partitions of the corresponding row, wherein the abscissa of the color uniformity curve represents the position of the partition, and the ordinate represents the grayscale distribution uniformity index of each partition of the corresponding row; Respectively obtain the angle between each two adjacent coordinate points on the color uniformity curve to obtain the angle mean of all angles, take the difference between the preset angle value and the angle mean as the angle difference, and take the ratio of the angle difference to the preset angle value as the curve smoothness; Obtaining the curve smoothness of all rows in the square window, adding the curve smoothness of all rows to obtain a total curve smoothness value, calculating, for the curve smoothness of any row, a ratio of the curve smoothness to the total curve smoothness value as a weight of the curve smoothness, and performing weighted summation on the curve smoothness of all rows to obtain an overall color uniformity index of the square window; The quality assessment of the apples in the same batch is performed according to the overall color uniformity index of each square window, including: For any overall color uniformity index, if the overall color uniformity index is within a preset index range, the quality of the apple corresponding to the overall color uniformity index is the quality grade corresponding to the preset index range.

2. The apple quality analysis and evaluation method based on image recognition according to claim 1, characterized in that: The step of constructing a square window containing an apple in each of the grayscale images comprises: For any grayscale image, edge detection is performed on the grayscale image to obtain the edge of the apple in the grayscale image, the vertical distance between every two edge points on the apple edge is calculated respectively, the maximum vertical distance is obtained as the initial window side length, and a square window containing the apple in the grayscale image is constructed with the length of the initial window side length.

3. The apple quality analysis and evaluation method based on image recognition according to claim 1, characterized in that: The dividing the pixel points in the partition into a normal point set and an abnormal point set includes: According to the grayscale value of each pixel in the partition and a preset number of grayscale value intervals, respectively obtaining the grayscale value frequency corresponding to each grayscale value interval; For any pixel point in the partition, obtain neighboring pixel points of the pixel point within a preset neighborhood range, calculate the absolute value of the difference between the grayscale value of the pixel point and the grayscale value of each of the neighboring pixel points, and normalize each of the absolute values ​​of the difference to obtain a corresponding normalized value; The grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs is used as a weight, all normalized values ​​are weighted and then averaged to obtain a weighted difference mean of the pixel points; Calculate the average value of the grayscale value frequency of the grayscale value interval to which the grayscale value of each of the neighborhood pixels belongs as the frequency mean, take the absolute value of the difference between the grayscale value frequency of the grayscale value interval to which the grayscale value of the pixel belongs and the frequency mean as the first variable, and take the product of the weighted difference mean of the pixel and the first variable as the abnormality degree of the pixel; Obtaining the abnormality degree of each pixel point in the partition, normalizing each abnormality degree to obtain a corresponding normalized abnormality degree value, and if the normalized abnormality degree value of any pixel point in the partition is greater than a preset abnormality value, marking the pixel point as an abnormal point to obtain an abnormal point set; If the normalized value of the abnormality degree of any pixel point in the partition is less than or equal to the preset abnormality value, the pixel point is marked as a normal point to obtain a normal point set.