Citrus surface defect detection method based on Retinex algorithm and deep learning

By combining Retinex algorithm and deep learning, a dynamic preprocessing pipeline is constructed, the lighting and background interference problems in citrus surface defect detection are solved, and the detection accuracy and real-timeness are improved, especially the ability to identify small defects.

CN120374530APending Publication Date: 2025-07-25JIANGXI NORMAL UNIV +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510437549.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-09
Publication Date
2025-07-25

AI Technical Summary

Technical Problem

In the detection of citrus surface defects, there are problems such as insufficient data and high labeling costs, interference with lighting and background, contradiction between model complexity and real-time, difficulty in detection of small defects and difficulty in classification of multiple defects, resulting in insufficient detection accuracy and real-time.

Method used

Combining the Retinex algorithm and deep learning, through image decomposition, lighting correction and feature enhancement, a dynamic preprocessing pipeline is built to improve image quality and introduce Transformer's attention mechanism to optimize the feature extraction and detection performance of deep learning models.

Benefits of technology

It improves the robustness of the model in complex lighting and background, enhances the detection ability of small defects, reduces background interference, improves detection accuracy and real-timeness, and reduces data demand.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120374530A_ABST
    Figure CN120374530A_ABST
Patent Text Reader

Abstract

The invention relates to a citrus surface defect detection method based on a Retinex algorithm and deep learning, and the method comprises the following steps: collecting citrus images of different defect types under different illumination conditions, and marking defect regions and defect types; adjusting the illumination uniformity and detail contrast of the citrus image by using a Retinex algorithm to form a Retinex enhanced image; introducing an attention mechanism of Transform, and performing feature extraction and attention modeling in combination with a convolutional neural network; predicting illumination distribution of the Retinex enhanced image through a deep learning model, and correcting illumination deviation; noise or artifacts in the Retinex enhanced image are removed, and an image after dynamic preprocessing is obtained; and selecting a deep learning model for defect detection, and training a defect detection model by using the dynamically preprocessed image. According to the method, the traditional advantages of image enhancement and the adaptive ability of deep learning are combined, an efficient and accurate solution is provided for citrus surface defect detection, the problems of uneven illumination, shadow interference and the like are effectively solved, and the robustness of defect detection is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of visual detection, and particularly to a citrus surface defect detection method based on the Retinex algorithm and deep learning. Background Art

[0002] The citrus surface defect detection method based on deep learning utilizes advanced convolutional neural networks (CNNs) and object detection technologies to achieve automated and high-precision detection of citrus surface defects. It can significantly improve the quality management level in each link, especially in aspects such as automated sorting, disease monitoring, warehousing logistics, and retail quality control. These application fields help reduce manual dependence, improve production efficiency, and ensure the final quality and market competitiveness of citrus products.

[0003] Although significant progress has been made in citrus surface defect detection using deep learning, there are still the following defects and problems:

[0004] A) Insufficient data and high annotation cost: It is difficult to obtain citrus defect data. Especially for different types of defects (such as minor disease spots and severe cracks), the number of labeled samples is often insufficient. Therefore, model training may overfit, resulting in insufficient generalization ability.

[0005] B) Interference from light and background: In the natural environment, the diversity of lighting conditions and backgrounds will have a significant impact on the detection accuracy. Therefore, the model has weak defect detection ability in areas with high reflection or shadow coverage. The main reason is the non-standardization of image acquisition equipment and environment, resulting in uneven sample quality.

[0006] C) Difficulty in detecting small defects: For defects with small sizes or blurred boundaries (such as initial disease spots or minor cracks), deep learning models are difficult to accurately identify. Therefore, it may lead to missed detections or false detections. The reason is that small targets account for too low a proportion in the image, and feature information is easily ignored by convolutional operations.

[0007] D) Contradiction between model complexity and real-time performance: Deep learning models (such as YOLOv8, Faster R-CNN, Mask R-CNN) have high computational complexity and are difficult to meet the real-time detection requirements in actual production lines. Therefore, the deployment cost is high and the real-time performance is limited.

