Fruit sugar degree detection method and system in different light environments

Through the DenseNet algorithm and spectral image reconstruction model, the problems of expensive traditional fruit sugar content detection equipment and ambient light interference were solved, and fast and accurate fruit sugar content detection was achieved.

CN120629153AActive Publication Date: 2025-09-12ZHEJIANG SCI-TECH UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511130287.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-13
Publication Date
2025-09-12
Estimated Expiration
2045-08-13

AI Technical Summary

Technical Problem

Traditional fruit sugar content detection methods rely on expensive equipment and are cumbersome to operate. They are easily affected by ambient light, resulting in slow detection speed and unstable results.

Method used

An ambient light compensation model based on the DenseNet algorithm and a spectral image reconstruction algorithm are used, combined with a partial least squares regression algorithm. By acquiring multiple fruit images and hyperspectral images, a data set is constructed and model training is performed to achieve ambient light compensation and image reconstruction, and ultimately perform sugar content detection.

Benefits of technology

It can achieve fast and accurate fruit sugar content detection under different lighting environments, avoiding the dependence on expensive equipment and interference from ambient light, and improving the stability and speed of detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120629153A_ABST
    Figure CN120629153A_ABST
Patent Text Reader

Abstract

The invention provides a fruit sugar degree detection method and system under different light environments, and relates to the technical field of fruit sugar degree detection, and the method comprises the steps: obtaining a plurality of fruit images and a plurality of fruit hyperspectral images; screening each fruit hyperspectral image, and recombining each screened image into an RGB (Red, Green and Blue) image; taking the RGB image as a fruit target image, matching each fruit image with the fruit target image, and constructing a fruit image data set; training the ambient light compensation algorithm model by taking the fruit image data set as training data; acquiring a real-time fruit image of the to-be-detected fruit; inputting a real-time fruit image into the trained ambient light compensation algorithm model for ambient light compensation, and outputting a fruit compensation image; inputting the fruit compensation image into a spectral image reconstruction algorithm model for reconstruction, and outputting a fruit reconstruction image; and inputting the fruit reconstruction image into a fruit sugar degree detection model for detection, and outputting the fruit sugar degree.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of fruit sugar content detection, and in particular to a method and system for detecting fruit sugar content under different lighting environments. Background Art

[0002] With the continuous advancement of science and technology, the application of fruit sugar content testing technology in food quality control and agricultural production has become increasingly important. As a key quality indicator of fruit, sugar content directly influences consumer purchasing decisions. Therefore, rapid and accurate fruit sugar content testing has become an indispensable part of post-harvest fruit processing and grading.

[0003] Traditional methods for detecting the sugar content of fruits usually rely on physical and chemical detection technologies, such as refractometers and hyperspectral imaging technology, which require expensive equipment, are cumbersome to operate, and are easily affected by environmental conditions, resulting in slow detection speed.

[0004] In addition, when smart devices take images under different ambient light conditions, the results are often easily affected by the ambient light, resulting in unstable sugar content prediction results. Summary of the Invention

[0005] In view of the above shortcomings of the existing technology, the purpose of the embodiments of the present invention is to provide a method for detecting the sugar content of fruit under different lighting environments. This method can solve the technical problems that traditional fruit sugar content detection methods generally rely on physical and chemical detection technologies, require expensive equipment, are cumbersome to operate, and are easily affected by environmental conditions, resulting in slow detection speed. In addition, when smart devices capture images under different ambient lighting conditions, the results are often easily interfered with by the ambient light, resulting in unstable sugar content prediction results.

[0006] A first aspect of an embodiment of the present invention provides a method for detecting the sugar content of fruit under different lighting environments, comprising: S1: Acquire multiple fruit images of fruit samples under different lighting environments and multiple fruit hyperspectral images under multiple halogen lamp light sources, wherein each fruit hyperspectral image corresponds one-to-one to a fruit image taken at the same shooting angle; S2: Based on the preset wavelength, each fruit hyperspectral image is screened to obtain multiple screened images, and each screened image is recombined into an RGB image; S3: Use the RGB image as the fruit target image, match each fruit image with the fruit target image, and build a fruit image dataset; S4: Using the fruit image dataset as training data, the ambient light compensation algorithm model based on the DenseNet algorithm is trained; S5: Acquire a real-time image of the fruit to be detected; S6: Input the real-time fruit image into the trained ambient light compensation algorithm model to perform ambient light compensation, and output a fruit compensated image with the same color temperature as the fruit target image; S7: inputting the fruit compensation image into the spectral image reconstruction algorithm model for reconstruction, and outputting the fruit reconstructed image; S8: Input the reconstructed fruit image into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, and output the sugar content of the fruit to be detected.

[0007] A second aspect of an embodiment of the present invention provides a system for detecting the sugar content of fruit under different lighting environments, comprising: a processor and a memory; The memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method for detecting the sugar content of fruits under different lighting environments as described in the first aspect are implemented.

[0008] According to a third aspect of the embodiments of the present invention, a readable storage medium is provided, on which a program or instruction is stored. When the program or instruction is executed by a processor, the steps of the method for detecting the sugar content of fruit under different lighting environments as described in the first aspect are implemented.

