An intelligent transplantation enhanced balancing method for cherry cracked fruit samples

Through offline enhancement technology, more equivalent data is generated to solve the problem of cherry cracking sample imbalance, improve the accuracy and generalization ability of the detection model, and significantly improve the detection effect of cherry cracking.

CN114897770BActive Publication Date: 2024-10-18DALIAN UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210326120.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-30
Publication Date
2024-10-18
Estimated Expiration
2042-03-30

AI Technical Summary

Technical Problem

Cherry cracked fruits are prone to decay during the maturity period, resulting in sample imbalance and affecting the accuracy of the detection model. Existing undersampling and oversampling methods have risks of information loss and overfitting.

Method used

Through offline enhancement, more equivalent data is generated based on limited image data samples. Binarization processing, morphological processing, circumscribed rectangle and automatic cropping technology are used to randomly change the size, translation and rotation, replace black pixels, and enrich training. Distribution of data.

Benefits of technology

Significantly improved the generalization ability of the detection model, the same data set increased mAP from 62.58% to 95.29%, the average accuracy of normal fruits increased from 76% to 93%, and the average accuracy of cracked fruits increased from 49% to 98% .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114897770B_ABST
    Figure CN114897770B_ABST
Patent Text Reader

Abstract

The present invention discloses an intelligent transplantation enhancement balance method for cherry cracked fruit samples, comprising: binarizing a target cracked fruit white background image f(x, y) to obtain a binarized image with foreground and background separated; the binarized image is morphologically processed using a closing and opening operation; the cracked fruit shape is obtained from the processed image through a circumscribed rectangle and automatic clipping technology; the cropped cracked fruit shape and mask are randomly resized, translated and rotated; black pixels are replaced to restore the desired image. This application reduces the huge workload of manual clipping and pasting when the data set is as many as several thousand images, and can supplement new minority sample image information without deleting the original majority sample images. It generates more equivalent data based on limited image data samples to enrich the distribution of training data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of agricultural image processing, and in particular to an intelligent transplantation enhancement balancing method for cherry cracked fruit samples. Background Art

[0002] Machine vision is an interdisciplinary subject involving pattern recognition, neurobiology, computer science, artificial intelligence, image processing, psychophysics, etc. It mainly simulates and reproduces certain intelligent behaviors of human vision through computers, and then processes and understands the information extracted from the images of objective things, and finally achieves the purpose of application in actual detection and control.

[0003] With the development of computer graphics and image processing and intelligent technology, machine vision has gradually penetrated into all aspects of agricultural life. By analyzing the application examples of machine vision technology in my country's agricultural production, it can be found that it is mainly concentrated in obtaining target image information, image processing and algorithm recognition, intelligent visual positioning and navigation, and machine vision system integration.

[0004] Cherry fruit cracking is serious when it rains during the ripening period. The nutritional value of cracked fruit is the same as that of uncracked fruit, but the cracks are easily infected by pathogens, causing the fruit to rot, making it difficult to transport and store, reducing the commodity rate and commodity value. Cherry fruit cracking has greatly affected the economic benefits of my country's cherry industry. Therefore, in order to extend the shelf life of cracked fruit and improve the economic value of the commodity, it is urgent to study the problem of cherry fruit cracking.

[0005] The occurrence of cracked fruit in greenhouses is easily affected by various factors such as temperature, humidity, and soil nutrients, resulting in a great deal of randomness. It is difficult for fixed equipment set up for long-term observation to capture a sufficient number of cracked fruit images. The normal fruit images in the data set are far more than the cracked fruit images, resulting in extremely unbalanced samples; sample imbalance will cause serious bias in the detection model and low accuracy. At present, the industry generally uses undersampling and oversampling methods to solve such problems, that is, removing some majority samples in the training set and copying minority samples, so that the two types of data are close in magnitude, and then training the model. However, the undersampling method abandons many counterexamples, resulting in the balanced training set being smaller than the initial training set. Moreover, randomly discarding counterexamples will lose important information that has been collected. Although the oversampling method introduces additional training data, it does not add any new information to the minority class samples, which is very easy to cause overfitting. Summary of the invention

[0006] In view of the above-mentioned defects in the prior art, the present invention adopts an offline enhancement method to generate more equivalent (valid) data based on limited image data samples, enrich the distribution of training data, and make the model obtained through the training set more generalizable.

[0007] To achieve the above objectives, the present application proposes an intelligent transplantation enhanced balancing method for cherry cracked fruit samples, comprising:

[0008] Binarize the target cracked fruit white background image f(x, y) to obtain a binary image with foreground and background separated;

[0009] The binary image is morphologically processed using a closing and opening operation;