[0008] E) Difficulty in classifying multiple defects: It is easy to be confused when classifying multiple complex defects (such as the unclear boundary between disease spots and insect pests). Therefore, the accuracy will decrease. The main reason is that the features of different defects may have high similarity, making it difficult for the model to distinguish. Summary of the Invention

[0009] The technical problem to be solved by the present invention is to overcome the deficiencies in the prior art and provide a citrus surface defect detection method based on the Retinex algorithm and deep learning. By combining the Retinex algorithm with deep learning, a dynamic preprocessing pipeline is constructed, which can robustly detect citrus surface defects under complex lighting and background conditions.

[0010] The present invention is realized through the following technical solutions:

[0011] A citrus surface defect detection method based on the Retinex algorithm and deep learning includes the following steps:

[0012] S1. Collect citrus images under different lighting conditions and different defect types, and mark the defect areas and defect types;

[0013] S2. Use the Retinex algorithm to simulate the ability of the human visual system to separate lighting and reflection, adjust the lighting uniformity and detail contrast of the citrus image, and form a Retinex-enhanced image;

[0014] S3. Introduce the attention mechanism of Transformer, and combine with a convolutional neural network for feature extraction and attention modeling;

[0015] S4. Predict the lighting distribution of the Retinex-enhanced image through a deep learning model for correcting lighting deviation;

[0016] S5. Remove the noise or artifacts caused by Retinex processing in the Retinex-enhanced image, and obtain an image with uniform lighting, enhanced contrast and noise suppression, that is, the dynamically preprocessed image, as the input of the subsequent defect detection model;

[0017] S6. Select a deep learning model based on object detection for defect detection, and use the dynamically preprocessed image to train the defect detection model.

[0018] According to the above technical solution, preferably, in step S1, a high-definition industrial camera or an ordinary imaging device is used to collect the citrus image, the lighting conditions include natural light, strong light, and dim light, and the defect types include cracks, lesions, and pests.

[0019] According to the above technical solution, preferably, in step S2, for the citrus image, the image I(x) is decomposed into the product of the reflection component R(x) and the lighting component L(x), that is: I(x) = R(x) * L(x).

[0020] According to the above technical solution, preferably, step S2 includes:

[0021] Apply a logarithmic transformation to the image I(x) to obtain log(I(x)) = log(R(x)) + log(L(x));

[0022] Smooth the image I(x) using Gaussian filtering to obtain the illumination component L(x), and then remove the illumination component L(x) from the original citrus image to obtain the reflection component R(x) = I(x) / L(x);

[0023] Introduce an energy function and regularization constraints for optimization and solution, and minimize the objective function through a variational model;

[0024] Perform further histogram equalization on the reflection component R(x) to obtain the enhanced reflection component R equalized (x);

[0025] Combine the enhanced reflection component R equalized (x) with the illumination component L(x) to reconstruct and form the Retinex-enhanced image.

[0026] According to the above technical solution, preferably, after step S2, form a training sample of multi-modal data with the Retinex-enhanced image and the original citrus image, and enrich the training sample through data augmentation methods such as rotation, scaling, and mirror flipping.

[0027] According to the above technical solution, preferably, step S3 includes:

[0028] Use CNN as the backbone network to extract multi-scale feature maps;

[0029] Use multi-head self-attention to calculate the correlation of features, and input the extracted features into the Transformer module to capture global dependencies.

[0030] According to the above technical solution, preferably, step S4 includes:

[0031] Train a deep learning model for predicting the illumination distribution, with the input citrus image as the input and outputting the illumination distribution map;

[0032] Use the predicted illumination distribution map to correct the illumination bias of the input image,

[0033]

[0034] where I input is the original input image and L is the predicted illumination distribution map.

[0035] According to the above technical solution, preferably, step S5 includes:

[0036] Train a deep learning denoising model and load the Retinex-enhanced image;

[0037] Use Gaussian denoising, bilateral filtering, and deep learning denoising to obtain a denoised image.

[0038] According to the above technical solution, preferably, it further includes:

[0039] S7. Perform performance evaluation and optimization on the defect detection model, specifically:

[0040] Use detection accuracy, recall rate, and F1 score as performance indicators to evaluate the defect detection model;

[0041] Adjust the Retinex algorithm parameters, optimize the structure and hyperparameters during the training of the defect detection model, and enhance the diversity of the training samples to train the defect detection model.

[0042] The beneficial effects of the present invention are:

[0043] (1) Improve the robustness of the model: The Retinex algorithm performs illumination correction on the input image, reducing the interference of uneven illumination on the feature extraction of the deep learning model, thereby improving the illumination uniformity. Under strong light, low light, or variable illumination conditions, the preprocessing ability of Retinex can significantly improve the robustness of the deep model in various environments, making it more adaptable to complex environments.

[0044] (2) Enhance image details and contrast: The Retinex algorithm enhances the details of the object surface by highlighting the reflection component, providing a higher-quality input image. For citrus surface defect detection, this can help the deep model better identify small defects (such as cracks, spots, etc.), thereby enhancing details; Retinex eliminates the illumination interference in over-bright or over-dark areas, making it easier for the deep learning model to focus on meaningful features.

[0045] (3) Improve the performance of small target defect detection: The Retinex algorithm can magnify the features of small targets (such as spots with blurred boundaries), thereby enhancing the detection ability of the deep learning model for small target defects and enhancing weak features. More boundary information is retained in the Retinex output image, helping the deep model accurately locate the defect area and better retain boundary details.

[0046] (4) Suppress background interference: The Retinex algorithm focuses on the reflection component, eliminating the artifacts caused by illumination changes in the background, thereby reducing the background interference problem of the deep model and suppressing the background; for complex backgrounds, the high-quality image generated after Retinex correction can reduce the sensitivity of the deep learning model to noise and reduce noise.

[0047] (5)Improving the training efficiency of deep learning models: After the Retinex algorithm adjusts the dynamic range of the image, the pixel distribution of the input image becomes more balanced, helping the deep learning model learn features faster. By enhancing the quality of the input image through Retinex preprocessing, the dependence on large-scale datasets is reduced, and the data requirements are decreased.

[0048] (6)Improving specific effects in application fields: In the application scenario of citrus surface defect detection, the specific advantages brought by the combination of Retinex and deep learning include:

[0049] Balancing complex illumination: The problem of uneven illumination on the citrus surface caused by gloss or shadow can be solved by Retinex correction;

[0050] Accurately identifying edge-blurred defects: The Retinex output enhances the visual contrast of blurred boundaries, helping the model improve detection accuracy;

[0051] Improving data utilization rate: Under the condition of limited data volume, the quality of the image processed by Retinex is improved, and the model's utilization efficiency of the data is also enhanced.

[0052] (7) The introduction of the attention mechanism (Transformer architecture) further improves the detection accuracy: More weights are dynamically allocated to key regions during the feature extraction process, enhancing the model's ability to focus on defect regions while suppressing background interference. Therefore, the detection accuracy of small target defects or regions with blurred boundaries is improved. Description of the Drawings

[0053] Figure 1 It is a schematic flowchart of the method for detecting citrus surface defects provided by the present invention. Specific Embodiments

[0054] In order to enable those skilled in the art of the present technology to better understand the technical solutions of the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and the best embodiments. Based on the embodiments of the invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of the invention.

[0055] Retinex is an image processing theory proposed by Edwin H. Land in 1964 to explain the mechanism by which the human visual system perceives color and brightness constancy of objects under different lighting conditions. It combines the concepts of "Retina" and "Cortex", simulating the ability of the human vision to separate the illumination and reflectance components. The Retinex theory holds that the light intensity of an image consists of two parts: the illumination component (Illumination): the contribution of ambient light to the reflected light from the object surface, and the reflectance component (Reflectance): the inherent color and texture characteristics of the object itself. Separate the illumination and reflectance components from the input image to reduce the impact of uneven illumination on the image while preserving or enhancing the reflectance component.