[0009] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least: In an embodiment of the present invention, a real-time fruit image is input into a trained ambient light compensation algorithm model for ambient light compensation, and a fruit compensation image having the same color temperature as the fruit target image is output. This makes it less susceptible to interference from ambient light when the smart device takes images under different ambient lights, thereby ensuring the stability of the sugar content prediction result. The fruit compensation image is input into a spectral image reconstruction algorithm model for reconstruction, and a fruit reconstructed image is output. The fruit reconstructed image is then input into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, and the fruit sugar content of the fruit to be detected is output. This no longer relies on physical and chemical detection technology, does not require expensive equipment, is easy to operate, is not easily affected by environmental conditions, and has a fast detection speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] The accompanying drawings are only for the purpose of illustrating specific embodiments and are not to be considered as limiting the present invention. Throughout the drawings, the same reference symbols represent the same components. Obviously, the drawings described below are only some embodiments of the present invention. It is clear that those skilled in the art can derive other drawings based on these drawings without inventive effort.

[0011] Figure 1 This is a flow chart of a method for detecting the sugar content of fruit under different lighting environments provided by an embodiment of the present invention; Figure 2 This is a structural diagram of a lighting control platform provided by an embodiment of the present invention; Figure 3 This is a structural diagram of a key control module provided by an embodiment of the present invention; Figure 4 This is a structural diagram of an LED lamp group module provided by an embodiment of the present invention; Figure 5 This is a structural diagram of a mobile load-carrying gripper provided by an embodiment of the present invention; Figure 6 1 is a structural diagram of an ambient light compensation algorithm model based on the DenseNet algorithm provided by an embodiment of the present invention; Figure 7 Schematic diagram of the structure of a spectral image reconstruction algorithm model provided by an embodiment of the present invention; Figure 8 The figure is a structural diagram of a fruit sugar content detection system under different lighting environments provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0012] In order to enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the embodiments described are part of the embodiments of the present invention, rather than all of the embodiments. It should be understood that these descriptions are merely exemplary and are not intended to limit the scope of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work should fall within the scope of protection of the present invention.

[0013] The following describes in detail the method for detecting the sugar content of fruit under different lighting environments provided by the embodiment of the present invention through specific embodiments and application scenarios in conjunction with the accompanying drawings.

[0014] Reference Manual Figure 1 , which shows a flow chart of a method for detecting the sugar content of fruit under different lighting environments provided by an embodiment of the present invention.

[0015] The embodiment of the present invention provides a method for detecting the sugar content of fruit under different lighting environments, which may include the following steps: S1: Acquire multiple fruit images of fruit samples under different lighting environments and multiple fruit hyperspectral images under multiple halogen lamp light sources, wherein each fruit hyperspectral image corresponds one-to-one to a fruit image taken at the same shooting angle.

[0016] Reference Manual Figure 2 , which shows a structural diagram of a lighting control platform provided by an embodiment of the present invention.

[0017] In a possible implementation, S1 specifically includes sub-steps S101 to S103: S101: Adjust the duty cycle through the lighting control platform to control the target color temperature and create different lighting environments: ; in, D c Indicates the duty cycle of the cold light source, T c Indicates the color temperature of the cold light source at rated current, T t represents the target color temperature, L cmax Indicates the brightness of the cold light source at rated current, T w Indicates the color temperature of the warm light source at rated current. L wmax Indicates the brightness of the warm light source at rated current. D w Indicates the duty cycle of the warm light source.

[0018] Reference Manual Figure 3 , shows a structural schematic diagram of a key control module provided by an embodiment of the present invention.

[0019] Reference Manual Figure 4 , shows a structural schematic diagram of an LED lamp group module provided by an embodiment of the present invention.

[0020] Among them, the lighting control platform includes: a control signal output module, an OLED display module, a button control module, a left LED light group module, a right LED light group module, a left drive circuit module, and a right drive circuit module.

[0021] Reference Manual Figure 5 , showing a structural schematic diagram of a mobile loading gripper provided by an embodiment of the present invention.

[0022] Furthermore, the lighting control platform also includes: a loading platform, wherein a movable loading gripper is provided above the loading platform.

[0023] To achieve controllable ambient light output, an STM32F103C8T6 chip is used as the control signal output module, outputting four PWM signals. A key control module connected to pins GPIO_B11 through GPIO_B15 allows switching between five different ambient light modes, precisely adjusting the duty cycle of warm and cool light sources to achieve the target color temperature. A driver circuit module receives the PWM signals and drives the left and right LED clusters to produce different combinations of light intensity and color temperature. The LED clusters are symmetrically arranged on either side of the device, arranged in a circular pattern along a 12cm diameter circle. They alternate between 2700K (warm white) and 6500K (cool white) SMD LEDs, creating an adjustable mixed light output. This allows for flexible color temperature adjustment between 2700K and 6500K, adapting to most shooting scenarios. Each LED has a minimum forward voltage of +9V. Combined with a PT4115 chip-based step-down constant current driver circuit (with an 18V DC input), it can drive one to seven high-power LEDs in series, achieving continuous light intensity adjustment. To prevent glare or image overexposure caused by direct light from the lamps, frosted glass is placed 5 cm from the light's direction of divergence to diffuse the light, improving image uniformity and quality. The light control platform incorporates a loading platform. A mobile loading handle moves the fruit sample along a chute, ensuring it remains centered in the field of view and consistent shooting angles, creating diverse lighting environments. An OLED display displays the current lighting mode in real time, preventing image capture under inappropriate lighting conditions. A chute connects the loading platform of the light control platform to the loading platform of the hyperspectral instrument.

[0024] S102: Acquire multiple images of fruit samples under different lighting environments through a smart device.

[0025] Optionally, the smart device includes: a smart phone.

[0026] S103: Acquire multiple hyperspectral images of the fruit sample under multiple halogen lamp light sources using a hyperspectral device.

