A method and system for detecting fruit sugar content under different lighting environments
By using the DenseNet algorithm for ambient light compensation and spectral image reconstruction, combined with the partial least squares regression algorithm, the problems of high cost and ambient light interference in traditional fruit sugar content detection equipment are solved, enabling rapid and accurate fruit sugar content detection.
Patent Information
- Application Number
- CN202511130287.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-13
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2045-08-13
AI Technical Summary
Traditional methods for detecting the sugar content of fruits rely on expensive equipment and are cumbersome to operate. They are also easily affected by ambient light, resulting in slow detection speeds and unstable results.
An ambient light compensation model based on the DenseNet algorithm and a spectral image reconstruction algorithm, combined with a partial least squares regression algorithm, is used to acquire and process fruit images under different lighting conditions, perform ambient light compensation and image reconstruction, and output the fruit sugar content.
It enables rapid and accurate detection of fruit sugar content under different lighting conditions, avoiding reliance on expensive equipment and interference from ambient light, and provides fast detection speed and stable results.
Smart Images

Figure CN120629153B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of fruit sugar content detection technology, and in particular to a method and system for detecting fruit sugar content under different lighting conditions. Background Technology
[0002] With the continuous advancement of technology, fruit sugar content testing technology is becoming increasingly important in food quality control and agricultural production. Sugar content, as a key quality indicator of fruit, directly impacts consumers' purchasing decisions. Therefore, rapid and accurate detection of fruit sugar content has become an indispensable part of post-harvest processing and grading.
[0003] Traditional methods for detecting the sugar content of fruits typically rely on physicochemical detection techniques, such as refractometers and hyperspectral imaging. These methods require expensive equipment, are cumbersome to operate, and are easily affected by environmental conditions, resulting in slow detection speeds.
[0004] In addition, when smart devices capture images under different ambient light conditions, the results are often easily affected by the ambient light, leading to instability in the sugar content prediction results. Summary of the Invention
[0005] In view of the shortcomings of the prior art, the purpose of this invention is to provide a method for detecting the sugar content of fruit under different lighting conditions. This method can solve the technical problems that traditional fruit sugar content detection methods usually rely on physicochemical detection technology, require expensive equipment, are cumbersome to operate, are easily affected by environmental conditions, resulting in slow detection speed, and when smart devices take pictures under different ambient light, the results are often easily interfered with by the ambient light, resulting in unstable sugar content prediction results.
[0006] A first aspect of this invention provides a method for detecting the sugar content of fruit under different lighting conditions, comprising:
[0007] S1: Obtain multiple fruit images under different lighting conditions and multiple hyperspectral images of fruit under multiple halogen lamp sources. Each hyperspectral image of fruit corresponds one-to-one with a fruit image taken from the same shooting angle.
[0008] S2: Based on a preset wavelength, each fruit hyperspectral image is filtered to obtain multiple filtered images, and each filtered image is recombined into an RGB image;
[0009] S3: Using RGB images as the target images of fruits, match each fruit image with the target fruit image to construct a fruit image dataset;
[0010] S4: Using fruit image datasets as training data, train the ambient light compensation algorithm model based on the DenseNet algorithm;
[0011] S5: Acquire real-time fruit images of the fruit to be detected;
[0012] S6: Input the real-time fruit image into the trained ambient light compensation algorithm model to perform ambient light compensation, and output a fruit compensation image with the same color temperature as the target fruit image.
[0013] S7: Input the fruit compensation image into the spectral image reconstruction algorithm model for reconstruction, and output the fruit reconstruction image;
[0014] S8: Input the reconstructed fruit image into the fruit sugar content detection model based on the partial least squares regression algorithm for detection, and output the fruit sugar content of the fruit to be detected.
[0015] A second aspect of this invention provides a fruit sugar content detection system under different lighting conditions, comprising: a processor and a memory;
[0016] The memory stores programs or instructions that can run on the processor, which, when executed by the processor, implement the steps of the fruit sugar content detection method under different lighting conditions as described in the first aspect.
[0017] A third aspect of the present invention provides a readable storage medium storing a program or instructions that, when executed by a processor, implement the steps of the fruit sugar content detection method under different lighting conditions as described in the first aspect.
[0018] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following:
[0019] In this embodiment of the invention, real-time fruit images are input into a trained ambient light compensation algorithm model for ambient light compensation, outputting a fruit compensation image with the same color temperature as the target fruit image. This makes it less susceptible to interference from ambient light when the smart device captures images under different ambient light conditions, ensuring the stability of the sugar content prediction results. The fruit compensation image is then input into a spectral image reconstruction algorithm model for reconstruction, outputting a reconstructed fruit image. Finally, the reconstructed fruit image is input into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, outputting the fruit sugar content of the fruit to be detected. This method no longer relies on physicochemical detection techniques, does not require expensive equipment, is easy to operate, is not easily affected by environmental conditions, and has a fast detection speed. Attached Figure Description
[0020] The accompanying drawings are for illustrative purposes only and are not intended to limit the invention. Throughout the drawings, the same reference numerals denote the same parts. Obviously, the drawings described below are merely some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without any creative effort.
[0021] Figure 1 This is a flowchart illustrating a method for detecting the sugar content of fruit under different lighting conditions, provided in an embodiment of the present invention.
[0022] Figure 2 This is a schematic diagram of the structure of a lighting control platform provided in an embodiment of the present invention;
[0023] Figure 3 This is a schematic diagram of the structure of a button control module provided in an embodiment of the present invention;
[0024] Figure 4 This is a structural schematic diagram of an LED lamp module provided in an embodiment of the present invention;
[0025] Figure 5 This is a schematic diagram of the structure of a mobile cargo gripper provided in an embodiment of the present invention;
[0026] Figure 6 This is a schematic diagram of the structure of an ambient light compensation algorithm model based on the DenseNet algorithm provided in an embodiment of the present invention;
[0027] Figure 7 This is a schematic diagram of the structure of a spectral image reconstruction algorithm model provided in an embodiment of the present invention;
[0028] Figure 8 This is a schematic diagram of a fruit sugar content detection system under different lighting conditions provided in an embodiment of the present invention. Detailed Implementation
[0029] 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 described embodiments are only some embodiments of the present invention, not all 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 skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0030] The following description, in conjunction with the accompanying drawings, details the fruit sugar content detection method under different lighting conditions provided by the embodiments of the present invention through specific examples and application scenarios.
[0031] Reference manual attached Figure 1 The diagram shows a flowchart of a method for detecting the sugar content of fruit under different lighting conditions provided by an embodiment of the present invention.
[0032] This invention provides a method for detecting the sugar content of fruit under different lighting conditions, which may include the following steps:
[0033] S1: Obtain multiple fruit images under different lighting conditions and multiple hyperspectral images of fruit under multiple halogen lamp sources. Each hyperspectral image of fruit corresponds one-to-one with a fruit image taken from the same shooting angle.
[0034] Reference manual attached Figure 2 The diagram shows a schematic representation of a lighting control platform provided in an embodiment of the present invention.
[0035] In one possible implementation, S1 specifically includes sub-steps S101 to S103:
[0036] S101: Adjust the duty cycle via the lighting control platform to control the target color temperature and create different lighting environments.
[0037] ;
[0038] in, D c Indicates the duty cycle of the cold light source. T c This indicates the color temperature at the rated current of the cold light source. T t Indicates the target color temperature. L cmax This indicates the brightness of a cold light source at its rated current. T w This indicates the color temperature at the rated current of a warm light source. L wmax This indicates the brightness of a warm light source at its rated current. D w This indicates the duty cycle of the warm light source.
[0039] Reference manual attached Figure 3 The diagram shows a schematic of a button control module provided in an embodiment of the present invention.
[0040] Reference manual attached Figure 4 The diagram shows a structural schematic of an LED lamp module provided in an embodiment of the present invention.
[0041] The lighting control platform includes: a control signal output module, an OLED display module, a button control module, a left-side LED light group module, a right-side LED light group module, a left-side drive circuit module, and a right-side drive circuit module.
[0042] Reference manual attached Figure 5 The diagram shows a structural schematic of a mobile cargo gripper provided in an embodiment of the present invention.
[0043] Furthermore, the lighting control platform also includes a cargo platform, wherein a mobile cargo grabber is installed on top of the cargo platform.
[0044] Specifically, to achieve controllable ambient light output, an STM32F103C8T6 chip is used as the control signal output module, outputting four PWM signals. These signals are controlled by buttons connected to GPIO_B11 to GPIO_B15 pins, allowing switching between five different ambient light modes and precise adjustment of the duty cycle between warm and cool light sources to achieve target color temperature control. The driver circuit module receives the PWM signals and drives the left and right LED groups to output different combinations of light intensity and color temperature. The LED groups are symmetrically distributed on both sides of the device, arranged in a ring along a 12cm diameter circle. They use alternating layers of 2700K (warm white) and 6500K (cool white) surface-mount LEDs to form an adjustable mixed light output, supporting flexible color temperature adjustment within the range of 2700K to 6500K, adapting to most shooting scenarios. Each LED has a minimum forward voltage of +9V. Combined with a PT4115-based step-down constant current driver circuit (power input DC18V), it can drive 1 to 7 high-power LEDs connected in series, achieving continuous adjustment of light intensity. To avoid glare or overexposure caused by direct light from the LEDs, frosted glass is placed 5cm away in the direction of light dispersion to scatter light, improving image uniformity and quality. The lighting control platform includes a carrying platform; fruit samples are moved along a chute by a movable gripper, always remaining centered in the field of view and ensuring a consistent shooting angle, thus creating different lighting environments. An OLED display shows the current lighting mode in real time, preventing image acquisition under incorrect lighting conditions. The chute connects the carrying platform of the lighting control platform to the carrying platform of the hyperspectral imager.
[0045] S102: Acquire multiple fruit images of fruit samples under different lighting conditions using smart devices.
[0046] Optionally, smart devices include: smartphones.
[0047] S103: Using a hyperspectral device, acquire multiple hyperspectral images of fruit samples under multiple halogen lamp light sources.
[0048] It should be noted that a platform is also arranged inside the hyperspectral equipment box.
[0049] For example, both the lighting control platform and the hyperspectral equipment are equipped with a carrying platform to ensure that the fruit sample is accurately centered during each shot. The lighting control platform allows for precise adjustment of the duty cycle of warm and cool light sources, enabling accurate control of the target color temperature (2700K to 6500K) and light intensity (50lx to 350lx), creating an adjustable lighting environment. Simultaneously, the carrying gripper can move between multiple shooting positions between the lighting control platform and the hyperspectral equipment, simulating different shooting angles and ensuring consistent angles throughout each shot, avoiding image deviations caused by angle changes. Ultimately, the intelligent device captures multiple fruit images, while the hyperspectral equipment acquires the corresponding hyperspectral image at the same shooting angle, ensuring a perfect match between each hyperspectral image and the corresponding fruit image.
[0050] In this embodiment of the invention, the duty cycle of warm and cool light sources is adjusted by a lighting control platform to achieve precise control of the target color temperature, thus creating a variety of controllable lighting environments. Combined with a structural design featuring a movable object gripper, this ensures that fruit samples are always at the same shooting angle and position under different lighting conditions, thereby guaranteeing image consistency and contrast. This implementation effectively simulates various everyday lighting scenarios, improving the stability and repeatability of the image acquisition process, avoiding image distortion and measurement errors caused by changes in ambient light or angular deviations, and contributing to the accuracy and reliability of subsequent fruit image processing and sugar content detection.
[0051] S2: Based on a preset wavelength, each fruit hyperspectral image is filtered to obtain multiple filtered images, and each filtered image is recombined into an RGB image.
[0052] Optionally, the preset wavelengths include: preset red light wavelength, preset green light wavelength, and preset blue light wavelength.
[0053] It should be noted that those skilled in the art can set the preset red light wavelength, preset green light wavelength, and preset blue light wavelength according to actual needs, and this invention does not limit these settings.
[0054] In one possible implementation, S2 specifically includes sub-steps S201 to S204:
[0055] S201: Select hyperspectral images of fruits with preset red light wavelengths as the first selection images.
[0056] S202: Select hyperspectral images of fruits with a preset green light wavelength as the second selection images.
[0057] S203: Select hyperspectral images of fruits with preset blue light wavelengths as the third selection images.
[0058] S204: Recombine the first filtered image, the second filtered image, and the third filtered image into an RGB image.
[0059] In this embodiment of the invention, by selecting images corresponding to preset red, green, and blue light wavelengths from hyperspectral images and reconstructing them into RGB images, a high-fidelity visual reference image with physical spectral consistency is constructed. This also effectively compresses the dimensionality of high-dimensional hyperspectral data, making it more suitable for structural alignment and model training with ordinary RGB images. This RGB image can serve as a supervision label in the training of the ambient light compensation model, significantly improving the model's compensation accuracy and generalization ability under complex lighting conditions. Furthermore, this step supports custom wavelength configuration, exhibiting good adaptability and scalability, suitable for different devices and application scenarios, further enhancing the system's practicality and robustness.
[0060] S3: Using RGB images as the target images for fruits, match each fruit image with the target fruit image to construct a fruit image dataset.
[0061] In this embodiment of the invention, images corresponding to preset red, green, and blue wavelengths in hyperspectral images are filtered and reconstructed into RGB images as a standard reference image for illumination. Then, fruit images captured by smart devices under different lighting conditions are matched one-to-one with this RGB image to construct paired image datasets, thereby achieving high consistency pairing between 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 illumination conditions, but also avoids the problems of false labels and image structure misalignment, ensuring the authenticity and effectiveness of the training data. This contributes to the construction of a sugar content detection model with strong illumination robustness and high deployment flexibility.
[0062] Reference manual attached Figure 6 The diagram shows a schematic representation of an ambient light compensation algorithm model based on the DenseNet algorithm provided in an embodiment of the present invention.
[0063] S4: Using a fruit image dataset as training data, train the ambient light compensation algorithm model based on the DenseNet algorithm.
[0064] It's important to note that DenseNet (Dense Convolutional Network) is a densely connected convolutional neural network architecture. Its core idea is that every layer in the network is directly connected to all preceding 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-layered information.
[0065] In this embodiment of the 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.
[0066] The ambient light compensation algorithm model includes: a Stem module, multiple DenseBlock modules, multiple Transition modules, multiple Decoder modules, and a Color mapping module.
[0067] It's important to note that the Stem module is the network's entry point, responsible for initial feature extraction from the original image. This typically includes convolution, normalization, and pooling operations to quickly reduce image size and extract low-level features. The DenseBlock module is the core of the DenseNet architecture. By concatenating the output of each layer with the outputs of all preceding layers, it achieves efficient feature transfer and reuse, enhancing the network's expressive power. The Transition module is usually used between two DenseBlocks, containing convolution and pooling operations. Its main function is to compress feature map size and channel count, controlling model complexity. The Decoder module restores the image's spatial resolution, combining upsampling and skip connections to progressively reconstruct a high-resolution image from the features extracted during the encoding stage. The Color Mapping module focuses on fine-tuning color features, using convolution and nonlinear transformations to perform color mapping or illumination compensation on the image, achieving visual consistency and color correction.
[0068] It should be noted that, k Indicates the size of the convolution kernel. s This indicates the stride of the convolution operation.
[0069] Optionally, the Stem module consists of a 7×7 convolutional layer, a BN+ReLU activation layer, and a MaxPool max pooling layer.
[0070] Optionally, the DenseBlock module consists of a first DenseLayer (Denselayer1), a second DenseLayer (Denselayer2), a third DenseLayer (Denselayer3), and a fourth DenseLayer (Denselayer4). The inputs of the fourth DenseLayer are the outputs of the first DenseLayer, the second DenseLayer, and the third DenseLayer, respectively. The inputs of the third DenseLayer are the outputs of the first DenseLayer and the second DenseLayer, respectively. The input of the second DenseLayer is the output of the first DenseLayer.
[0071] Optionally, the Transition module consists of a BN+ReLU activation layer, a 3×3 convolutional layer, and an Avgpool average pooling layer.
[0072] 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.
[0073] Optionally, the Color mapping module consists of two 3×3 convolutional layers, two ReLU activation layers, three 1×1 convolutional layers, and one Sigmoid activation layer.
[0074] The DenseBlock module includes: the first DenseBlock module (Denseblock1), the second DenseBlock module (Denseblock2), and the third DenseBlock module (Denseblock3).
[0075] The Transition module includes a first Transition module (Transition1) and a second Transition module (Transition2), wherein the first Transition module is located between the first DenseBlock module and the second DenseBlock module, and the second Transition module is located between the second DenseBlock module and the third DenseBlock module.
[0076] The Decoder module includes: the first Decoder module (Decoder1), the second Decoder module (Decoder2), the third Decoder module (Decoder3), the fourth Decoder module (Decoder4), and the fifth Decoder module (Decoder5).
[0077] In this embodiment of the invention, by utilizing the various modules of the DenseNet architecture, particularly the efficient feature extraction of the Stem module, the feature reuse of DenseBlock, 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 can effectively improve the accuracy and robustness of image compensation. Each module is designed to optimize feature flow, enhance gradient propagation, reduce computational cost, and maintain the integrity and consistency of the image structure, ultimately providing high-quality input for fruit sugar content prediction.
[0078] S5: Obtain real-time fruit images of the fruit to be detected.
[0079] S6: Input the real-time fruit image into the trained ambient light compensation algorithm model to perform ambient light compensation, and output a fruit compensation image with the same color temperature as the target fruit image.
[0080] In this embodiment of the invention, by inputting real-time fruit images into the trained ambient light compensation model for compensation, the interference caused by changes in ambient light is eliminated, ensuring that the color temperature of the compensated image is consistent with that of the target image. This provides an accurate, uniform, and stable input image for subsequent sugar content prediction, significantly improving detection accuracy and system real-time performance.
[0081] In one possible implementation, S6 specifically includes sub-steps S601 to S604:
[0082] S601: Combining the Stem module and various DenseBlock modules, features are extracted from real-time fruit images to obtain multiple local feature maps.
[0083] S602: Through each Transition module, pooling operations are performed on each local feature map to obtain multiple pooled feature maps.
[0084] S603: Through each Decoder module, feature fusion is performed on each local feature map and each pooled feature map, and the feature fusion result is decoded to obtain multiple decoded feature maps.
[0085] S604: Through the Color mapping module, 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 target fruit image.
[0086] Specifically, in the Stem module, features are extracted from the real-time fruit image to obtain a first local feature map. In the first DenseBlock module, features are extracted from the first local feature map to obtain a second local feature map. In the first Transition module, pooling is performed on the second local feature map to obtain a first pooled feature map. In the second DenseBlock module, features are extracted from the first pooled feature map to obtain a third local feature map. In the second Transition module, pooling is performed on the third local feature map to obtain a second pooled feature map. In the third DenseBlock module, features are extracted from the second pooled feature map to obtain a fourth local feature map. In the first Decoder module, features are fused between the second pooled feature map and the fourth local feature map to obtain a first fused feature map, and decoding is performed on the first fused feature map to obtain a first decoded feature map. In the second Decoder module, features are fused between the third local feature map and the first decoded feature map to obtain a second fused feature map, and decoding is performed on the second fused feature map to obtain a second decoded feature map. In the third Decoder module, the first pooling feature map and the second decoded feature map are fused to obtain a third fused feature map, which is then 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 fused to obtain a fourth fused feature map, which is then decoded to obtain a fourth decoded feature map. In the fifth Decoder module, the first local feature map and the four decoded feature maps are fused to obtain a fifth fused feature map, which is then decoded to obtain a fifth decoded feature map. In the Color mapping module, dual-path residual fusion is performed on the real-time fruit image and the fifth decoded feature map to output a fruit-compensated image with the same color temperature as the target fruit image.
[0087] In this embodiment of the invention, by combining multi-module processing in the DenseNet architecture, ambient light compensation is performed on real-time fruit images step by step, from feature extraction to upsampling and then to color correction. Through multi-level feature learning, pooling compression, feature fusion, upsampling restoration, and color mapping correction, the compensated image maintains consistency with the standard target image in terms of color temperature and detail, greatly improving the accuracy of image compensation, detail restoration, and color consistency, thus providing an accurate input image for subsequent fruit sugar content detection.
[0088] Reference manual attached Figure 7 The diagram shows a schematic representation of a spectral image reconstruction algorithm model provided in an embodiment of the present invention.
[0089] S7: Input the fruit compensation image into the spectral image reconstruction algorithm model for reconstruction, and output the fruit reconstruction image.
[0090] In this embodiment of the invention, by inputting the compensated fruit image into the spectral image reconstruction algorithm model, the multi-band information of the hyperspectral image is recovered, 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.
[0091] The spectral image reconstruction algorithm model includes: DoubleConv module, multiple downsampling ERB module, multiple upsampling DAB module, inter-stage SAM connection module, and OutConv module.
[0092] It's worth noting that the DoubleConv module, used to extract local texture and multi-scale features, is a common fundamental component in encoders and decoders. The downsampling ERB (Enhanced Residual Block) extracts deep features through residual connections and convolutional operations, while employing pooling to reduce image resolution, enhancing the network's representational capabilities and preserving gradient flow. The upsampling DAB (Dual Attention Block) combines the SE (Channel Attention) and SCAM (Spatial Attention) modules, using transposed convolutions for size restoration, strengthening the response to important features for high-precision image reconstruction. The inter-stage SAM (Spatial Attention Module) is located between two sub-network stages, guiding information flow to key regions through spatial attention, 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 the target-dimensional output image, such as fruit reconstruction images.
[0093] Optionally, the downsampling ERB module consists of four 3×3 convolutional layers, two BN+ReLU activation layers, one ReLU activation layer, and one MaxPool max pooling layer.
[0094] Optionally, the upsampling DAB module consists of two 1×1 convolutional layers, an SE module, an AgvPool average pooling layer, a ReLU activation layer, an SCAM module, a 2×2 Transconv convolutional layer, and a DoubleConv convolutional layer.
[0095] Optionally, the SE module consists of an AgvPool average pooling layer, two Linear fully connected layers, and two ReLU activation layers.
[0096] 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 weights of each channel through a fully connected layer, and finally weights the original feature map, making the network pay more attention to the key channel features.
[0097] Optionally, the SCAM module consists of a 1×1 convolutional layer, two Sigmoid activation layers, and a 7×7 convolutional layer.
[0098] It should be noted that the SCAM module combines spatial attention and channel attention, which can both highlight key regions in the image and enhance the information representation of important channels. It typically first uses a channel attention mechanism to select high-weight features, and then uses a spatial attention mechanism to locate important regions in the image, achieving joint optimization of spatial and channel attention and improving the model's ability to represent complex features.
[0099] Optionally, the inter-stage SAM connection module consists of two 3×3 convolutional layers, one 1×1 convolutional layer, and one Sigmoid activation layer.
[0100] The downsampling ERB modules include: the first downsampling ERB module (ERB 1_1), the second downsampling ERB module (ERB 2_1), the third downsampling ERB module (ERB 3_1), the fourth downsampling ERB module (ERB 4_1), the fifth downsampling ERB module (ERB 1_2), the sixth downsampling ERB module (ERB 2_2), the seventh downsampling ERB module (ERB 3_2), and the eighth downsampling ERB module (ERB 4_2).
[0101] The upsampling DAB modules include: the first upsampling DAB module (DAB 1_1), the second upsampling DAB module (DAB 2_1), the third upsampling DAB module (DAB 3_1), the fourth upsampling DAB module (DAB 4_1), the fifth upsampling DAB module (DAB 1_2), the sixth upsampling DAB module (DAB 2_2), the seventh upsampling DAB module (DAB 3_2), and the eighth upsampling DAB module (DAB 4_2).
[0102] In this embodiment of the invention, an efficient and accurate image reconstruction framework is constructed by combining DoubleConv, downsampling ERB, upsampling DAB, inter-stage SAM connection modules, and the 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 and detail preservation of image reconstruction, making the final output image closer to reality, significantly improving the accuracy of sugar content prediction and the robustness of the system.
[0103] In one possible implementation, S7 specifically includes sub-steps S701 to S707:
[0104] S701: Using the DoubleConv module, multi-scale feature extraction is performed on the fruit compensation image to obtain a multi-scale feature map.
[0105] S702: Through each downsampling ERB module, a downsampling operation is performed on the multi-scale feature map to obtain multiple single-downsampled feature maps.
[0106] S703: Through each upsampling DAB module, perform an upsampling operation on each first-order downsampling feature map, and concatenate the result of the first-order upsampling operation with each first-order downsampling feature map to obtain multiple first-order upsampling feature maps.
[0107] S704: Through the inter-stage SAM connection module, spatial attention interaction is performed on the multi-scale feature map and the first upsampled feature map to obtain the enhanced feature map.
[0108] S705: Through each downsampling ERB module, a secondary downsampling operation is performed on the enhanced feature map to obtain multiple secondary downsampling feature maps.
[0109] S706: Through each upsampling DAB module, perform secondary upsampling operations on each secondary downsampling feature map, and concatenate the results of the secondary upsampling operations with each secondary downsampling feature map to obtain multiple secondary upsampling feature maps.
[0110] S707: The OutConv module performs a convolution operation on the secondary upsampled feature map to output the fruit reconstruction image.
[0111] Specifically, in the DoubleConv module, multi-scale feature extraction is performed on the fruit compensation image to obtain a multi-scale feature map. In the first downsampling ERB module, the multi-scale feature map is downsampled to obtain a first downsampled feature map. In the second downsampling ERB module, the first downsampled feature map is downsampled to obtain a second downsampled feature map. In the third downsampling ERB module, the second downsampled feature map is downsampled to obtain a third downsampled feature map. In the fourth downsampling ERB module, the third downsampled feature map is downsampled to obtain a fourth downsampled feature map. In the fourth upsampling DAB module, the fourth downsampled feature map is upsampled to obtain a first upsampled feature map. In the third upsampling DAB module, both the third downsampled feature map and the first upsampled feature map are upsampled, and the upsampled third downsampled feature map and the first upsampled feature map are concatenated to obtain a second upsampled feature map. In the second upsampling DAB module, upsampling operations are performed on both the second downsampling feature map and the second upsampling feature map, and then concatenated to obtain the third upsampling feature map. In the first upsampling DAB module, upsampling operations are performed on both the first downsampling feature map and the third upsampling feature map, and then concatenated to obtain the fourth upsampling feature map. In the inter-stage SAM connection module, spatial attention interaction is performed on the multi-scale feature map and the fourth upsampling feature map to obtain the enhanced feature map. In the fifth downsampling ERB module, downsampling operations are performed on the enhanced feature map to obtain the fifth downsampling feature map. In the sixth downsampling ERB module, downsampling operations are performed on the fifth downsampling feature map to obtain the sixth downsampling feature map. In the seventh downsampling ERB module, downsampling operations are performed on the sixth downsampling feature map to obtain the seventh downsampling feature map. In the eighth downsampling ERB module, downsampling operations are performed on the seventh downsampling feature map to obtain the eighth downsampling feature map. In the eighth upsampling DAB module, the eighth downsampling feature map is upsampled to obtain the fifth upsampling feature map. In the seventh upsampling DAB module, both the seventh downsampling feature map and the fifth upsampling feature map are upsampled, and the resulting seventh downsampling feature map and fifth upsampling feature map are concatenated to obtain the sixth upsampling feature map. In the sixth upsampling DAB module, both the sixth downsampling feature map and the sixth upsampling feature map are upsampled, and the resulting sixth downsampling feature map and sixth upsampling feature map are concatenated to obtain the seventh upsampling feature map. In the fifth upsampling DAB module, both the fifth downsampling feature map and the seventh upsampling feature map are upsampled, and the resulting fifth downsampling feature map and seventh upsampling feature map are concatenated to obtain the eighth upsampling feature map.In the OutConv module, a convolution operation is performed on the eighth upsampled feature map to output the fruit reconstruction image.
[0112] In this embodiment of the invention, the high-resolution features of the fruit image are gradually restored through the collaborative work of the DoubleConv, downsampling ERB, upsampling DAB, SAM connection module, and OutConv module. An attention mechanism is used to enhance the extraction of important information, ultimately outputting a high-quality reconstructed image. This process effectively improves the accuracy and detail preservation of image reconstruction, providing high-quality input data for subsequent sugar content prediction.
[0113] S8: Input the reconstructed fruit image into the fruit sugar content detection model based on the partial least squares regression algorithm for detection, and output the fruit sugar content of the fruit to be detected.
[0114] It's important to note 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 sizes. PLSR projects both input and output variables into a new latent space, extracting a set of latent factors that explain the maximum correlation between input features and output responses, and then performs regression analysis based on these factors. Compared to traditional least squares regression, PLSR not only effectively handles multicollinearity but also improves the model's robustness and generalization ability, thus it is widely used in tasks such as hyperspectral analysis, chemometrics, and fruit sugar content prediction.
[0115] In one possible implementation, S8 specifically refers to:
[0116] The sugar content of the fruit to be tested is output according to the following formula:
[0117] ;
[0118] in, Y This indicates the sugar content of the fruit being tested. Q Represents the coefficient of the regression term. X Represents a reconstructed image of fruit. T This indicates the transpose operation. F The residual represents the difference between the predicted and actual sugar content of the fruit. q N In the reconstructed image of the fruit, the first... N The regression coefficients corresponding to each band N =1,2,3,…, n , n Indicates the total number of bands. x N In the reconstructed image of the fruit, the first...N Hyperspectral data for each band.
[0119] In this embodiment of the invention, by employing the partial least squares regression (PLSR) algorithm to model the relationship between fruit reconstructed images and sugar content, key information can be effectively extracted from high-dimensional spectral data, improving the accuracy, robustness, and generalization ability of sugar content prediction, and providing an efficient and reliable prediction model for fruit sugar content detection in practical applications.
[0120] The beneficial effects of the technical solutions provided in the embodiments of the present invention include at least the following:
[0121] In this embodiment of the invention, real-time fruit images are input into a trained ambient light compensation algorithm model for ambient light compensation, outputting a fruit compensation image with the same color temperature as the target fruit image. This makes it less susceptible to interference from ambient light when the smart device captures images under different ambient light conditions, ensuring the stability of the sugar content prediction results. The fruit compensation image is then input into a spectral image reconstruction algorithm model for reconstruction, outputting a reconstructed fruit image. Finally, the reconstructed fruit image is input into a fruit sugar content detection model based on a partial least squares regression algorithm for detection, outputting the fruit sugar content of the fruit to be detected. This method no longer relies on physicochemical detection techniques, does not require expensive equipment, is easy to operate, is not easily affected by environmental conditions, and has a fast detection speed.
[0122] Reference manual attached Figure 8 The diagram shows a structural schematic of a fruit sugar content detection system under different lighting conditions provided by an embodiment of the present invention.
[0123] This invention provides a fruit sugar content detection system 20 under different lighting conditions, including: a processor 201 and a memory 202;
[0124] The memory 202 stores programs or instructions that can run on the processor 201. When the program or instructions are executed by the processor 201, they implement the steps of the above-described fruit sugar content detection method under different lighting conditions and achieve the same technical effect. To avoid repetition, the present invention will not elaborate further.
[0125] It should be understood that the processor 201 in this embodiment of the invention may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.
[0126] It should also be understood that the memory 202 in the embodiments of the present invention can be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of random access memory (RAM) are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDR SDRAM), enhanced synchronous DRAM (ESDRAM), synchronous linked DRAM (SLDRAM), and direct rambus RAM (DR RAM).
[0127] The above embodiments can be implemented, in whole or in part, by software, hardware (such as circuits), firmware, or any other combination thereof. When implemented using software, the above embodiments can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions or computer programs. When the computer instructions or computer programs are loaded or executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. 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 (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more sets of available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium. A semiconductor medium can be a solid-state drive.
[0128] It should be understood that, in various embodiments of the present invention, the order of the above-mentioned process numbers does not imply 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.
[0129] Those skilled in the art will recognize that the units and algorithm steps of the various examples 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 implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0130] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0131] In the several embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another device, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0132] The units described as separate components may or may not be physically separate. 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 the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0133] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0134] If the aforementioned 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 this invention, essentially, or the part 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 to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0135] This invention provides a readable storage medium comprising: storing a program or instructions on the readable storage medium, wherein when the program or instructions are executed by a processor, the program or instructions implement the steps of the above-described method for detecting the sugar content of fruits under different lighting conditions, and can achieve the same technical effect. To avoid repetition, this invention will not elaborate further.
[0136] Finally, it should be noted that the above embodiments are only used to illustrate 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 foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting the sugar content of fruit under different lighting conditions, characterized in that, include: S1: Obtain multiple fruit images under different lighting conditions and multiple hyperspectral images of fruit under multiple halogen lamp sources, wherein each hyperspectral image of the fruit corresponds one-to-one with a fruit image at the same shooting angle; S2: Based on a preset wavelength, each of the fruit hyperspectral images is filtered to obtain multiple filtered images, and each of the filtered images is recombined into an RGB image; S3: Using the RGB image as the target fruit image, match each of the fruit images with the target fruit image to construct a fruit image dataset; S4: Using the fruit image dataset as training data, train the ambient light compensation algorithm model based on the DenseNet algorithm; S5: Acquire real-time fruit images 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 compensation image with the same color temperature as the target fruit image; S7: Input the fruit compensation image into the spectral image reconstruction algorithm model for reconstruction, and output the fruit reconstruction image; S8: Input the reconstructed image of the fruit into a fruit sugar content detection model based on partial least squares regression algorithm for detection, and output the fruit sugar content of the fruit to be detected.
2. The method for detecting fruit sugar content under different lighting conditions according to claim 1, characterized in that, S1 specifically includes: S101: Adjust the duty cycle via 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 This indicates the color temperature at the rated current of the cold light source. T t Indicates the target color temperature. L cmax This indicates the brightness of a cold light source at its rated current. T w This indicates the color temperature at the rated current of a warm light source. L wmax This indicates the brightness of a warm light source at its rated current. D w Indicates the duty cycle of the warm light source; S102: Using a smart device, acquire multiple images of the fruit sample under different lighting conditions; S103: Using a hyperspectral device, acquire multiple hyperspectral images of the fruit sample under multiple halogen lamp light sources.
3. The method for detecting fruit sugar content under different lighting conditions according to claim 2, characterized in that, The lighting control platform includes: a control signal output module, an OLED display module, a button control module, a left-side LED light group module, a right-side LED light group module, a left-side drive circuit module, and a right-side drive circuit module.
4. The method for detecting fruit sugar content under different lighting conditions according to claim 1, characterized in that, The preset wavelengths include: preset red light wavelength, preset green light wavelength, and preset blue light wavelength; S2 specifically includes: S201: Select the hyperspectral images of fruits with the preset red light wavelength as the first selection images; S202: Select the hyperspectral images of fruits with the preset green light wavelength as the second selection images; S203: Select the hyperspectral images of fruits with the preset blue light wavelength as the third selection images; S204: Recombine the first filtered image, the second filtered image, and the third filtered image into the RGB image.
5. The method for detecting fruit sugar content under different lighting conditions according to claim 1, characterized in that, 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 disposed between the first DenseBlock module and the second DenseBlock module, and the second Transition module is disposed 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 fruit sugar content under different lighting conditions according to claim 5, characterized in that, S6 specifically includes: S601: Combine the Stem module and each of the DenseBlock modules to extract features from the real-time fruit image to obtain multiple local feature maps; S602: Through each of the Transition modules, pooling operations are performed on each of the local feature maps to obtain multiple pooled feature maps; S603: Through each of the Decoder modules, feature fusion is performed on each of the local feature maps and each of the pooled feature maps, and the feature fusion result is decoded to obtain multiple decoded feature maps; S604: The Color mapping module performs dual-path residual fusion on the real-time fruit image and the decoded feature map to output the fruit compensation image with the same color temperature as the target fruit image.
7. The method for detecting fruit sugar content under different lighting conditions according to claim 1, characterized in that, 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 fruit sugar content under different lighting conditions according to claim 7, characterized in that, Specifically, S7 includes: S701: The DoubleConv module is used to extract multi-scale features from the fruit compensation image 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 single-downsampled feature maps; S703: Through each of the upsampling DAB modules, perform an upsampling operation on each of the first downsampling feature maps, and concatenate the result of the upsampling operation with each of the first downsampling feature maps to obtain multiple first upsampling feature maps; S704: Through the inter-stage SAM connection module, spatial attention interaction is performed on the multi-scale feature map and the first upsampled feature map to obtain an enhanced feature map; S705: Perform a secondary downsampling operation on the enhanced feature map through each of the downsampling ERB modules to obtain multiple secondary downsampling feature maps; S706: Through each of the upsampling DAB modules, perform a secondary upsampling operation on each of the secondary downsampling feature maps, and concatenate the results of the secondary upsampling operation with each of the secondary downsampling feature maps to obtain multiple secondary upsampling feature maps; S707: The OutConv module performs a convolution operation on the secondary upsampled feature map to output the reconstructed fruit image.
9. The method for detecting fruit sugar content under different lighting conditions according to claim 1, characterized in that, Specifically, S8 is: The sugar content of the fruit to be tested is output according to the following formula: ; in, Y This indicates the sugar content of the fruit being tested. Q Represents the coefficient of the regression term. X Represents a reconstructed image of fruit. T This indicates the transpose operation. F The residual represents the difference between the predicted and actual sugar content of the fruit. q N In the reconstructed image of the fruit, the first... N The regression coefficients corresponding to each band N =1,2,3,…, n , n Indicates the total number of bands. x N In the reconstructed image of the fruit, the first... N Hyperspectral data for each band.
10. A fruit sugar content detection system under different lighting conditions, characterized in that, include: Processor and memory; The memory stores programs or instructions that can run on the processor, which, when executed by the processor, implement the steps of the fruit sugar content detection method under different lighting conditions as described in any one of claims 1 to 9.
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