[0010] The cracked fruit shape is obtained from the processed image through the bounding rectangle and automatic clipping technology;

[0011] Randomly change the size, translation and rotation of the cropped cracked fruit shapes and masks;

[0012] Replace the black pixels and restore the desired image.

[0013] Furthermore, the target cracked fruit white background image f(x, y) is binarized to obtain a binary image with foreground and background separated, specifically:

[0014] Read the JPG white background image with missing samples into BGR format, then convert the BGR format into HSV format, and then only extract the H layer of the image;

[0015] Perform Gaussian filtering on the H layer of the image to eliminate Gaussian noise;

[0016] Based on the HSV color space, the hue H layer value is used as the basis for binarization.

[0017] Furthermore, based on the HSV color space, the hue H layer value is used as the basis for binarization, specifically:

[0018] Assume that the size of the target cracked fruit white background image is MXN, the number of pixels in the image whose H layer value is less than the threshold T is recorded as N0, and the number of pixels in the image whose H layer value is greater than the threshold T is recorded as N1, then:

[0019] (1)ω0=N0 / (M×N)

[0020] (2)ω1=N1 / (M×N)

[0021] (3) N0+N1=M×N

[0022] (4)ω0+ω1=1

[0023] (5)μ=ω0*μ0+ω1*μ1

[0024] (6) g = ω0*(μ0-μ) 2 +ω1*(μ1-μ) 2

[0025] Substituting formula (5) into formula (6), we get the equivalent formula:

[0026] (7)g=ω0*ω1*(μ0-μ1) 2

[0027] Among them, ω0 is the proportion of background pixels in the H layer image, μ0 is the average value of ω0 in the H layer; ω1 is the proportion of foreground pixels in the H layer image, μ1 is the average value of ω1 in the H layer; μ is the average value of the H layer image, g is the inter-class variance, and when g is the maximum, the corresponding T is the optimal threshold of the H layer;

[0028] According to the optimal threshold, 0 is set as the new value assigned when it is below the threshold, and 255 is set as the new value assigned when it is above the threshold, so as to obtain a binary image with foreground and background separated.

[0029] Furthermore, the target cracked fruit white background image is f(x,y), and the natural environment collection image is g(x,y). The g(x,y) is used to process f(x,y). g(x,y) is called the structural element S. Let f(x,y) be X. The set obtained by corroding X with S is the set of all origin positions in X including S. z represents the origin position. It can be expressed as:

[0030]

[0031] The principle of expansion is the dual operation of erosion. After translating the structural element S by a, we get Sa. If Sa hits X, record this point a. The set of all a points that meet the above conditions is called the result of X being expanded by S, which can be expressed as:

[0032]

[0033] Furthermore, the binary image is morphologically processed using a closing and opening operation, specifically:

[0034] With the two-dimensional array as the core, the image is closed. In mathematical morphology, the closing operation is first dilation and then erosion, that is:

[0035]

[0036] Closing operations can fill in cracks within foreground objects while leaving their overall position and shape unchanged;

[0037] With the two-dimensional array as the core, the image is opened. In mathematical morphology, the opening operation first erodes and then expands, that is:

[0038]

[0039] The opening operation can remove isolated points, burrs and small bridges while keeping the overall position and shape unchanged.

[0040] Furthermore, the shape of the cracked fruit is obtained from the processed image through the bounding rectangle and automatic clipping technology, specifically:

[0041] First, the grayscale values ​​0 and 255 of the processed image are reversed, and the minimum enclosing rectangle algorithm principle is used to obtain the coordinates x, y of the upper left corner of the matrix and the width w, height h of the matrix. According to the four values ​​of x, y, w, and h, the matrix is ​​used to cut out the cracked fruit, and a mask with a length of w and a height of h is obtained in the original image.

[0042] Furthermore, using a floating point number u between 0.5 and 1 and coordinates x and y, the cropped cracked fruit shape and mask are randomly resized, translated, and rotated as follows:

[0043] The formula for the change is: 1 =ux;y 1 =uy;

[0044] The rotation formula is: 1 =uxcosθ-uycosθ;y 1 =ux sinθ+uy cosθ;

[0045] The translation formula is: 1 =x+u;y 1 =y+u;

[0046] Get the length rows and width cols of the cropped image, subtract h and w from them respectively to get new values ​​a and b, so as to limit the position of the cracked fruit image in the new background image.

[0047] Furthermore, the black pixels are replaced to restore the desired image, as follows:

[0048] Traverse and replace according to the cropped image length rows and width cols. When the grayscale value of the mask is 0, it means that this point is a black pixel. Replace the color of the point and change it to BGR channel.

