Fruit and vegetable defect detection method and system
By preprocessing, decomposing, aggregating, color enhancement and feature extraction of fruit and vegetable images, the problem of insignificant noise and details in fruit and vegetable defect detection is solved, and the accuracy and accuracy of the detection are improved.
Patent Information
- Application Number
- CN202510618719.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-14
- Publication Date
- 2025-08-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, there is a lot of image noise, uneven color, and less obvious detail characteristics when detecting fruit and vegetable defects, resulting in low detection accuracy and accuracy.
By acquiring the target fruit and vegetable images for preprocessing, image decomposition and aggregation, color space conversion and enhancement, improved median filtering and feature image extraction, and detection using a preset detection model.
Effectively suppress image artifacts, enhance edge details and brightness contrast, and improve detection accuracy and accuracy.
Smart Images

Figure CN120495249A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of defect detection, and particularly relates to a method and system for detecting defects in fruits and vegetables. Background Art
[0002] After the fruits and vegetables are picked, due to the influence of factors such as growth, picking and transportation, some physical damage or growth damage may occur on the surface of the fruits and vegetables, such as bumps, squeezing, cracking, abrasions, insect bites, partial rot and other problems. For the commercialization of fruits and vegetables, it is usually necessary to control the quality of fruit and vegetable products, that is, to ensure that there are no defects on the surface of fruits and vegetables. Therefore, the existing technology usually obtains images of target fruits and vegetables and determines whether there are defects on the surface of fruits and vegetables based on the images and recognition models. However, the images actually obtained have problems such as high noise, uneven color, and unclear detail features, which leads to low precision and accuracy of the subsequent recognition model when performing defect detection on fruits and vegetables, affecting the defect detection process of fruits and vegetables. Summary of the Invention
[0003] In order to solve the above technical problems, the present invention provides a method and system for detecting defects in fruits and vegetables, which are used to solve the technical problems in the prior art.
[0004] In one aspect, the present invention provides the following technical solution: a method for detecting defects in fruits and vegetables, comprising: Acquire a target fruit and vegetable image, and preprocess the target fruit and vegetable image to obtain a processed fruit and vegetable image; performing image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; performing color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; Performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; Acquire training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results.
[0005] Compared with the prior art, the present invention has the following beneficial effects: the present invention first obtains a target fruit and vegetable image and preprocesses the target fruit and vegetable image to obtain a processed fruit and vegetable image; then performs image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; then performs color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; then performs improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; finally, obtains a training fruit and vegetable image, inputs the training fruit and vegetable image into a preset detection model for training, and inputs the fruit and vegetable feature image into the trained preset detection model for detection to output a fruit and vegetable detection result. The present invention first decomposes and aggregates the image, which can effectively suppress artifacts in the image while enhancing image edge details and improving focus information and clarity. Then, color enhancement is performed on the image, which can effectively remove noise in the image while improving image brightness and contrast, and effectively inheriting the naturalness and integrity of the image. Then, feature extraction is performed on the image, which can fully extract feature information and detail information in the image, thereby improving the accuracy and precision of subsequent model detection, thereby improving the accuracy of fruit and vegetable defect detection.
[0006] Preferably, the step of performing image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image includes: Obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively, perform image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix ; Based on the first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result with the second aggregation result ; Based on the first aggregation result With the second aggregation result Determine aggregated fruit and vegetable images : ; Where, Represent the first and second final aggregation weights respectively, Represents the inverse discrete cosine transform.
[0007] Preferably, the step of obtaining two processed fruit and vegetable images with different focuses and using them as a first focus image and a second focus image, respectively, and performing image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix, a second low-rank matrix, a first sparse matrix, or a second sparse matrix includes: Obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively. With the second focus image Perform matrix decomposition: ; Where, Indicates the first focus image or second focus image , Represent the first focus image respectively The corresponding first low-rank matrix or second focus image The corresponding second low-rank matrix, Represent the first focus image respectively The corresponding first sparse matrix or second focus image The corresponding second sparse matrix, Represent the first focus image respectively The corresponding first noise matrix or second focus image The corresponding second noise matrix; Construct the objective function: ; ; Where, express -norm squared, represents the norm, represents the regularization factor, express rank, represents the maximum rank, express of The sparse value of represents the sparse threshold; The objective function is iteratively solved until the iteration stop condition is met to obtain the Sparse matrix and low-rank matrix after iterations: ; ; Where, 、 Respectively represent sequence The first low-rank matrix or the second low-rank matrix after iterations, Respectively represent sequence The first sparse matrix or the second sparse matrix after iterations; Construct matrix row space and matrix column space: ; ; Where, Indicates the first focus image Corresponding to the first matrix row space or the second focus image The corresponding second matrix row space, Indicates the first focus image Corresponding to the first matrix column space or the second focus image The corresponding second matrix column space, Indicates the first focus image Corresponding to the first column of random matrix or the second focus image The corresponding second column of random matrix, Indicates the first focus image Corresponding to the first row of random matrix or the second focus image The corresponding second row of random matrix; Performing orthogonal triangular decomposition on the matrix row space and the matrix column space to obtain an orthogonal matrix and an upper triangular matrix, and determining a first low-rank matrix or a second low-rank matrix based on the orthogonal matrix and the upper triangular matrix: ; Where, represents the orthogonal matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the orthogonal matrix decomposed into the first matrix column space or the second matrix column space, represents the upper triangular matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the upper triangular matrix decomposed into the first matrix column space or the second matrix column space, Indicates preset parameters; Determine a first sparse matrix or a second sparse matrix based on the first low-rank matrix or the second low-rank matrix: ; Where, express Before The non-zero subset of the largest element, express The acquisition projection of the matrix.
[0008] Preferably, the first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result With the second aggregation result The steps include: The first low-rank matrix Decomposed into a number of first discrete cosine transform sub-blocks and the second low rank matrix The first discrete cosine transform sub-block is divided into a plurality of second discrete cosine transform sub-blocks, and a first Laplace energy matrix of the first discrete cosine transform sub-block and a second Laplace energy matrix of the second discrete cosine transform sub-block are determined, and a first energy matrix is calculated based on the first Laplace energy matrix and the second Laplace energy matrix. With the second energy : ; ; Where, represents the trace of the matrix, Respectively represent Rank a first Laplace energy matrix of the first discrete cosine sub-block of the column, and a second Laplace energy matrix of the second discrete cosine sub-block; Based on the first energy With the second energy Compute Aggregate Mapping : ; In the aggregate mapping Set an average mask in the corresponding map and map the aggregate based on the mask Iterate and output the final mapping : ; like If is an odd number, ; like If is an even number, ; Where, Indicates the After iterations Aggregate mapping at Indicates the After iterations Aggregate mapping at represents the average mask-to-boundary distance, represents the size of the average mask, Respectively represent the average mask to OK, The distance between the columns, represent the first and second decision thresholds respectively; Based on the first low-rank matrix , the second low-rank matrix With the final mapping Determine the first aggregation result : ; The first sparse matrix With the second sparse matrix Fusion is performed to obtain sparse fusion results , the fusion matrix result Perform morphological opening and closing operations respectively, and use the opening results Result of AND closing operation : ; Where, is the sparse fusion weight; Based on the opening operation result The result of the closing operation Determine the second aggregation result : ; Where, Represent the first and second sparse aggregation weights respectively.
[0009] Preferably, the step of performing color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image includes: The aggregated fruit and vegetable image is subjected to guided filtering, spatial transformation, fusion and factor calculation to obtain a fused image and a transformed fruit and vegetable image. Enhancement Factor ; Based on the enhancement factor Converting the fruit and vegetable images Enhance to get enhanced image : ; Where, represents the upper limit of the scale, Representation scale The weight of represents the convolution operation, represents the mapping function, Represents a two-dimensional Gaussian filter function; The enhanced image The weighted fusion is performed with the fused image to obtain an enhanced fruit and vegetable image.
[0010] Preferably, the aggregated fruit and vegetable image is subjected to guided filtering, spatial transformation, fusion and factor calculation to obtain a fused image and an enhancement factor. The steps include: performing guided filtering on the aggregated fruit and vegetable image to obtain a filtered fruit and vegetable image, and converting the filtered fruit and vegetable image from an RGB space to an HSV space to obtain a converted fruit and vegetable image; Extract the V channel image of the converted fruit and vegetable image , and correct the V channel image to obtain a corrected image : ; Where, Represents the brightness mean of the incident component of the V channel image; The correction image Converting to RGB space to obtain a spatially transformed image, and weightedly fusing the spatially transformed image with the filtered fruit and vegetable image to obtain a fused image; Calculating enhancement factors based on the converted fruit and vegetable images : ; Where, 、 Represent the adjustment coefficient and gain constant respectively, Indicates the conversion of fruit and vegetable images in The image of any channel in .
[0011] Preferably, the step of performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain the fruit and vegetable feature image includes: Set a median filter window in the enhanced fruit and vegetable image and calculate the first grayscale difference , the second grayscale difference , the third grayscale difference , the fourth grayscale difference : ; ; ; ; Where, 、 、 Respectively represent the maximum grayscale value, median grayscale value, and minimum grayscale value of the pixel points in the median filter window. Indicates the enhancement of fruit and vegetable images Gray value of the pixel at ; If the first grayscale difference Greater than 0 and the second grayscale difference If it is greater than 0, the third grayscale difference is determined Is it greater than 0 and the fourth grayscale difference Is it greater than 0? If the third grayscale difference Greater than 0 and the fourth grayscale difference If it is greater than 0, then the output , if the third grayscale difference Not greater than 0 and / or the fourth grayscale difference If it is not greater than 0, then output ; If the first grayscale difference Not greater than 0 and / or the second grayscale difference If the value is not greater than 0, the median filter window is expanded and when the median filter window is expanded to the maximum size of the window, the grayscale median of the pixel points in the current median filter window is output to obtain a median filtered fruit and vegetable image; Decompose the median filtered fruit and vegetable image into several sub-images, and calculate the grayscale average of the pixels in the neighborhood of each sub-image. And grayscale variance , based on the grayscale average With the grayscale variance Calculate the screening threshold for each of the sub-images : ; Where, is the control factor; Compare the grayscale value of each pixel point of the sub-image with the corresponding screening threshold Compare and find the gray value of the pixel of the sub-image is greater than the corresponding screening threshold. , the corresponding pixel points are retained to obtain a screening image, and a connected domain analysis algorithm is used to segment each of the screening images to obtain a number of connected domain images. The connected domain images with an area smaller than a preset area are eliminated to obtain a number of screening connected domain images, and the several screening connected domain images are combined to obtain a fruit and vegetable feature image.
[0012] In a second aspect, the present invention provides the following technical solution: a fruit and vegetable defect detection system, the system comprising: a processing module, configured to obtain target fruit and vegetable images and pre-process the target fruit and vegetable images to obtain processed fruit and vegetable images; an aggregation module, configured to perform image decomposition and image aggregation on the processed fruit and vegetable images to obtain aggregated fruit and vegetable images; an enhancement module, configured to perform color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; an extraction module, configured to perform improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; The detection module is used to obtain training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results.
[0013] In a third aspect, the present invention provides the following technical solution: a computer comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for detecting fruit and vegetable defects when executing the computer program.
[0014] In a fourth aspect, the present invention provides the following technical solution: a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the above-mentioned method for detecting defects in fruits and vegetables. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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 any creative work.
[0016] Figure 1 This is a flow chart of the fruit and vegetable defect detection method provided in Example 1 of the present invention; Figure 2 This is a structural block diagram of a fruit and vegetable defect detection system provided in the second embodiment of the present invention; Figure 3 A schematic diagram of the hardware structure of a computer provided in another embodiment of the present invention.
[0017] The embodiments of the present invention will be further described below with reference to the accompanying drawings. DETAILED DESCRIPTION
[0018] The following describes embodiments of the present invention in detail, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the embodiments of the present invention, and should not be construed as limiting the present invention.
[0019] Example 1 In the first embodiment of the present invention, Figure 1 As shown, a method for detecting defects in fruits and vegetables comprises: S1. Acquire a target fruit and vegetable image, and pre-process the target fruit and vegetable image to obtain a processed fruit and vegetable image; Specifically, the target fruit and vegetable image here refers to the captured image of the target fruit and vegetable, and the preprocessing process may include operations such as image rotation, image cropping, and image translation. Since the above preprocessing process is a commonly used image processing method in the prior art, it will not be described in detail here.
[0020] S2. performing image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; Wherein, the step S2 includes: S21, obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively, perform image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix ; Wherein, the step S21 includes: S211, obtain two processed fruit and vegetable images with different focuses and use them as a first focus image and a second focus image respectively, and use the first focus image With the second focus image Perform matrix decomposition: ; Where, Indicates the first focus image or second focus image , Represent the first focus image respectively The corresponding first low-rank matrix or second focus image The corresponding second low-rank matrix, Represent the first focus image respectively The corresponding first sparse matrix or second focus image The corresponding second sparse matrix, Represent the first focus image respectively The corresponding first noise matrix or second focus image The corresponding second noise matrix; Specifically, by acquiring images with different focuses, the focus information and detail information in the image can be effectively extracted. The low-rank matrix approximates the original image, while the sparse matrix includes the significant information in the image. When decomposing, the first focus image and the second focus image need to be converted into corresponding image matrices.
[0021] S212. Construct the objective function: ; ; Where, express -norm squared, represents the norm, represents the regularization factor, express rank, represents the maximum rank, express of The sparse value of represents the sparse threshold; Specifically, the maximum rank here specifically refers to the maximum rank of the low-rank matrix, and the sparse threshold can be specifically expressed as the product of the sparsity of the sparse matrix and the set threshold, which is to avoid the sparse value of the sparse matrix being too large.
[0022] S213, iteratively solve the objective function until the iteration stop condition is met to obtain the first Sparse matrix and low-rank matrix after iterations: ; ; Where, 、 Respectively represent sequence The first low-rank matrix or the second low-rank matrix after iterations, Respectively represent sequence The first sparse matrix or the second sparse matrix after iterations.
[0023] S214. Construct matrix row space and matrix column space: ; ; Where, Indicates the first focus image Corresponding to the first matrix row space or the second focus image The corresponding second matrix row space, Indicates the first focus image Corresponding to the first matrix column space or the second focus image The corresponding second matrix column space, Indicates the first focus image Corresponding to the first column of random matrix or the second focus image The corresponding second column of random matrix, Indicates the first focus image Corresponding to the first row of random matrix or the second focus image The corresponding second row of random matrix; Specifically, a bilateral random projection method is used here to construct the matrix row space and the matrix column space, so that the low rank of the bilateral random projection approximates the solution in step S213.
[0024] S215. Perform orthogonal triangular decomposition on the matrix row space and the matrix column space to obtain an orthogonal matrix and an upper triangular matrix, and determine a first low-rank matrix or a second low-rank matrix based on the orthogonal matrix and the upper triangular matrix: ; Where, represents the orthogonal matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the orthogonal matrix decomposed into the first matrix column space or the second matrix column space, represents the upper triangular matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the upper triangular matrix decomposed into the first matrix column space or the second matrix column space, Indicates preset parameters; Specifically, the preset parameters here are specifically Power Scheme parameters, which are used to reduce the impact of the slow decay of the singular values of the matrices corresponding to the first focus image and the second focus image, and can reduce the errors of the first low-rank matrix and the second low-rank matrix by increasing the values of the preset parameters.
[0025] S216. Determine a first sparse matrix or a second sparse matrix based on the first low-rank matrix or the second low-rank matrix: ; Where, express Before The non-zero subset of the largest element, express The acquisition projection of the matrix.
[0026] S22, based on the first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result with the second aggregation result ; Wherein, the step S22 includes: S221, the first low-rank matrix Decomposed into a number of first discrete cosine transform sub-blocks and the second low rank matrix The first discrete cosine transform sub-block is divided into a plurality of second discrete cosine transform sub-blocks, and a first Laplace energy matrix of the first discrete cosine transform sub-block and a second Laplace energy matrix of the second discrete cosine transform sub-block are determined, and a first energy matrix is calculated based on the first Laplace energy matrix and the second Laplace energy matrix. With the second energy : ; ; Where, represents the trace of the matrix, Respectively represent Rank a first Laplace energy matrix of the first discrete cosine sub-block of the column, and a second Laplace energy matrix of the second discrete cosine sub-block; Specifically, for the Laplace energy matrix, it is calculated as follows: ; in, represents the first low-rank matrix or the second lowest rank matrix Discrete cosine transform of the image sub-block, 、 、 Represent the image sub-blocks at different positions respectively. In the above steps, first the first low-rank matrix , the second low-rank matrix Decompose into 8×8 sub-blocks, and then perform discrete cosine transform on each sub-block to obtain the corresponding transform results. According to the above calculation formula, the first Laplace energy matrix and the second Laplace energy matrix can be obtained based on the corresponding transform results.
[0027] S222, based on the first energy With the second energy Compute Aggregate Mapping : .
[0028] S223, in the aggregation mapping Set an average mask in the corresponding map and map the aggregate based on the mask Iterate and output the final mapping : ; like If is an odd number, ; like If is an even number, ; Where, Indicates the After iterations Aggregate mapping at Indicates the After iterations Aggregate mapping at represents the average mask-to-boundary distance, represents the size of the average mask, Respectively represent the average mask to OK, The distance between the columns, represent the first and second decision thresholds respectively; Specifically, the average mask size here is 7×7, and the first and second decision thresholds are 0.2 and 0.1, respectively. Since the output of the average mask is multi-valued, it is necessary to generate the required binary mapping based on its threshold. Therefore, the first and second decision thresholds are set in this step.
[0029] S224, based on the first low-rank matrix , the second low-rank matrix With the final mapping Determine the first aggregation result : .
[0030] S225, the first sparse matrix With the second sparse matrix Fusion is performed to obtain sparse fusion results , the fusion matrix result Perform morphological opening and closing operations respectively, and use the opening results Result of AND closing operation : ; Where, is the sparse fusion weight; Specifically, the sparse fusion weight here is specifically 0.5. The purpose of setting the sparse fusion weight is to improve the contour structure information and image quality of the image.
[0031] S226, based on the opening operation result The result of the closing operation Determine the second aggregation result : ; Where, Represent the first and second sparse aggregation weights respectively; Specifically, the first and second sparse aggregation weights are both 1. By setting the first and second sparse aggregation weights, the contrast of the image can be effectively improved.
[0032] S23, based on the first aggregation result With the second aggregation result Determine aggregated fruit and vegetable images : ; Where, Represent the first and second final aggregation weights respectively, represents the inverse discrete cosine transform; Specifically, the first and second final aggregation weights are both 1. The purpose of setting the first and second final aggregation weights is to further improve the aggregation quality and image contrast.
[0033] S3, performing color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; Wherein, the step S3 includes: S31, performing guided filtering, spatial conversion, fusion and factor calculation on the aggregated fruit and vegetable image to obtain a fused image and a converted fruit and vegetable image. Enhancement Factor ; Wherein, the step S31 includes: S311 . Perform guided filtering on the aggregated fruit and vegetable image to obtain a filtered fruit and vegetable image, and convert the filtered fruit and vegetable image from an RGB space to an HSV space to obtain a converted fruit and vegetable image.
[0034] S312: Extracting the V channel image of the converted fruit and vegetable image , and correct the V channel image to obtain a corrected image : ; Where, Indicates the mean brightness of the incident component of the V channel image.
[0035] S313, the corrected image Converting to RGB space to obtain a spatially transformed image, and weightedly fusing the spatially transformed image with the filtered fruit and vegetable image to obtain a fused image; Specifically, the weights of the spatially transformed image and the filtered fruit and vegetable image in the weighted fusion are both 0.5.
[0036] S314: Calculating an enhancement factor based on the converted fruit and vegetable image : ; Where, 、 Represent the adjustment coefficient and gain constant respectively, Indicates the conversion of fruit and vegetable images in The image of any channel in; Specifically, the adjustment coefficient is used to adjust the color intensity of the image, and the gain constant is used to enhance the image. The adjustment coefficient is 0.95, and the gain constant is 1.2.
[0037] S32, based on the enhancement factor Converting the fruit and vegetable images Enhance to get enhanced image : ; Where, represents the upper limit of the scale, Representation scale The weight of represents the convolution operation, represents the mapping function, Represents a two-dimensional Gaussian filter function; Specifically, the scale here The weights can be determined according to the main components of the image. The main components are determined by inputting the eigenvalues and eigenvectors of the image and performing principal component analysis. The upper limit of the scale here is 3. The mapping function is used to make the color distribution uniform.
[0038] S33, the enhanced image Performing weighted fusion with the fused image to obtain an enhanced fruit and vegetable image; Specifically, in the above weighted fusion process, the enhanced image The weights of the image and the fused image are both 0.5.
[0039] S4, performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; Wherein, the step S4 includes: S41, setting a median filter window in the enhanced fruit and vegetable image and calculating a first grayscale difference , the second grayscale difference , the third grayscale difference , the fourth grayscale difference : ; ; ; ; Where, 、 、 Respectively represent the maximum grayscale value, median grayscale value, and minimum grayscale value of the pixel points in the median filter window. Indicates the enhancement of fruit and vegetable images The gray value of the pixel at .
[0040] S42, if the first grayscale difference Greater than 0 and the second grayscale difference If it is greater than 0, the third grayscale difference is determined Is it greater than 0 and the fourth grayscale difference Is it greater than 0? If the third grayscale difference Greater than 0 and the fourth grayscale difference If it is greater than 0, then the output , if the third grayscale difference Not greater than 0 and / or the fourth grayscale difference If it is not greater than 0, then output .
[0041] S43, if the first grayscale difference Not greater than 0 and / or the second grayscale difference If the median filter window is not greater than 0, the median filter window is expanded and when the median filter window is expanded to the maximum window size, the grayscale median of the pixel points in the current median filter window is output to obtain a median filtered fruit and vegetable image.
[0042] S44, decomposing the median filtered fruit and vegetable image into several sub-images, and calculating the grayscale average of the pixels in the neighborhood of each sub-image And grayscale variance , based on the grayscale average With the grayscale variance Calculate the screening threshold for each of the sub-images : ; Where, is the control factor; Specifically, the control factor here is -0.1.
[0043] S45, comparing the grayscale value of each pixel point of the sub-image with the corresponding screening threshold If the gray value of the pixel point of the sub-image is greater than the corresponding screening threshold , the corresponding pixel points are retained to obtain a screening image, each of the screening images is segmented using a connected domain analysis algorithm to obtain a number of connected domain images, connected domain images with an area smaller than a preset area are eliminated to obtain a number of screening connected domain images, and the several screening connected domain images are combined to obtain a fruit and vegetable feature image; Specifically, the connected domain analysis algorithm here is a commonly used algorithm in the prior art, so it will not be described in detail. The preset area here can be determined according to the type of fruits and vegetables and the defect types of different fruits and vegetables.
[0044] S5. Obtain training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results; Specifically, the preset detection model here is an SVM model. By obtaining training fruit and vegetable images and training the model with the training fruit and vegetable images, the fruit and vegetable feature maps are input into the trained model to output the corresponding results.
[0045] The fruit and vegetable defect detection method provided in the first embodiment of the present invention first obtains a target fruit and vegetable image and preprocesses the target fruit and vegetable image to obtain a processed fruit and vegetable image; then performs image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; then performs color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; then performs improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; finally, obtains a training fruit and vegetable image, inputs the training fruit and vegetable image into a preset detection model for training, and inputs the trained fruit and vegetable feature image into the preset detection model for detection to output a fruit and vegetable detection result. The present invention first decomposes and aggregates the image, which can effectively suppress artifacts in the image while enhancing image edge details and improving focus information and clarity. Then, color enhancement is performed on the image, which can effectively remove noise in the image while improving image brightness and contrast, and effectively inheriting the naturalness and integrity of the image. Then, feature extraction is performed on the image, which can fully extract feature information and detail information in the image, thereby improving the accuracy and precision of subsequent model detection, thereby improving the accuracy of fruit and vegetable defect detection.
[0046] Example 2 like Figure 2As shown, in a second embodiment of the present invention, a fruit and vegetable defect detection system is provided, the system comprising: Processing module 1 is used to obtain target fruit and vegetable images and pre-process the target fruit and vegetable images to obtain processed fruit and vegetable images; Aggregation module 2, configured to perform image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; Enhancement module 3, configured to perform color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; Extraction module 4, used for performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; Detection module 5, used to obtain training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results; The aggregation module 2 includes: The decomposition submodule is used to obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively, and perform image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix ; Aggregation result submodule, for , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result with the second aggregation result ; Aggregation submodule, for With the second aggregation result Determine aggregated fruit and vegetable images : ; Where, Represent the first and second final aggregation weights respectively, Represents the inverse discrete cosine transform.
[0047] The decomposition submodule includes: The decomposition unit is used to obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively. With the second focus image Perform matrix decomposition: ; Where, Indicates the first focus image or second focus image , Represent the first focus image respectively The corresponding first low-rank matrix or second focus image The corresponding second low-rank matrix, Represent the first focus image respectively The corresponding first sparse matrix or second focus image The corresponding second sparse matrix, Represent the first focus image respectively The corresponding first noise matrix or second focus image The corresponding second noise matrix; Function unit, used to construct the target function: ; ; Where, express -norm squared, represents the norm, represents the regularization factor, express rank, represents the maximum rank, express of The sparse value of represents the sparse threshold; The solving unit is used to iteratively solve the objective function until the iteration stop condition is met to obtain the first Sparse matrix and low-rank matrix after iterations: ; ; Where, 、 Respectively represent sequence The first low-rank matrix or the second low-rank matrix after iterations, Respectively represent sequence The first sparse matrix or the second sparse matrix after iterations; Spatial units are used to construct matrix row space and matrix column space: ; ; Where, Indicates the first focus image Corresponding to the first matrix row space or the second focus image The corresponding second matrix row space, Indicates the first focus image Corresponding to the first matrix column space or the second focus image The corresponding second matrix column space, Indicates the first focus image Corresponding to the first column of random matrix or the second focus image The corresponding second column of random matrix, Indicates the first focus image Corresponding to the first row of random matrix or the second focus image The corresponding second row of random matrix; An orthogonal unit is used to perform orthogonal triangular decomposition on the matrix row space and the matrix column space to obtain an orthogonal matrix and an upper triangular matrix, and determine a first low-rank matrix or a second low-rank matrix based on the orthogonal matrix and the upper triangular matrix: ; Where, represents the orthogonal matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the orthogonal matrix decomposed into the first matrix column space or the second matrix column space, represents the upper triangular matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the upper triangular matrix decomposed into the first matrix column space or the second matrix column space, Indicates preset parameters; A sparse unit, configured to determine a first sparse matrix or a second sparse matrix based on the first low-rank matrix or the second low-rank matrix: ; Where, express Before The non-zero subset of the largest element, express The acquisition projection of the matrix.
[0048] The aggregation result submodule includes: A transformation unit, configured to transform the first low-rank matrix Decomposed into a number of first discrete cosine transform sub-blocks and the second low rank matrix The first discrete cosine transform sub-block is divided into a plurality of second discrete cosine transform sub-blocks, and a first Laplace energy matrix of the first discrete cosine transform sub-block and a second Laplace energy matrix of the second discrete cosine transform sub-block are determined, and a first energy matrix is calculated based on the first Laplace energy matrix and the second Laplace energy matrix. With the second energy : ; ; Where, represents the trace of the matrix, Respectively represent Rank a first Laplace energy matrix of the first discrete cosine sub-block of the column, and a second Laplace energy matrix of the second discrete cosine sub-block; A mapping unit for With the second energy Compute Aggregate Mapping : ; Iteration unit for the aggregate map Set an average mask in the corresponding map and map the aggregate based on the mask Iterate and output the final mapping : ; like If is an odd number, ; like If is an even number, ; Where, Indicates the After iterations Aggregate mapping at Indicates the After iterations Aggregate mapping at represents the average mask-to-boundary distance, represents the size of the average mask, Respectively represent the average mask to OK, The distance between the columns, represent the first and second decision thresholds respectively; A first aggregation unit is configured to aggregate the first low-rank matrix , the second low-rank matrix With the final mapping Determine the first aggregation result : ; Morphological unit, for converting the first sparse matrix With the second sparse matrix Fusion is performed to obtain sparse fusion results , the fusion matrix result Perform morphological opening and closing operations respectively, and use the opening results Result of AND closing operation : ; Where, is the sparse fusion weight; The second aggregation unit is used to The result of the closing operation Determine the second aggregation result : ; Where, Represent the first and second sparse aggregation weights respectively.
[0049] The enhancement module 3 includes: The conversion submodule is used to perform guided filtering, spatial conversion, fusion and factor calculation on the aggregated fruit and vegetable image to obtain a fused image and a converted fruit and vegetable image. Enhancement Factor ; Enhancer module based on the enhancer factor Converting the fruit and vegetable images Enhance to get enhanced image : ; Where, represents the upper limit of the scale, Representation scale The weight of represents the convolution operation, represents the mapping function, Represents a two-dimensional Gaussian filter function; Fusion submodule, used to enhance the image The weighted fusion is performed with the fused image to obtain an enhanced fruit and vegetable image.
[0050] The conversion submodule includes: a conversion unit, configured to perform guided filtering on the aggregated fruit and vegetable image to obtain a filtered fruit and vegetable image, and convert the filtered fruit and vegetable image from an RGB space to an HSV space to obtain a converted fruit and vegetable image; A correction unit for extracting the V channel image of the converted fruit and vegetable image , and correct the V channel image to obtain a corrected image : ; Where, Represents the brightness mean of the incident component of the V channel image; A weighting unit for weighting the corrected image Converting to RGB space to obtain a spatially transformed image, and weightedly fusing the spatially transformed image with the filtered fruit and vegetable image to obtain a fused image; A factor unit for calculating an enhancement factor based on the converted fruit and vegetable image : ; Where, 、 Represent the adjustment coefficient and gain constant respectively, Indicates the conversion of fruit and vegetable images in The image of any channel in .
[0051] The extraction module 4 includes: The difference submodule is used to set a median filter window in the enhanced fruit and vegetable image and calculate the first grayscale difference , the second grayscale difference , the third grayscale difference , the fourth grayscale difference : ; ; ; ; Where, 、 、 Respectively represent the maximum grayscale value, median grayscale value, and minimum grayscale value of the pixel points in the median filter window. Indicates the enhancement of fruit and vegetable images Gray value of the pixel at ; The first output submodule is used to output the first grayscale difference. Greater than 0 and the second grayscale difference If it is greater than 0, the third grayscale difference is determined Is it greater than 0 and the fourth grayscale difference Is it greater than 0? If the third grayscale difference Greater than 0 and the fourth grayscale difference If it is greater than 0, then the output , if the third grayscale difference Not greater than 0 and / or the fourth grayscale difference If it is not greater than 0, then output ; The second output submodule is used to output the first grayscale difference. Not greater than 0 and / or the second grayscale difference If the value is not greater than 0, the median filter window is expanded and when the median filter window is expanded to the maximum size of the window, the grayscale median of the pixel points in the current median filter window is output to obtain a median filtered fruit and vegetable image; The threshold submodule is used to decompose the median filtered fruit and vegetable image into several sub-images and calculate the grayscale average value of the pixels in the neighborhood of each sub-image. And grayscale variance , based on the grayscale average With the grayscale variance Calculate the screening threshold for each of the sub-images : ; Where, is the control factor; The screening submodule is used to compare the grayscale value of each pixel of the sub-image with the corresponding screening threshold If the gray value of the pixel point of the sub-image is greater than the corresponding screening threshold , the corresponding pixel points are retained to obtain a screening image, and a connected domain analysis algorithm is used to segment each of the screening images to obtain a number of connected domain images. The connected domain images with an area smaller than a preset area are eliminated to obtain a number of screening connected domain images, and the several screening connected domain images are combined to obtain a fruit and vegetable feature image.
[0052] In other embodiments of the present invention, embodiments of the present invention provide the following technical solution: a computer, comprising a memory 102, a processor 101, and a computer program stored in the memory 102 and executable on the processor 101; the processor 101 implements the above-described method for detecting fruit and vegetable defects when executing the computer program.
[0053] Specifically, the processor 101 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or may be configured as one or more integrated circuits for implementing the embodiments of the present invention.
[0054] Memory 102 may include a large-capacity memory for data or instructions. By way of example, and not limitation, memory 102 may include a hard disk drive (HDD), a floppy disk drive, a solid-state drive (SSD), flash memory, an optical disk, a magneto-optical disk, a magnetic tape, or a Universal Serial Bus (USB) drive, or a combination of two or more of these. Where appropriate, memory 102 may include removable or non-removable (or fixed) media. Where appropriate, memory 102 may be internal or external to the data processing device. In certain embodiments, memory 102 is non-volatile memory. In certain embodiments, memory 102 includes read-only memory (ROM) and random access memory (RAM). Where appropriate, the ROM may be a mask-programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically alterable ROM (EAROM) or a flash memory (FLASH), or a combination of two or more of these. Under appropriate circumstances, the RAM can be a static random access memory (SRAM) or a dynamic random access memory (DRAM), where the DRAM can be a fast page mode dynamic random access memory (FPMDRAM), an extended data output dynamic random access memory (EDODRAM), a synchronous dynamic random access memory (SDRAM), etc.
[0055] The memory 102 may be used to store or cache various data files that need to be processed and / or used for communication, as well as possible computer program instructions executed by the processor 101 .
[0056] The processor 101 implements the above-mentioned fruit and vegetable defect detection method by reading and executing computer program instructions stored in the memory 102.
[0057] In some embodiments, the computer may further include a communication interface 103 and a bus 100. Figure 3 As shown, the processor 101 , the memory 102 , and the communication interface 103 are connected via a bus 100 and communicate with each other.
[0058] The communication interface 103 is used to implement communication between the various modules, devices, units, and / or equipment in the embodiments of the present invention. The communication interface 103 can also implement data communication with other components such as external devices, image / data acquisition equipment, databases, external storage, and image / data processing workstations.
[0059] Bus 100 includes hardware, software, or both, and couples components of a computer device to each other. Bus 100 includes, but is not limited to, at least one of the following: a data bus, an address bus, a control bus, an expansion bus, and a local bus. By way of example and not limitation, bus 100 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Extended Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a Hyper Transport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a Micro Channel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local Bus (VLB) bus, or other suitable buses, or a combination of two or more of these. Bus 100 may include one or more buses, where appropriate. Although embodiments of the present invention describe and illustrate a particular bus, the present invention contemplates any suitable bus or interconnect.
[0060] The computer can execute the fruit and vegetable defect detection method of the present invention based on the acquired fruit and vegetable defect detection system, thereby realizing fruit and vegetable defect detection.
[0061] In still further embodiments of the present invention, in combination with the above-mentioned fruit and vegetable defect detection method, embodiments of the present invention provide the following technical solution: a storage medium having a computer program stored thereon, wherein the computer program implements the above-mentioned fruit and vegetable defect detection method when executed by a processor.
[0062] Those skilled in the art will appreciate that the logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device), or in conjunction with such instruction execution system, apparatus, or device. For purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate, or transport a program for use by an instruction execution system, apparatus, or device, or in conjunction with such instruction execution system, apparatus, or device.
[0063] More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic devices), a portable computer disk cartridge (magnetic devices), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disc read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering, or processing in another suitable manner as necessary, and then stored in a computer memory.
[0064] It should be understood that various components of the present invention may be implemented using hardware, software, firmware, or a combination thereof. In the aforementioned embodiments, multiple steps or methods may be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using hardware, as in another embodiment, any one or a combination of the following technologies known in the art may be used: a discrete logic circuit having logic gate circuits for implementing logic functions on data signals, an application-specific integrated circuit having suitable combinational logic gate circuits, a programmable gate array (PGA), a field-programmable gate array (FPGA), etc.
[0065] The technical features of the above-mentioned embodiments can be combined arbitrarily. In order to make the description concise, not all possible combinations of the technical features in the above-mentioned embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0066] The above-described embodiments merely illustrate several implementations of the present invention, and while their descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the patent. It should be noted that a person skilled in the art would be able to make numerous variations and improvements without departing from the spirit of the present invention, all of which fall within the scope of protection of the present invention. Therefore, the scope of protection of the patent for this invention shall be determined by the appended claims.
Claims
1. A method for detecting defects in fruits and vegetables, characterized in that: include: Acquire a target fruit and vegetable image, and preprocess the target fruit and vegetable image to obtain a processed fruit and vegetable image; performing image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image; performing color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; Performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; Acquire training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results.
2. The method for detecting defects in fruits and vegetables according to claim 1, wherein: The step of performing image decomposition and image aggregation on the processed fruit and vegetable image to obtain an aggregated fruit and vegetable image includes: Obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively, perform image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix ; Based on the first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result With the second aggregation result ; Based on the first aggregation result With the second aggregation result Determine aggregated fruit and vegetable images : ; Where, Represent the first and second final aggregation weights respectively, Represents the inverse discrete cosine transform.
3. The method for detecting defects in fruits and vegetables according to claim 2, characterized in that: The steps of obtaining two processed fruit and vegetable images with different focuses and using them as a first focus image and a second focus image, respectively, and performing image decomposition on the first focus image and the second focus image to obtain a first low-rank matrix, a second low-rank matrix, a first sparse matrix, or a second sparse matrix include: Obtain two processed fruit and vegetable images with different focuses and use them as the first focus image and the second focus image respectively. With the second focus image Perform matrix decomposition: ; Where, Indicates the first focus image or second focus image , Represent the first focus image respectively The corresponding first low-rank matrix or second focus image The corresponding second low-rank matrix, Represent the first focus image respectively The corresponding first sparse matrix or second focus image The corresponding second sparse matrix, Represent the first focus image respectively The corresponding first noise matrix or second focus image The corresponding second noise matrix; Construct the objective function: ; ; Where, express -norm squared, represents the norm, represents the regularization factor, express rank, represents the maximum rank, express of The sparse value of represents the sparse threshold; The objective function is iteratively solved until the iteration stop condition is met to obtain the Sparse matrix and low-rank matrix after iterations: ; ; Where, 、 Respectively represent sequence The first low-rank matrix or the second low-rank matrix after iterations, Respectively represent sequence The first sparse matrix or the second sparse matrix after iterations; Construct matrix row space and matrix column space: ; ; Where, Indicates the first focus image Corresponding to the first matrix row space or the second focus image The corresponding second matrix row space, Indicates the first focus image Corresponding to the first matrix column space or the second focus image The corresponding second matrix column space, Indicates the first focus image Corresponding to the first column of random matrix or the second focus image The corresponding second column of random matrix, Indicates the first focus image Corresponding to the first row of random matrix or the second focus image The corresponding second row of random matrix; Performing orthogonal triangular decomposition on the matrix row space and the matrix column space to obtain an orthogonal matrix and an upper triangular matrix, and determining a first low-rank matrix or a second low-rank matrix based on the orthogonal matrix and the upper triangular matrix: ; Where, represents the orthogonal matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the orthogonal matrix decomposed into the first matrix column space or the second matrix column space, represents the upper triangular matrix obtained by decomposing the first matrix row space or the second matrix row space, represents the upper triangular matrix decomposed into the first matrix column space or the second matrix column space, Indicates preset parameters; Determine a first sparse matrix or a second sparse matrix based on the first low-rank matrix or the second low-rank matrix: ; Where, express Before The non-zero subset of the largest element, express The acquisition projection of the matrix.
4. The method for detecting defects in fruits and vegetables according to claim 2, wherein: Based on the first low-rank matrix , the second low-rank matrix , the first sparse matrix , the second sparse matrix Determine the first aggregation result with the second aggregation result The steps include: The first low-rank matrix Decomposed into a number of first discrete cosine transform sub-blocks and the second low rank matrix The first discrete cosine transform sub-block is divided into a plurality of second discrete cosine transform sub-blocks, and a first Laplace energy matrix of the first discrete cosine transform sub-block and a second Laplace energy matrix of the second discrete cosine transform sub-block are determined, and a first energy matrix is calculated based on the first Laplace energy matrix and the second Laplace energy matrix. With the second energy : ; ; Where, represents the trace of the matrix, Respectively represent Rank a first Laplace energy matrix of the first discrete cosine sub-block of the column, and a second Laplace energy matrix of the second discrete cosine sub-block; Based on the first energy With the second energy Compute Aggregate Mapping : ; In the aggregate mapping Set an average mask in the corresponding map and map the aggregate based on the mask Iterate and output the final mapping : ; like If is an odd number, ; like If is an even number, ; Where, Indicates the After iterations Aggregate mapping at Indicates the After iterations Aggregate mapping at represents the average mask-to-boundary distance, represents the size of the average mask, Respectively represent the average mask to OK, The distance between the columns, represent the first and second decision thresholds respectively; Based on the first low-rank matrix , the second low-rank matrix With the final mapping Determine the first aggregation result : ; The first sparse matrix With the second sparse matrix Fusion is performed to obtain sparse fusion results , the fusion matrix result Perform morphological opening and closing operations respectively, and use the opening results Result of AND closing operation : ; Where, is the sparse fusion weight; Based on the opening operation result The result of the closing operation Determine the second aggregation result : ; Where, Represent the first and second sparse aggregation weights respectively.
5. The method for detecting defects in fruits and vegetables according to claim 1, wherein: The step of performing color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image includes: The aggregated fruit and vegetable image is subjected to guided filtering, spatial transformation, fusion and factor calculation to obtain a fused image and a transformed fruit and vegetable image. Enhancement Factor ; Based on the enhancement factor Converting the fruit and vegetable images Enhance to get enhanced image : ; Where, represents the upper limit of the scale, Representation scale The weight of represents the convolution operation, represents the mapping function, Represents a two-dimensional Gaussian filter function; The enhanced image The weighted fusion is performed with the fused image to obtain an enhanced fruit and vegetable image.
6. The method for detecting defects in fruits and vegetables according to claim 5, characterized in that: The aggregated fruit and vegetable image is subjected to guided filtering, spatial transformation, fusion and factor calculation to obtain a fused image and an enhancement factor. The steps include: performing guided filtering on the aggregated fruit and vegetable image to obtain a filtered fruit and vegetable image, and converting the filtered fruit and vegetable image from an RGB space to an HSV space to obtain a converted fruit and vegetable image; Extract the V channel image of the converted fruit and vegetable image , and correct the V channel image to obtain a corrected image : ; Where, Represents the brightness mean of the incident component of the V channel image; The correction image Converting to RGB space to obtain a spatially transformed image, and weightedly fusing the spatially transformed image with the filtered fruit and vegetable image to obtain a fused image; Calculating enhancement factors based on the converted fruit and vegetable images : ; Where, 、 Represent the adjustment coefficient and gain constant respectively, Indicates the conversion of fruit and vegetable images in The image of any channel in .
7. The method for detecting defects in fruits and vegetables according to claim 1, wherein: The step of performing improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image includes: Set a median filter window in the enhanced fruit and vegetable image and calculate the first grayscale difference , the second grayscale difference , the third grayscale difference , the fourth grayscale difference : ; ; ; ; Where, 、 、 Respectively represent the maximum grayscale value, median grayscale value, and minimum grayscale value of the pixel points in the median filter window. Indicates the enhancement of fruit and vegetable images Gray value of the pixel at ; If the first grayscale difference Greater than 0 and the second grayscale difference If it is greater than 0, the third grayscale difference is determined Is it greater than 0 and the fourth grayscale difference Is it greater than 0? If the third grayscale difference Greater than 0 and the fourth grayscale difference If it is greater than 0, then the output , if the third grayscale difference Not greater than 0 and / or the fourth grayscale difference If it is not greater than 0, then output ; If the first grayscale difference Not greater than 0 and / or the second grayscale difference If the value is not greater than 0, the median filter window is expanded and when the median filter window is expanded to the maximum size of the window, the grayscale median of the pixel points in the current median filter window is output to obtain a median filtered fruit and vegetable image; Decompose the median filtered fruit and vegetable image into several sub-images, and calculate the grayscale average of the pixels in the neighborhood of each sub-image. And grayscale variance , based on the grayscale average With the grayscale variance Calculate the screening threshold for each of the sub-images : ; Where, is the control factor; Compare the grayscale value of each pixel point of the sub-image with the corresponding screening threshold If the gray value of the pixel point of the sub-image is greater than the corresponding screening threshold , the corresponding pixel points are retained to obtain a screening image, and a connected domain analysis algorithm is used to segment each of the screening images to obtain a number of connected domain images. The connected domain images with an area smaller than a preset area are eliminated to obtain a number of screening connected domain images, and the several screening connected domain images are combined to obtain a fruit and vegetable feature image.
8. A fruit and vegetable defect detection system, characterized in that: The system comprises: a processing module, configured to obtain target fruit and vegetable images and pre-process the target fruit and vegetable images to obtain processed fruit and vegetable images; an aggregation module, configured to perform image decomposition and image aggregation on the processed fruit and vegetable images to obtain aggregated fruit and vegetable images; an enhancement module, configured to perform color space conversion and color enhancement processing on the aggregated fruit and vegetable image to obtain an enhanced fruit and vegetable image; an extraction module, configured to perform improved median filtering and feature image extraction on the enhanced fruit and vegetable image to obtain a fruit and vegetable feature image; The detection module is used to obtain training fruit and vegetable images, input the training fruit and vegetable images into a preset detection model for training, input the fruit and vegetable feature images into the trained preset detection model for detection, and output fruit and vegetable detection results.
9. A computer comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the fruit and vegetable defect detection method according to any one of claims 1 to 7 is implemented.
10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the fruit and vegetable defect detection method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Scotopic vision image enhancement method based on Retinex and image fusion
CN116188339A
Low-contrast magnet device surface defect image enhancement method based on machine vision
CN116385359A
Retinex low-illumination image enhancement method based on image fusion
CN118333922A
Chip pin coplanarity detection method and system based on multi-focus image fusion
CN119887626A