[0027] It should be noted that a loading platform is also arranged in the hyperspectral equipment box.

[0028] For example, both the lighting control platform and the hyperspectral device are equipped with a loading platform to ensure that the fruit sample is accurately placed in the center during each shot. The lighting control platform can precisely adjust the duty cycle of the cold and warm light sources, thereby achieving precise control of the target color temperature (2700K to 6500K) and light intensity (50lx to 350lx), creating an adjustable lighting environment. At the same time, the loading gripper can move between multiple shooting positions between the lighting control platform and the hyperspectral device to simulate different shooting angles and ensure that the angle is consistent during each shot, avoiding image deviation due to angle changes. Ultimately, the smart device captures multiple fruit images, and the hyperspectral device obtains corresponding hyperspectral images at the same shooting angle, ensuring that each hyperspectral image perfectly matches the corresponding fruit image.

[0029] In this embodiment of the present invention, a lighting control platform adjusts the duty cycle of warm and cold light sources to achieve precise control of the target color temperature and create a variety of controllable lighting environments. Combined with a structural design featuring a mobile loading gripper, this ensures that fruit samples are always photographed at the same angle and position under different lighting conditions, thereby ensuring image consistency and contrast. This implementation effectively simulates a variety of everyday lighting scenarios, improving the stability and repeatability of the image acquisition process, avoiding image distortion and measurement errors caused by ambient light variations or angle deviations, and facilitating the accuracy and reliability of subsequent fruit image processing and sugar content detection.

[0030] S2: Based on the preset wavelength, each fruit hyperspectral image is filtered to obtain multiple filtered images, and each filtered image is recombined into an RGB image.

[0031] Optionally, the preset wavelength includes: a preset red light wavelength, a preset green light wavelength, and a preset blue light wavelength.

[0032] It should be noted that those skilled in the art can set the sizes of the preset red light wavelength, the preset green light wavelength and the preset blue light wavelength according to actual needs, and the present invention does not limit this.

[0033] In a possible implementation, S2 specifically includes sub-steps S201 to S204: S201: Screening out a fruit hyperspectral image with a preset red light wavelength as a first screening image.

[0034] S202: Filter out a fruit hyperspectral image with a preset green light wavelength as a second filtered image.

[0035] S203: Filter out a fruit hyperspectral image with a preset blue light wavelength as a third filtered image.

[0036] S204: Recombining the first filtered image, the second filtered image, and the third filtered image into an RGB image.

[0037] In an embodiment of the present invention, by screening images corresponding to preset red, green, and blue wavelengths from hyperspectral images and recombining them into RGB images, not only is a high-fidelity visual reference image with physical spectral consistency constructed, but the dimensionality of the high-dimensional hyperspectral data is also effectively compressed, making it more suitable for structural alignment and model training with ordinary RGB images. This RGB image can be used as a supervisory label in the training of the ambient light compensation model, significantly improving the compensation accuracy and generalization ability of the model under complex lighting conditions. At the same time, this step supports custom wavelength configuration, has good adaptability and scalability, and is suitable for different devices and application scenarios, further enhancing the practicality and robustness of the system.

[0038] S3: Use the RGB image as the fruit target image, match each fruit image with the fruit target image, and build a fruit image dataset.

[0039] In an embodiment of the present invention, images corresponding to preset red, green, and blue wavelengths in a hyperspectral image are filtered and reassembled into an RGB image, which serves as a standard illumination reference image. Fruit images captured by smart devices under different lighting environments are then matched one-to-one with the RGB image to construct a paired image dataset, thereby achieving highly consistent pairing of image input and target output. This dataset not only provides high-quality supervised training samples for the ambient light compensation model, significantly improving the model's generalization ability and compensation accuracy under multiple lighting conditions, but also avoids the problems of pseudo-labeling and image structure misalignment, ensuring the authenticity and effectiveness of the training data, and facilitating the construction of a sugar content detection model with strong illumination robustness and high deployment flexibility.

[0040] Reference Manual Figure 6 , shows a structural schematic diagram of an ambient light compensation algorithm model based on the DenseNet algorithm provided in an embodiment of the present invention.

[0041] S4: Use the fruit image dataset as training data to train the ambient light compensation algorithm model based on the DenseNet algorithm.

[0042] It should be noted that DenseNet (Dense Convolutional Network) is a densely connected convolutional neural network architecture. Its core concept is that any layer in the network is directly connected to all previous layers. That is, each layer receives feature maps from all previous layers as input and passes its output to all subsequent layers. This structure effectively enables feature reuse, mitigates gradient vanishing, improves model efficiency, and reduces the number of parameters. DenseNet is particularly suitable for image processing tasks such as classification, image enhancement, and feature compensation because it can capture richer and more detailed multi-level information.

[0043] In this embodiment of the present invention, by training an ambient light compensation model based on the DenseNet architecture and utilizing deep feature reuse and gradient flow optimization, the image compensation accuracy and computational efficiency are improved, effectively achieving accurate compensation of fruit images under different lighting conditions, and providing high-quality input data for subsequent sugar content prediction.

[0044] The ambient light compensation algorithm model includes: a Stem module, multiple DenseBlock modules, multiple Transition modules, multiple Decoder modules and a Color mapping module.