[0056] The deep learning-based citrus surface defect detection method uses advanced convolutional neural networks (CNNs) and object detection techniques to achieve automated and high-precision detection of citrus surface defects. The core of this technology lies in that by combining the Retinex algorithm and the deep learning model, the illumination correction ability of Retinex and the adaptive characteristics of deep learning can be utilized to further improve the image enhancement and object detection effects in complex environments. By constructing and training a deep learning model, different defects on the citrus surface (such as lesions, cracks, pests, etc.) are identified and classified.

[0057] As shown in the figure, the present invention includes the following steps:

[0058] S1. Collect citrus images under different lighting conditions and different defect types, and mark the defect areas and defect types.

[0059] In step S1, a high-definition industrial camera or an ordinary imaging device is used to collect the citrus images. The lighting conditions include natural light, strong light, dim light, and complex backgrounds. The defect types include cracks, lesions, and pests. At the same time, the collected images are annotated to mark the defect areas and their types, providing a basis for subsequent model training.

[0060] S2. Utilize the Retinex algorithm to simulate the ability of the human visual system to separate illumination and reflection, adjust the illumination uniformity and detail contrast of the citrus image, and form a Retinex-enhanced image.

[0061] For the citrus image, the image I(x) is decomposed into the product of the reflectance component R(x) and the illumination component L(x), that is: I(x) = R(x) * L(x). Specifically, step S2 includes:

[0062] S21. Apply a logarithmic transformation to the image I(x) to convert the multiplicative relationship into an additive relationship, so as to stabilize the relationship between the reflection and illumination components, obtaining log(I(x)) = log(R(x)) + log(L(x)).

[0063] S22. Smooth the image I(x) using Gaussian filtering to obtain the illumination component L(x), where the Gaussian Filter method is:

[0064] L(x) = I(x) * G(x; σ)

[0065] G(x; σ) is the Gaussian kernel function, σ controls the degree of smoothness, and * represents the convolution operation.

[0066] Furthermore, remove the illumination component L(x) from the original citrus image to obtain the reflection component R(x) = I(x) / L(x), and R(x) contains the high-frequency features and edge information of the image.

[0067] S23. Further improve the separation effect through an optimization method, introduce an energy function and regularization constraints (smoothness constraint and sparsity constraint) for optimization and solution, ensure that the separated illumination and reflection components are more accurate, and then minimize the objective function through a variational model. The construction of the smoothness and sparsity constraints is as follows:

[0068] S23-1: The smoothness constraint is used to constrain the illumination component L(x) because the illumination change is usually slow and smooth. Gradient smoothness constraint:

[0069]

[0070] Among them, represents the gradient of the illumination component L(x), and ||·|| 2 represents the sum of the squares of the gradients, and Ω is the domain of the image.

[0071] S23-2: The sparsity constraint is mainly used to constrain the reflection component R(x). The reflection component R(x) mainly contains the inherent material, texture, and edges of the object, and these features are often sparsely distributed, that is, there are no significant reflection changes in most areas, and only a few areas contain obvious edges and high-frequency components.

[0072] Sparsity constraint:

[0073]

[0074] S23-3: Combine the smoothness and sparsity regularization terms to construct an energy function:

[0075]

[0076] Among them, ||I - L·R|| 2 Ensure that the reconstructed image is close to the original input image. λ1 is the weight of the smoothness regularization term, which controls the smoothness of the illumination component L(x), and λ2 is the weight of the sparsity regularization term, which controls the sparsity of the reflection component R(x).

[0077] S23 - 4: Finally, the variational model minimizes the objective function: min E(L, R), and optimally solves for L(x) and R(x).

[0078] S23 - 5: Combine Gaussian kernels of different scales to enhance details:

[0079]

[0080] Where I(x) is the input image and Gs(x) is the Gaussian convolution kernel with scale s.

[0081] S24. Perform further histogram equalization on the reflection component R(x) to enhance the detail clarity. Histogram equalization can redistribute the pixel intensity values of the reflection component, thereby increasing the contrast of the image, highlighting hidden details, and obtaining the enhanced reflection component R equalized (x).

[0082] Normalize the reflection component: Ensure that the pixel value range of the reflection component is suitable for histogram equalization. Usually, it is necessary to normalize R(x) to the gray - level range of [0, 255]:

[0083]

[0084] Where, R min and R max are the minimum and maximum values of the reflection component respectively.

[0085] Use the cv2.equalizeHist() function in OpenCV to perform histogram equalization on the image to obtain the reflection component R equalized (x).

[0086] S25. Combine the enhanced reflection component R equalized (x) with the illumination component L(x) to reconstruct and form the Retinex - enhanced image.

[0087] I enhanced (x) = L(x)·R equalized (x)

[0088] After step S2, combine the Retinex - enhanced image with the original citrus image to form a training sample of multi - modal data, and enrich the training sample through data augmentation methods such as rotation, scaling, and mirror flipping.

[0089] S3. Introduce the attention mechanism of Transformer and combine it with a convolutional neural network for feature extraction and attention modeling.

[0090] Use an efficient CNN as the backbone network (such as ResNet, EfficientNet) to extract multi-scale feature maps. Calculate the correlation of features using multi-head self-attention (MHSA), and input the extracted features into the Transformer module to capture global dependencies.

[0091] In addition, the modeling process also includes the optimization of small targets and fuzzy boundaries. First, the global attention mechanism of Transformer automatically assigns high weights to small target defects and fuzzy boundary regions. The attention distribution map is visualized (using Grad-CAM or Attention Map) to verify whether the model focuses on the target area. Apply the Transformer module to different scale features to improve the perception ability of small targets through attention modeling of multi-scale features.

[0092] S4. Predict the illumination distribution of the Retinex-enhanced image through a deep learning model for correcting illumination bias, and the implementation steps are as follows:

[0093] S41. Train a deep learning model for predicting the illumination distribution (such as ResNet), with the input citrus image as the input and output the illumination distribution map;

[0094] S42. Use the predicted illumination distribution map to correct the illumination bias of the input image,

[0095]

[0096] where I input is the original input image, L is the predicted illumination distribution map, and ∈ is a small value to prevent division by zero errors, so the illumination bias is corrected.

[0097] S5. Remove the noise or artifacts caused by Retinex processing in the Retinex-enhanced image to obtain an image with uniform illumination, enhanced contrast, and noise suppression, that is, the dynamically preprocessed image, as the input of the subsequent defect detection model, and the implementation steps are as follows:

[0098] S51. Train a deep learning denoising model, load the Retinex-enhanced image I(x) / / image = load_retinex_image(image_path)

[0099] S52. Apply Gaussian denoising / / denoised_image = gaussian_denoise(image)

[0100] S53. Apply bilateral filtering / / denoised_image = bilateral_denoise(denoised_image)

[0101] S54. Use deep learning for denoising to obtain the denoised image.

[0102] Integrate the Retinex algorithm and the deep learning module into a pipeline to achieve dynamic preprocessing. Input the original citrus image and adjust the resolution to fit the subsequent model (such as scaling to 224×224); adjust the illumination uniformity and detail contrast of the image through the Retinex algorithm in step S2, correct the illumination deviation using step S4, remove the noise or artifacts caused by Retinex processing using step S5, and output the image with uniform illumination, enhanced contrast, and noise suppression as the input for the subsequent defect detection model.

[0103] S6. Select a deep learning model based on object detection (such as YOLOv8) for defect detection, and use the dynamically preprocessed image to train the defect detection model to improve the model's adaptability to complex illumination conditions and diverse backgrounds.

[0104] S7. Conduct performance evaluation and optimization of the defect detection model. Use detection accuracy (Precision), recall rate (Recall), and F1 score (F1-Score) as performance metrics. Verify the effectiveness of the Retinex + deep learning module by comparing the performance of the model with and without preprocessing; adjust the parameters of the Retinex algorithm (such as Gaussian kernel scale, weight coefficient), optimize the structure and hyperparameters during the training of the defect detection model, and enhance the diversity of the training samples to train the defect detection model.

[0105] The following embodiments are one of the embodiments of this application:

[0106] (A) Dataset: Contains images of normal and defective citrus fruits. Total number of images: 2000 (1600 for the training set, 400 for the test set)