[0049] Compared with the prior art, the above technical solution adopted by the present invention has the following advantages: when the data set is as many as several thousand images, the present application reduces the huge workload of manual cutting and pasting, can supplement the new minority sample image information without deleting the original majority sample images, and generates more equivalent (valid) data based on limited image data samples, enriching the distribution of training data. After using this method to solve the sample imbalance problem, the same data set makes the same detection model increase from mAP 62.58% to 95.29%, the average accuracy of normal fruit increases from 76% to 93%, and the average accuracy of cracked fruit increases from 49% to 98%. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] Figure 1 A new sample graph obtained after intelligent transplantation of the present invention;

[0051] Figure 2 This is a flow chart of the intelligent transplantation enhanced balancing method of the present invention;

[0052] Figure 3 It is a schematic diagram of the closing and opening operation of the present invention;

[0053] Figure 4 This is the network detection model effect before the improvement of the present invention;

[0054] Figure 5 This is the effect of the improved network detection model of the present invention;

[0055] Figure 6 The image of the target cracked fruit white background image f(x, y) after the H layer is taken out;

[0056] Figure 7 is the binary image of the target cracked fruit with white background f(x, y);

[0057] Figure 8 The image after the closing and opening operation of the target cracked fruit white background image f(x, y);

[0058] Fig. 9 is the cropped image of the target cracked fruit white background image f(x, y);

[0059] Fig.10 is a mask image with noise. DETAILED DESCRIPTION

[0060] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application, that is, the embodiments described are only part of the embodiments of the present application, not all of the embodiments.

[0061] Example 1

[0062] The present invention adopts an offline enhancement method to generate more equivalent (valid) data based on limited image data samples, enrich the distribution of training data, and make the model obtained through the training set more generalizable. Traditional copy and paste will cause the operation itself to bring abnormal characteristics, and the cracked fruit has small variability (in scale and shape), the scene is relatively simple, the foreground and background are highly separable, and manual operation is required. When the data set is as many as thousands of images, it is time-consuming, labor-intensive and labor-intensive.

[0063] like Figure 1-10As shown, the present invention provides an intelligent transplantation enhanced balancing method for cherry cracked fruit samples, which specifically includes:

[0064] Step 1: Binarize the target cracked fruit white background image f(x, y) to obtain a binary image with foreground and background separated, specifically:

[0065] S11. Read the JPG white background image with missing samples into BGR format, convert the BGR format into HSV format, and then take out only the H layer of the image;

[0066] S12. Use a Gaussian matrix with a length of 21 and a width of 21, with a standard deviation of 0, to perform Gaussian filtering on the H layer of the image to eliminate Gaussian noise and reduce the noise of the sample image;

[0067] S13. Based on the HSV color space, the hue H layer value is used as the basis for binarization;

[0068] Specifically, the existing OTSU algorithm principle idea uses a threshold to perform fixed threshold binarization of the image, and divides the image into background and foreground according to the grayscale characteristics of the image. However, this method ignores the spatial information of the image, and uses the grayscale distribution of the image as the basis for segmenting the image, which is also quite sensitive to noise. Since the image has a white background, the present invention is improved to be based on the HSV color space, using the hue H layer value as the basis for binarization.

[0069] Assume that the size of the image is MXN, the number of pixels in the H layer whose values ​​are less than the threshold T is recorded as N0, and the number of pixels in the H layer whose values ​​are greater than the threshold T is recorded as N1, then:

[0070] (1)ω0=N0 / (M×N)

[0071] (2)ω1=N1 / (M×N)

[0072] (3) N0+N1=M×N

[0073] (4)ω0+ω1=1

[0074] (5)μ=ω0*μ0+ω1*μ1

[0075] (6) g = ω0*(μ0-μ) 2 +ω1*(μ1-μ) 2

[0076] Substituting formula (5) into formula (6), we get the equivalent formula:

[0077] (7)g=ω0*ω1*(μ0-μ1) 2

[0078] Among them, ω0 is the proportion of background pixels in the H layer image, μ0 is the average value of ω0 in the H layer; ω1 is the proportion of foreground pixels in the H layer image, μ1 is the average value of ω1 in the H layer; μ is the average value of the H layer image, g is the inter-class variance, and when g is the maximum, the corresponding T is the optimal threshold of the H layer;

[0079] The known values ​​of M and N can be obtained from the image size. The unknown threshold T divides the pixel set R with values ​​less than the threshold T and the pixel set S with values ​​greater than the threshold T in the H layer of the image, and also determines N0 and N1. μ0 can be understood as the average value of all pixels in R, and μ1 can be understood as the average value of all pixels in S. ω0 and ω1 are only related to N0 and N1. In summary, g in formula (7) is only related to the threshold T. At this time, the value of T when g is maximum can be obtained by computer simulation.