[0045] It should be noted that the Stem module is the entrance of the network and is responsible for performing preliminary feature extraction on the original image, which usually includes convolution, normalization and pooling operations, which are used to quickly reduce the image size and extract low-level features. The DenseBlock module is the core of the DenseNet architecture. By splicing the output of each layer with the output of all previous layers, it realizes efficient transmission and reuse of features and enhances the expressive power of the network. The Transition module is usually used between two DenseBlocks and includes convolution and pooling operations. Its main function is to compress the feature map size and number of channels and control the complexity of the model. The Decoder module is used to restore the spatial resolution of the image. Combined with upsampling and jump connections, the features extracted in the encoding stage are gradually restored to a high-resolution image. The Color Mapping module focuses on the fine-tuning of color features. It performs color mapping or illumination compensation on the image through convolution and nonlinear transformation to achieve visual consistency and color correction.

[0046] It should be noted that k represents the size of the convolution kernel, s Indicates the stride of the convolution operation.

[0047] Optionally, the Stem module consists of a 7×7 convolutional layer, a BN+ReLU activation layer, and a MaxPool maximum pooling layer.

[0048] Optionally, the DenseBlock module consists of a first DenseLayer layer (Denselayer1), a second DenseLayer layer (Denselayer2), a third DenseLayer layer (Denselayer3) and a fourth DenseLayer layer (Denselayer4), the inputs of the fourth DenseLayer layer are the outputs of the first DenseLayer layer, the second DenseLayer layer and the third DenseLayer layer, the inputs of the third DenseLayer layer are the outputs of the first DenseLayer layer and the second DenseLayer layer, and the input of the second DenseLayer layer is the output of the first DenseLayer layer.

[0049] Optionally, the Transition module consists of a BN+ReLU activation layer, a 3×3 convolutional layer, and an Avgpool average pooling layer.

[0050] Optionally, the Decoder module consists of a 4×4 Transconv convolutional layer, a 1×1 convolutional layer, two BN+ReLU activation layers, and a 3×3 convolutional layer.

[0051] Optionally, the color mapping module consists of two 3×3 convolutional layers, two ReLU activation layers, three 1×1 convolutional layers, and a Sigmoid activation layer.

[0052] The DenseBlock module includes: a first DenseBlock module (Denseblock1), a second DenseBlock module (Denseblock2) and a third DenseBlock module (Denseblock3).

[0053] The Transition module includes: a first Transition module (Transition1) and a second Transition module (Transition2), wherein the first Transition module is arranged between the first DenseBlock module and the second DenseBlock module, and the second Transition module is arranged between the second DenseBlock module and the third DenseBlock module.

[0054] The decoder modules include: a first decoder module (Decoder1), a second decoder module (Decoder2), a third decoder module (Decoder3), a fourth decoder module (Decoder4), and a fifth decoder module (Decoder5).

[0055] In this embodiment of the present invention, by leveraging the various modules of the DenseNet architecture—particularly the efficient feature extraction of the Stem module, the feature reuse of the DenseBlock module, the complexity control of the Transition module, the high-resolution restoration of the Decoder module, and the color compensation of the Color Mapping module—the model effectively improves the accuracy and robustness of image compensation. Each module is designed to optimize feature flow, enhance gradient transfer, reduce computational complexity, and maintain the integrity and consistency of image structure, ultimately providing high-quality input for fruit sugar content prediction.

[0056] S5: Acquire a real-time fruit image of the fruit to be detected.

[0057] S6: Input the real-time fruit image into the trained ambient light compensation algorithm model to perform ambient light compensation, and output a fruit compensated image with the same color temperature as the fruit target image.

[0058] In an embodiment of the present invention, by inputting real-time fruit images into a trained ambient light compensation model for compensation, the interference caused by ambient light changes is eliminated, ensuring that the compensated image has the same color temperature as the target image, thereby providing an accurate, unified, and stable input image for subsequent sugar content prediction, significantly improving the detection accuracy and real-time performance of the system.

[0059] In a possible implementation, S6 specifically includes sub-steps S601 to S604: S601: Combine the Stem module and each DenseBlock module to extract features of the real-time fruit image and obtain multiple local feature maps.

[0060] S602: Performing a pooling operation on each local feature map through each Transition module to obtain multiple pooled feature maps.

[0061] S603: Through each Decoder module, feature fusion is performed on each local feature map and each pooled feature map, and a decoding operation is performed on the feature fusion result to obtain multiple decoded feature maps.

[0062] S604: Through the color mapping module, a dual-path residual fusion is performed on the real-time fruit image and the decoded feature map to output a fruit compensation image with the same color temperature as the fruit target image.

[0063] Specifically, in the Stem module, feature extraction is performed on the real-time fruit image to obtain a first local feature map. In the first DenseBlock module, feature extraction is performed on the first local feature map to obtain a second local feature map. In the first Transition module, a pooling operation is performed on the second local feature map to obtain a first pooled feature map. In the second DenseBlock module, feature extraction is performed on the first pooled feature map to obtain a third local feature map. In the second Transition module, a pooling operation is performed on the third local feature map to obtain a second pooled feature map. In the third DenseBlock module, feature extraction is performed on the second pooled feature map to obtain a fourth local feature map. In the first Decoder module, feature fusion is performed on the second pooled feature map and the fourth local feature map to obtain a first fused feature map, and a decoding operation is performed on the first fused feature map to obtain a first decoded feature map. In the second Decoder module, feature fusion is performed on the third local feature map and the first decoded feature map to obtain a second fused feature map, and a decoding operation is performed on the second fused feature map to obtain a second decoded feature map. In the third Decoder module, the first pooled feature map and the second decoded feature map are feature fused to obtain a third fused feature map, and the third fused feature map is decoded to obtain a third decoded feature map. In the fourth Decoder module, the second local feature map and the third decoded feature map are feature fused to obtain a fourth fused feature map, and the fourth fused feature map is decoded to obtain a fourth decoded feature map. In the fifth Decoder module, the first local feature map and the fourth decoded feature map are feature fused to obtain a fifth fused feature map, and the fifth fused feature map is decoded to obtain a fifth decoded feature map. In the Color Mapping module, a dual-path residual fusion is performed on the real-time fruit image and the fifth decoded feature map to output a fruit compensation image with the same color temperature as the fruit target image.