[0107] (B) Data augmentation: Includes random cropping, rotation, and brightness adjustment to simulate different illumination conditions.

[0108] (C) Model: Use ResNet50 as the classification model.

[0109] Two versions:

[0110] No preprocessing: directly input the original image.

[0111] Use preprocessing: first apply Retinex + deep learning module for dynamic correction and then input into the model.

[0112] (D) Result comparison

[0113] Initial parameter settings

[0114] Model Version Precision Recall F1-Score Without Preprocessing 85.2% 81.0% 83.0% With Preprocessing 91.5% 88.7% 90.1%

[0115] (E) Conclusion: The model using Retinex + deep learning module preprocessing is significantly better than the model without preprocessing in various indicators. The preprocessing significantly improves the impact of uneven illumination on classification and enhances the ability to extract detailed features.

[0116] (F) Further optimization:

[0117] (F1) Optimize Retinex algorithm parameters: improve the illumination correction effect by adjusting Retinex parameters (such as Gaussian kernel scale, weight coefficient, etc.).

[0118] Parameter Tuning Precision Recall F1-Score Default Parameters 91.5% 88.7% 90.1% Gaussian Kernel Scale Optimization 92.3% 89.4% 90.8% Weight Coefficient Optimization 93.0% 89.8% 91.3%

[0119] (F2) Optimize the deep learning module: optimize the network structure (such as introducing deeper networks, residual blocks) and hyperparameters (such as learning rate, batch size): use deeper ResNet101 to replace ResNet50. Adjust the learning rate to 1e - 4 and the batch size to 32.

[0120] Network Structure Precision Recall F1-Score ResNet50 91.5% 88.7% 90.1% ResNet101 93.8% 91.5% 92.6%

[0121] (F3) Enhance the diversity of the dataset: add more data augmentations for different illumination conditions and defect types to improve the robustness of the model to complex scenarios.

[0122] Dataset Augmentation Precision Recall F1-Score Without Data Augmentation 91.5% 88.7% 90.1% After Data Augmentation 94.2% 92.8% 93.5%

[0123] (F4) Final optimization result: After adjusting Retinex parameters, optimizing the deep learning module, and enhancing the diversity of the dataset, the final performance is as follows:

[0124] Model Version Precision Recall F1-Score Without Preprocessing 85.2% 81.0% 83.0% With Preprocessing (Optimized) 94.2% 92.8% 93.5%

[0125] (F5) Final conclusion: The Retinex + deep learning module effectively improves the robustness of the model to uneven illumination scenarios. Adjusting Retinex parameters (such as Gaussian kernel scale, weight coefficient) can further improve the illumination correction effect. Optimization of the deep learning module (deeper networks and adjusted hyperparameters) significantly enhances the classification performance. Data augmentation expands the adaptability of the model and improves its stability under complex illumination conditions.

[0126] This application provides a citrus surface defect detection method based on the Retinex algorithm and deep learning, which has a wide range of application fields, covering multiple links from agricultural production to terminal sales. The following are the main application fields:

[0127] Citrus planting and quality management: Detect problems such as lesions and mildew on the citrus surface, help growers detect diseases early, optimize prevention and control measures, judge the maturity and health status of citrus, and guide growers to choose the best picking time. Its value is to improve the orchard management efficiency and reduce the risk of disease transmission.

[0128] Food processing and pretreatment: In food processing links such as fruit juice and jam, automatically remove citrus with obvious defects or rot to ensure product quality and conduct processing raw material screening. Its value is to improve the quality of processed products and reduce the food safety risk brought by unqualified raw materials.

[0129] Warehousing and logistics monitoring: Conduct quality monitoring in the warehousing link, detect surface damage or spoilage of citrus caused by storage environment (such as humidity, temperature). Its value is to process problem batches in advance and reduce goods losses. During transportation, quickly detect the arriving citrus and evaluate whether there is a quality decline during transportation.

[0130] Market quality monitoring: At the retail terminal, conduct spot checks on the appearance quality of citrus to ensure compliance with market sales standards.