[0080] According to the optimal threshold, 0 is set as the new value assigned when it is below the threshold, and 255 is set as the new value assigned when it is above the threshold, so as to obtain a binary image with obvious separation between foreground and background.

[0081] Step 2: The binary image is morphologically processed using a closing and opening operation, specifically:

[0082] The existing target cracked fruit white background image is f(x,y), and the natural environment collection image is g(x,y). The g(x,y) is used to process f(x,y). G(x,y) is called the structural element S. Let f(x,y) be X. The principle of corrosion is that the result of corroding X with S is the set of all x that are still in X after S is translated by x. In other words, the set obtained by corroding X with S is the set of all origin positions in X that include S. z represents the origin position, which can be expressed by the formula:

[0083]

[0084] The principle of expansion is the dual operation of erosion. After translating the structural element S by a, we get Sa. If Sa hits X, record this point a. The set of all a points that meet the above conditions is called the result of X being expanded by S, which can be expressed as:

[0085]

[0086] With a 15X15 two-dimensional array with a value of 1 as the core, the image is closed. In mathematical morphology, the closing operation is first dilation and then erosion, that is:

[0087]

[0088] Closing can fill small cracks in foreground objects while keeping the overall position and shape unchanged. Closing also filters the image by filling the concave corners of the image. Different sizes of structural elements will result in different filtering effects. Different choices of structural elements lead to different segmentations. This can fuse slightly connected patches, and when there are disconnected objects in the image, this method can repair the connection.

[0089] With a 9X9 two-dimensional array with a value of 1 as the core, the image is opened. In mathematical morphology, the opening operation first erodes and then expands, that is:

[0090]

[0091] The opening operation can remove isolated small points, burrs and small bridges, while the overall position and shape are inconvenient. The opening operation is a filter based on geometric operations. Different sizes of structural elements will lead to different filtering effects. Different structural element selections will also lead to different segmentation, that is, different features are extracted. This operation can remove noise and filter out some noise that is too small.

[0092] Step 3: Obtain the cracked fruit shape from the processed image using the bounding rectangle and automatic clipping technology, specifically:

[0093] The grayscale values ​​0 and 255 of the image after the closing and opening operation are reversed, and the minimum enclosing rectangle algorithm principle is used to obtain the coordinates x, y of the upper left corner of the matrix and the width w and height h of the matrix. According to the four values ​​of x, y, w, and h, the matrix is ​​used to cut out the cracked fruit, and a mask with a length of w and a height of h is obtained in the original image.

[0094] Step 4: Randomly change the size, translation and rotation of the cropped cracked fruit shape and mask, specifically:

[0095] Using a floating point number u between 0.5 and 1 and the coordinates x and y obtained in step 3, randomly scale the percentage and perform random size, translation, and rotation transformations on the cropped cracked fruit shape and mask.

[0096] The formula for the change is: 1 =ux;y 1 =uy;

[0097] The rotation formula is: 1 =uxcosθ-uycosθ;y 1 =ux sinθ+uy cosθ;

[0098] The translation formula is: 1 =x+u;y 1 =y+u;

[0099] Get the length rows and width cols of the cropped image, subtract h and w from them respectively to get new values ​​a and b, so as to limit the position of the cracked fruit image in the new background image.

[0100] Step 5: Replace the black pixels and restore the desired image. Specifically:

[0101] Traverse and replace according to the cropped image length rows and width cols. When the grayscale value of the mask is 0, it means that this point is a black pixel. Replace the color of the point and change it to BGR channel.

[0102] The cracked fruit images added by the present invention are samples that do not exist in the initial data set. New minority sample image information can be supplemented without deleting the original majority sample images (assuming that there are 100 pictures in the original data set, and the cracked fruit picture is cropped from the 101st picture and is not in the original 100 pictures), thereby significantly improving the current shortcomings of the undersampling method and the oversampling method.

[0103] The foregoing description of specific exemplary embodiments of the present invention is for the purpose of illustration and demonstration. These descriptions are not intended to limit the present invention to the precise form disclosed, and it is clear that many changes and variations can be made based on the above teachings. The purpose of selecting and describing the exemplary embodiments is to explain the specific principles of the present invention and its practical application, so that those skilled in the art can realize and utilize various different exemplary embodiments of the present invention and various different selections and changes. The scope of the present invention is intended to be limited by the claims and their equivalents.

Claims