[0064] In this embodiment, by combining the multi-module processing of the DenseNet architecture, from feature extraction to upsampling and color correction, ambient light compensation is gradually performed on real-time fruit images. Through multi-level feature learning, pooling compression, feature fusion, upsampling recovery, and color mapping correction, the compensated image is consistent with the standard target image in color temperature and detail, greatly improving the accuracy of image compensation, detail restoration, and color consistency, providing a precise input image for subsequent fruit sugar content detection.

[0065] Reference Manual Figure 7 , shows a structural schematic diagram of a spectral image reconstruction algorithm model provided by an embodiment of the present invention.

[0066] S7: Input the fruit compensation image into the spectral image reconstruction algorithm model for reconstruction, and output the fruit reconstructed image.

[0067] In an embodiment of the present invention, by inputting the compensated fruit image into the spectral image reconstruction algorithm model, the multi-band information of the hyperspectral image is restored, thereby providing richer spectral feature data for sugar content prediction, improving the accuracy of image processing and the reliability of data, providing high-quality input for subsequent models, and enhancing the applicability and generalization ability of the system.

[0068] Among them, the spectral image reconstruction algorithm model includes: DoubleConv module, multiple downsampling ERB modules, multiple upsampling DAB modules, inter-stage SAM connection module and OutConv module.

[0069] It should be noted that the DoubleConv module is used to extract local texture and multi-scale features and is a common building block in encoders and decoders. The downsampling ERB module (Enhanced Residual Block) extracts deep features through residual connections and convolution operations, while also using pooling to reduce image resolution, enhancing the network's representational capabilities and maintaining gradient flow. The upsampling DAB module (Dual Attention Block) combines the SE (Channel Attention) module and the SCAM (Spatial Attention) module to perform scale restoration through transposed convolutions, enhancing the response of important features for high-precision image reconstruction. The inter-stage SAM connection module (Spatial Attention Module), located between two sub-network stages, uses a spatial attention mechanism to guide information flow to key areas, improving the effectiveness of cross-stage feature interactions. The OutConv module is the output layer structure, typically composed of 1×1 convolutions, used to map high-dimensional features to an output image of the target dimension, such as a fruit reconstruction image.

[0070] Optionally, the downsampling ERB module consists of four 3×3 convolutional layers, two BN+ReLU activation layers, one ReLU activation layer, and one MaxPool layer.

[0071] Optionally, the upsampling DAB module consists of two 1×1 convolutional layers, an SE module, an AgvPool average pooling layer, a ReLU activation layer, a SCAM module, a 2×2 Transconv convolutional layer, and a DoubleConv convolutional layer.

[0072] Optionally, the SE module consists of an AgvPool average pooling layer, two Linear fully connected layers, and two ReLU activation layers.

[0073] The SE module models the channel dimension of the feature map through a "compression-excitation" mechanism. It first performs global average pooling on each channel, then learns the importance weight of each channel through a fully connected layer, and finally reweights the original feature map, making the network pay more attention to key channel features.

[0074] Optionally, the SCAM module consists of a 1×1 convolutional layer, two Sigmod activation layers, and a 7×7 convolutional layer.

[0075] It's important to note that the SCAM module combines spatial and channel attention to highlight key image regions while enhancing the representation of information in important channels. It typically first uses the channel attention mechanism to filter high-weight features, then uses the spatial attention mechanism to locate important image regions. This achieves joint optimization of spatial and channel attention, improving the model's ability to represent complex features.

[0076] Optionally, the inter-stage SAM connection module consists of two 3×3 convolutional layers, one 1×1 convolutional layer, and one Sigmod activation layer.

[0077] The downsampling ERB modules include: a first downsampling ERB module (ERB 1_1), a second downsampling ERB module (ERB 2_1), a third downsampling ERB module (ERB 3_1), a fourth downsampling ERB module (ERB 4_1), a fifth downsampling ERB module (ERB 1_2), a sixth downsampling ERB module (ERB 2_2), a seventh downsampling ERB module (ERB 3_2), and an eighth downsampling ERB module (ERB 4_2).

[0078] The upsampling DAB module includes: a first upsampling DAB module (DAB 1_1), a second upsampling DAB module (DAB 2_1), a third upsampling DAB module (DAB 3_1), a fourth upsampling DAB module (DAB 4_1), a fifth upsampling DAB module (DAB 1_2), a sixth upsampling DAB module (DAB 2_2), a seventh upsampling DAB module (DAB 3_2) and an eighth upsampling DAB module (DAB 4_2).

[0079] In this embodiment of the present invention, an efficient and accurate image reconstruction framework is constructed by combining DoubleConv, downsampling ERB, upsampling DAB, an inter-stage SAM connection module, and an OutConv module. This framework can recover high-resolution hyperspectral images from compensated fruit images, capturing more detailed information and providing high-quality input data for subsequent sugar content prediction. The collaboration of each module improves the accuracy of image reconstruction and detail preservation, making the final output image closer to reality, significantly enhancing the accuracy of sugar content prediction and the robustness of the system.