[0131] By combining the Retinex algorithm with deep learning, this application constructs a dynamic preprocessing pipeline, which can robustly detect citrus surface defects under complex lighting and background conditions. This method combines the traditional advantages of image enhancement and the adaptive ability of deep learning, providing an efficient and accurate solution for citrus surface defect detection. Combining the Retinex algorithm with a deep learning model for dynamic preprocessing of citrus surface images can effectively solve problems such as uneven lighting and shadow interference, and improve the robustness of defect detection.

[0132] The above is only the preferred embodiment of the present invention. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present invention, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present invention.

Claims

1. A citrus surface defect detection method based on the Retinex algorithm and deep learning, characterized in that, It includes the following steps: S1. Collect citrus images under different lighting conditions and with different defect types, and mark the defect areas and defect types; S2. Utilize the Retinex algorithm to simulate the ability of the human visual system to separate light and reflection, adjust the lighting uniformity and detail contrast of the citrus image, and form a Retinex-enhanced image; S3. Introduce the attention mechanism of Transformer, and combine with a convolutional neural network for feature extraction and attention modeling; S4. Predict the lighting distribution of the Retinex-enhanced image through a deep learning model for correcting lighting deviation; S5. Remove the noise or artifacts caused by Retinex processing in the Retinex-enhanced image, obtain an image with uniform lighting, enhanced contrast, and noise suppression, that is, the dynamically preprocessed image, as the input for the subsequent defect detection model; S6. Select a deep learning model based on object detection for defect detection, and use the dynamically preprocessed image to train the defect detection model.

2. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 1, characterized in that, In step S1, a high-definition industrial camera or an ordinary imaging device is used to collect the citrus image, The lighting conditions include natural light, strong light, and dim light, and the defect types include cracks, lesions, and pests.

3. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 1, characterized in that, In step S2, for the citrus image, the image I(x) is decomposed into the product of the reflection component R(x) and the lighting component L(x), that is: I(x) = R(x) * L(x).

4. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 3, wherein Step S2 includes: Apply a logarithmic transformation to the image I(x) to obtain log(I(x)) = log(R(x)) + log(L(x)); Use Gaussian filtering to smooth the image I(x) to obtain the lighting component L(x), and then remove the lighting component L(x) from the original citrus image to obtain the reflection component R(x) = I(x) / L(x); Introduce an energy function and regularization constraints for optimization and solution, and minimize the objective function through a variational model; Perform further histogram equalization on the reflection component R(x) to obtain the enhanced reflection component R equalized (x); Combine the enhanced reflected component R equalized (x) with the illumination component L(x) to reconstruct and form the Retinex enhanced image.

5. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 4, wherein After step S2, the Retinex-enhanced image and the original citrus image are together formed into a training sample of multimodal data, And through data augmentation methods such as rotation, scaling, and mirror flipping, the training samples are enriched.

6. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 1, characterized in that Step S3 includes: Use CNN as the backbone network to extract multi-scale feature maps; Use multi-head self-attention to calculate the correlation of features, and input the extracted features into the Transformer module to capture global dependencies.

7. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 4, characterized in that, Step S4 includes: Train a deep learning model for predicting the lighting distribution, with the input citrus image as the input and outputting the lighting distribution map; Use the predicted lighting distribution map to correct the lighting deviation of the input image, Among them, I input is the original input image, and L is the predicted illumination distribution map.

8. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 4 or 7, characterized in that Step S5 includes: Train a deep learning denoising model and load the Retinex-enhanced image; Use Gaussian denoising, bilateral filtering, and deep learning denoising to obtain the denoised image.

9. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 5, characterized in that, It also includes: S7. Evaluate and optimize the performance of the defect detection model.

10. The citrus surface defect detection method based on the Retinex algorithm and deep learning according to claim 9, wherein Step S7 includes: Use detection accuracy, recall rate, and F1 score as performance indicators to evaluate the defect detection model; Adjust the parameters of the Retinex algorithm, optimize the structure and hyperparameters during the training of the defect detection model, and enhance the diversity of the training samples, and then train the defect detection model.

Citation Information

Cited By

  • Photovoltaic glass on-line defect visual detection method and system

    CN120953245A