1. An intelligent transplantation enhanced balancing method for cherry cracked fruit samples, characterized in that: include: The target cracked fruit white background image f(x, y) is binarized to obtain a binary image with foreground and background separated, specifically: Read the JPG white background image with missing samples into BGR format, then convert the BGR format into HSV format, and then only extract the H layer of the image; Perform Gaussian filtering on the H layer of the image to eliminate Gaussian noise; Based on the HSV color space, the hue H layer value is used as the basis for binarization. Specifically, let the size of the target cracked fruit white background image be MXN, the number of pixels in the image whose H layer value is less than the threshold T is recorded as N0, and the number of pixels whose H layer value is greater than the threshold T is recorded as N1, then: (1)ω0=N0 / (M×N) (2)ω1=N1 / (M×N) (3) N0+N1=M×N (4)ω0+ω1=1 (5)μ=ω0*μ0+ω1*μ1 (6)g=ω0*(μ0-μ) 2 +ω1*(μ1-μ) 2 Substituting formula (5) into formula (6), we get the equivalent formula: (7)g=ω0*ω1*(μ0-μ1) 2 Among them, ω0 is the proportion of background pixels in the H layer image, μ0 is the average value of ω0 in the H layer; ω1 is the proportion of foreground pixels in the H layer image, μ1 is the average value of ω1 in the H layer; μ is the average value of the H layer image, g is the inter-class variance, and when g is the maximum, the corresponding T is the optimal threshold of the H layer; According to the optimal threshold, 0 is set as the new value assigned when it is below the threshold, and 255 is set as the new value assigned when it is above the threshold, so as to obtain a binary image with foreground and background separated; The binary image is morphologically processed using a closing and opening operation; The cracked fruit shape is obtained from the processed image through the bounding rectangle and automatic clipping technology; Randomly change the size, translation and rotation of the cropped cracked fruit shapes and masks; Replace the black pixels and restore the desired image. Specifically, perform traversal and replacement according to the cropped image length rows and width cols. When the grayscale value of the mask is 0, it means that this point is a black pixel. Replace the color of the point and change it to BGR channel.

2. According to claim 1, a method for intelligent transplantation and enhanced balancing of cherry cracked fruit samples, characterized in that: The target cracked fruit white background image is f(x,y), and the natural environment collection image is g(x,y). The g(x,y) is used to process f(x,y). g(x,y) is called the structural element S. Let f(x,y) be X. The set obtained by corroding X with S is the set of all origin positions in X including S. z represents the origin position. It can be expressed as: The principle of expansion is the dual operation of erosion. After translating the structural element S by a, we get Sa. If Sa hits X, record this point a. The set of all a points that meet the above conditions is called the result of X being expanded by S, which can be expressed as:

3. According to claim 2, a method for intelligent transplantation and enhanced balancing of cherry cracked fruit samples, characterized in that: The binary image is morphologically processed using a closing and opening operation, specifically: With the two-dimensional array as the core, the image is closed. In mathematical morphology, the closing operation is first dilation and then erosion, that is: Closing operations can fill in cracks within foreground objects while leaving their overall position and shape unchanged; With the two-dimensional array as the core, the image is opened. In mathematical morphology, the opening operation first erodes and then expands, that is: The opening operation can remove isolated points, burrs and small bridges while keeping the overall position and shape unchanged.

4. The intelligent transplantation and enhanced balancing method for cherry cracked fruit samples according to claim 1, characterized in that: The cracked fruit shape is obtained from the processed image through the bounding rectangle and automatic clipping technology, specifically: First, the grayscale values ​​0 and 255 of the processed image are reversed, and the minimum enclosing rectangle algorithm principle is used to obtain the coordinates x, y of the upper left corner of the matrix and the width w, height h of the matrix. According to the four values ​​of x, y, w, and h, the matrix is ​​used to cut out the cracked fruit, and a mask with a length of w and a height of h is obtained in the original image.

5. The intelligent transplantation and enhanced balancing method for cherry cracked fruit samples according to claim 1, characterized in that: Using a floating point number u between 0.5 and 1 and coordinates x and y, the cropped cracked fruit shape and mask are randomly resized, translated, and rotated as follows: The formula for the change is: 1 =ux;y 1 =uy; The rotation formula is: 1 =uxcosθ-uycosθ; y 1 =uxsinθ+uycosθ; The translation formula is: 1 =x+u;y 1 =y+u; Get the length rows and width cols of the cropped image, subtract h and w from them respectively to get new values ​​a and b, so as to limit the position of the cracked fruit image in the new background image.

Citation Information

Patent Citations

  • Rice blast grading system and method

    AU2020103260A4

  • Building raise dust recognition system and method based on computer vision

    CN112149543A