[0080] In a possible implementation, S7 specifically includes sub-steps S701 to S707: S701: Perform multi-scale feature extraction on the fruit compensation image through the DoubleConv module to obtain a multi-scale feature map.

[0081] S702: Perform a downsampling operation on the multi-scale feature map through each downsampling ERB module to obtain multiple down-sampled feature maps.

[0082] S703: Perform an upsampling operation on each of the first down-sampled feature maps through each upsampling DAB module, and concatenate the upsampling operation result with each of the first down-sampled feature maps to obtain multiple first up-sampled feature maps.

[0083] S704: Through the inter-stage SAM connection module, spatial attention interaction is performed on the multi-scale feature map and the once up-sampled feature map to obtain an enhanced feature map.

[0084] S705: Perform a secondary downsampling operation on the enhanced feature map through each downsampling ERB module to obtain multiple secondary downsampling feature maps.

[0085] S706: Perform a secondary upsampling operation on each secondary downsampling feature map through each upsampling DAB module, and concatenate the secondary upsampling operation result with each secondary downsampling feature map to obtain multiple secondary upsampling feature maps.

[0086] S707: Perform a convolution operation on the secondary upsampled feature map through the OutConv module to output a fruit reconstructed image.

[0087] Specifically, in the DoubleConv module, multi-scale feature extraction is performed on the fruit compensated image to obtain a multi-scale feature map. In the first downsampling ERB module, a downsampling operation is performed on the multi-scale feature map to obtain a first downsampling feature map. In the second downsampling ERB module, a downsampling operation is performed on the first downsampling feature map to obtain a second downsampling feature map. In the third downsampling ERB module, a downsampling operation is performed on the second downsampling feature map to obtain a third downsampling feature map. In the fourth downsampling ERB module, a downsampling operation is performed on the third downsampling feature map to obtain a fourth downsampling feature map. In the fourth upsampling DAB module, an upsampling operation is performed on the fourth downsampling feature map to obtain a first upsampling feature map. In the third upsampling DAB module, upsampling operations are performed on the third downsampling feature map and the first upsampling feature map, respectively, and the upsampling third downsampling feature map and the first upsampling feature map are concatenated to obtain a second upsampling feature map. In the second upsampling DAB module, the second downsampled feature map and the second upsampled feature map are upsampled, respectively, and the upsampled second downsampled feature map and the upsampled second upsampled feature map are concatenated to obtain a third upsampled feature map. In the first upsampling DAB module, the first downsampled feature map and the third upsampled feature map are upsampled, respectively, and the upsampled first downsampled feature map and the third upsampled feature map are concatenated to obtain a fourth upsampled feature map. In the inter-stage SAM connection module, spatial attention interaction is performed on the multi-scale feature map and the fourth upsampled feature map to obtain an enhanced feature map. In the fifth downsampling ERB module, the enhanced feature map is downsampled to obtain a fifth downsampled feature map. In the sixth downsampling ERB module, the fifth downsampled feature map is downsampled to obtain a sixth downsampled feature map. In the seventh downsampling ERB module, the sixth downsampled feature map is downsampled to obtain a seventh downsampled feature map. In the eighth downsampling ERB module, the seventh downsampled feature map is downsampled to obtain an eighth downsampled feature map. In the eighth upsampling DAB module, an upsampling operation is performed on the eighth downsampling feature map to obtain a fifth upsampling feature map. In the seventh upsampling DAB module, an upsampling operation is performed on the seventh downsampling feature map and the fifth upsampling feature map respectively, and the seventh downsampling feature map and the fifth upsampling feature map after the upsampling operation are spliced ​​to obtain a sixth upsampling feature map. In the sixth upsampling DAB module, an upsampling operation is performed on the sixth downsampling feature map and the sixth upsampling feature map respectively, and the sixth downsampling feature map and the sixth upsampling feature map after the upsampling operation are spliced ​​to obtain a seventh upsampling feature map. In the fifth upsampling DAB module, an upsampling operation is performed on the fifth downsampling feature map and the seventh upsampling feature map respectively, and the fifth downsampling feature map and the seventh upsampling feature map after the upsampling operation are spliced ​​to obtain an eighth upsampling feature map.In the OutConv module, a convolution operation is performed on the eighth upsampled feature map to output the fruit reconstructed image.

[0088] In this embodiment of the present invention, the DoubleConv, downsampling ERB, upsampling DAB, SAM connection modules, and OutConv modules work together to gradually restore high-resolution features of fruit images. The attention mechanism enhances the extraction of important information, ultimately outputting a high-quality reconstructed image. This process effectively improves image reconstruction accuracy and detail preservation, providing high-quality input data for subsequent sugar content prediction.

[0089] S8: Input the reconstructed fruit image into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, and output the sugar content of the fruit to be detected.

[0090] It should be noted that Partial Least Squares Regression (PLSR) is a statistical learning method that combines feature dimensionality reduction with regression modeling. It is particularly suitable for high-dimensional, strongly correlated, or small-sample problems. PLSR simultaneously projects the input and output variables into a new latent space, extracting a set of latent factors that explain the maximum correlation between the input features and the output response, and then performs regression analysis based on this. Compared to traditional least squares regression, PLSR not only effectively handles multicollinearity but also improves the model's robustness and generalization capabilities. Therefore, it is widely used in tasks such as hyperspectral analysis, chemometrics, and fruit sugar content prediction.

[0091] In a possible implementation, S8 specifically includes: According to the following formula, the sugar content of the fruit to be tested is output: ; in, Y Indicates the sugar content of the fruit to be tested. Q represents the regression coefficient, X represents the fruit reconstructed image, T represents the transpose operation, F Residual is the difference between the predicted result and the actual result of the fruit sugar content. q N Indicates the first N The regression coefficient corresponding to each band is N =1,2,3,…, n , n Indicates the total number of bands, x N Indicates the first N Hyperspectral data of multiple bands.

[0092] In an embodiment of the present invention, by adopting the partial least squares regression algorithm (PLSR), the relationship between the reconstructed image of the fruit and the sugar content is modeled, which can effectively extract key information from high-dimensional spectral data, improve the accuracy, robustness and generalization ability of sugar content prediction, and provide an efficient and reliable prediction model for fruit sugar content detection in practical applications.

[0093] The beneficial effects brought about by the technical solution provided by the embodiment of the present invention include at least: In an embodiment of the present invention, a real-time fruit image is input into a trained ambient light compensation algorithm model for ambient light compensation, and a fruit compensation image having the same color temperature as the fruit target image is output. This makes it less susceptible to interference from ambient light when the smart device takes images under different ambient lights, thereby ensuring the stability of the sugar content prediction result. The fruit compensation image is input into a spectral image reconstruction algorithm model for reconstruction, and a fruit reconstructed image is output. The fruit reconstructed image is then input into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, and the fruit sugar content of the fruit to be detected is output. This no longer relies on physical and chemical detection technology, does not require expensive equipment, is easy to operate, is not easily affected by environmental conditions, and has a fast detection speed.

[0094] Reference Manual Figure 8 , shows a structural schematic diagram of a fruit sugar content detection system under different lighting environments provided by an embodiment of the present invention.

[0095] The embodiment of the present invention provides a fruit sugar content detection system 20 under different lighting environments, comprising: a processor 201 and a memory 202; The memory 202 stores programs or instructions that can be run on the processor 201. When the programs or instructions are executed by the processor 201, the steps of the above-mentioned method for detecting the sugar content of fruits under different lighting environments are implemented, and the same technical effect can be achieved. To avoid repetition, the present invention will not be described in detail.

[0096] It should be understood that the processor 201 in the embodiment of the present invention may be a central processing unit (CPU), or may be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0097] It should also be understood that the memory 202 in the embodiments of the present invention may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. The non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic random access memory (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDR SDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct rambus RAM (DR RAM).

[0098] The above embodiments can be implemented in whole or in part via software, hardware (e.g., circuits), firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented in whole or in part in the form of a computer program product. The computer program product comprises one or more computer instructions or computer programs. When loaded or executed on a computer, the processes or functions described in accordance with the embodiments of the present invention are fully or partially performed. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired means (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium accessible by a computer or a data storage device such as a server or data center that contains a collection of one or more available media. The available medium can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media. The semiconductor media can be a solid-state drive.

[0099] It should be understood that in various embodiments of the present invention, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.

[0100] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0101] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described equipment, devices and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0102] In the several embodiments provided by the present invention, it should be understood that the disclosed devices, apparatuses and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interface, indirect coupling or communication connection of the device or unit, which can be electrical, mechanical or other forms.

[0103] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0104] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0105] If the functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the portion that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, mobile hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.

[0106] An embodiment of the present invention provides a readable storage medium including: a program or instruction stored on the readable storage medium, wherein the program or instruction, when executed by a processor, implements the steps of the above-mentioned method for detecting the sugar content of fruit under different lighting environments, and can achieve the same technical effect. To avoid repetition, the present invention will not be described in detail.

[0107] Finally, it should be noted that the above embodiments are merely illustrative of the technical solutions of the embodiments of the present invention, and are not intended to limit them. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they may still modify the technical solutions described in the aforementioned embodiments, or replace some of the technical features therein with equivalents; and such modifications or replacements do not deviate from the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or replacements that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be covered by the scope of protection of the present invention.

Claims

1. A method for detecting the sugar content of fruit under different lighting environments, characterized in that: include: S1: Acquire multiple fruit images of a fruit sample under different lighting environments and multiple fruit hyperspectral images under multiple halogen lamp light sources, wherein each of the fruit hyperspectral images corresponds one-to-one to a fruit image taken at the same shooting angle; S2: Based on a preset wavelength, each of the fruit hyperspectral images is screened to obtain a plurality of screened images, and each of the screened images is recombined into an RGB image; S3: using the RGB image as a fruit target image, matching each of the fruit images with the fruit target image to construct a fruit image dataset; S4: Using the fruit image dataset as training data, training an ambient light compensation algorithm model based on the DenseNet algorithm; S5: Acquire a real-time image of the fruit to be detected; S6: Inputting the real-time fruit image into the trained ambient light compensation algorithm model to perform ambient light compensation, and outputting a fruit compensated image with the same color temperature as the fruit target image; S7: inputting the fruit compensation image into a spectral image reconstruction algorithm model for reconstruction, and outputting a fruit reconstructed image; S8: Inputting the reconstructed fruit image into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, and outputting the fruit sugar content of the fruit to be detected.

2. The method for detecting the sugar content of fruits under different lighting environments according to claim 1, wherein: Said S1 specifically includes: S101: Adjust the duty cycle through the lighting control platform to control the target color temperature and create different lighting environments: ; in, D c Indicates the duty cycle of the cold light source, T c Indicates the color temperature of the cold light source at rated current, T t represents the target color temperature, L cmax Indicates the brightness of the cold light source at rated current, T w Indicates the color temperature of the warm light source at rated current. L wmax Indicates the brightness of the warm light source at rated current. D w Indicates the duty cycle of warm light source; S102: Acquire, through a smart device, a plurality of images of the fruit sample under different lighting environments; S103: Acquire, by means of a hyperspectral device, a plurality of hyperspectral images of the fruit sample under a plurality of halogen lamp light sources.

3. The method for detecting the sugar content of fruits under different lighting environments according to claim 2, wherein: The lighting control platform includes: a control signal output module, an OLED display module, a button control module, a left LED light group module, a right LED light group module, a left drive circuit module, and a right drive circuit module.

4. The method for detecting the sugar content of fruits under different lighting environments according to claim 1, wherein: The preset wavelengths include: a preset red light wavelength, a preset green light wavelength, and a preset blue light wavelength; The S2 specifically includes: S201: Screening out a fruit hyperspectral image having the preset red light wavelength as a first screening image; S202: Screening out a fruit hyperspectral image having the preset green light wavelength as a second screening image; S203: Filtering out a fruit hyperspectral image having the preset blue light wavelength as a third screening image; S204: Recombining the first filtered image, the second filtered image, and the third filtered image into the RGB image.

5. The method for detecting the sugar content of fruits under different lighting environments according to claim 1, wherein: The ambient light compensation algorithm model includes: a Stem module, multiple DenseBlock modules, multiple Transition modules, multiple Decoder modules and a Color mapping module; The DenseBlock module includes: a first DenseBlock module, a second DenseBlock module and a third DenseBlock module; The Transition module includes: a first Transition module and a second Transition module, wherein the first Transition module is arranged between the first DenseBlock module and the second DenseBlock module, and the second Transition module is arranged between the second DenseBlock module and the third DenseBlock module; The decoder module includes: a first decoder module, a second decoder module, a third decoder module, a fourth decoder module and a fifth decoder module.

6. The method for detecting the sugar content of fruits under different lighting environments according to claim 5, characterized in that: The S6 specifically includes: S601: Combining the Stem module and each of the DenseBlock modules, performing feature extraction on the real-time fruit image to obtain multiple local feature maps; S602: performing a pooling operation on each of the local feature maps through each of the Transition modules to obtain multiple pooled feature maps; S603: performing feature fusion on each of the local feature maps and each of the pooled feature maps through each of the decoder modules, and performing a decoding operation on the feature fusion results to obtain multiple decoded feature maps; S604: Performing dual-path residual fusion on the real-time fruit image and the decoded feature map through the Color mapping module to output the fruit compensation image having the same color temperature as the fruit target image.

7. The method for detecting the sugar content of fruits under different lighting environments according to claim 1, wherein: The spectral image reconstruction algorithm model includes: a DoubleConv module, multiple downsampling ERB modules, multiple upsampling DAB modules, an inter-stage SAM connection module and an OutConv module; The downsampling ERB module includes: a first downsampling ERB module, a second downsampling ERB module, a third downsampling ERB module, a fourth downsampling ERB module, a fifth downsampling ERB module, a sixth downsampling ERB module, a seventh downsampling ERB module and an eighth downsampling ERB module; The upsampling DAB module includes: a first upsampling DAB module, a second upsampling DAB module, a third upsampling DAB module, a fourth upsampling DAB module, a fifth upsampling DAB module, a sixth upsampling DAB module, a seventh upsampling DAB module and an eighth upsampling DAB module.

8. The method for detecting the sugar content of fruits under different lighting environments according to claim 7, characterized in that: The S7 specifically includes: S701: performing multi-scale feature extraction on the fruit compensation image through the DoubleConv module to obtain a multi-scale feature map; S702: Perform a downsampling operation on the multi-scale feature map through each of the downsampling ERB modules to obtain multiple down-sampled feature maps; S703: performing an upsampling operation on each of the first down-sampled feature maps through each of the upsampling DAB modules, and concatenating the upsampling operation result with each of the first down-sampled feature maps to obtain multiple first up-sampled feature maps; S704: Performing spatial attention interaction on the multi-scale feature map and the once upsampled feature map through the inter-stage SAM connection module to obtain an enhanced feature map; S705: Performing a secondary downsampling operation on the enhanced feature map through each of the downsampling ERB modules to obtain multiple secondary downsampling feature maps; S706: performing a secondary upsampling operation on each of the secondary downsampling feature maps through each of the upsampling DAB modules, and concatenating the secondary upsampling operation results with each of the secondary downsampling feature maps to obtain multiple secondary upsampling feature maps; S707: Perform a convolution operation on the secondary up-sampled feature map through the OutConv module to output the fruit reconstructed image.

9. The method for detecting the sugar content of fruits under different lighting environments according to claim 1, wherein: The S8 is specifically: According to the following formula, the sugar content of the fruit to be tested is output: ; in, Y Indicates the sugar content of the fruit to be tested. Q represents the regression coefficient, X represents the fruit reconstructed image, T represents the transpose operation, F Residual is the difference between the predicted result and the actual result of the fruit sugar content. q N Indicates the first N The regression coefficient corresponding to each band is N =1,2,3,…, n , n Indicates the total number of bands, x N Indicates the first N Hyperspectral data of multiple bands.

10. A fruit sugar content detection system under different lighting environments, characterized in that: include: processor and memory; The memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the method for detecting the sugar content of fruits under different lighting environments as described in any one of claims 1 to 9 are implemented.

Citation Information

Patent Citations

  • Fruit sugar degree nondestructive testing method based on spectral reflectivity reconstruction technology

    CN115015180A

  • Non-destructive measuring device for sugar content in fruits and vegetables

    JP3049026U