Soil cation exchange capacity detection method based on color developing solution image recognition
By employing image processing techniques based on visual Transformer and extreme gradient boosting algorithms, the detection process for soil cation exchange capacity (CEC) has been simplified, achieving efficient and accurate CEC detection and solving the problems of cumbersome procedures and low efficiency in traditional methods.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-18
- Publication Date
- 2026-03-20
AI Technical Summary
Traditional chemical methods for detecting soil cation exchange capacity are cumbersome, inefficient, and require high operational precision.
Zero-shot semantic segmentation is performed using an image segmentation model based on the visual Transformer architecture, color correction is performed using a multivariate linear regression model, and the extreme gradient boosting algorithm is used to fit the relationship between the color concentration of the colored region and the soil cation exchange capacity, forming an automated analysis chain.
It simplifies the traditional chemical detection process, improves detection efficiency, and enables rapid and high-precision detection of soil cation exchange capacity under multi-light source conditions.
Smart Images

Figure CN121703078A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of soil physicochemical property detection technology, and in particular to a method for detecting soil cation exchange capacity based on colorimetric solution image recognition. Background Technology
[0002] Soil cation exchange capacity (CEC) has significant theoretical value and broad practical implications, serving as a core element in soil resource management, sustainable agricultural development, and environmental protection.
[0003] Currently, the detection methods for CEC mainly rely on traditional chemical detection methods, such as ammonium acetate extraction standard acid titration, BaCl2-MgSO4, and hexaamminecobalt trichloride extraction spectrophotometry. The basic steps of the ammonium acetate extraction standard acid titration method are as follows: saturate the soil exchange sites with a 1 mol / L ammonium acetate solution (pH 7.0) to displace exchangeable cations, then wash away free salts with ethanol, followed by 3-4 replacements with potassium chloride or sodium chloride solution to remove NH4+ from the soil colloids. + After complete displacement, the displacement solution is collected and distilled under alkaline conditions to remove NH4. + It is converted into NH3, absorbed with boric acid solution and titrated with a standard acid, thereby calculating the cation exchange capacity of the soil.
[0004] However, traditional chemical detection methods involve multiple exchangeable ion saturation and displacement of soil samples, repeated washing to remove free salts, and subsequent distillation and titration processes. These steps not only require high operational precision, but also require waiting for the reaction to complete and for transfer and cleaning at each step, making the entire determination process cumbersome, complex, and inefficient. Summary of the Invention
[0005] Therefore, it is necessary to provide a method for detecting soil cation exchange capacity based on colorimetric solution image recognition to address the aforementioned technical problems.
[0006] This invention provides a method for detecting soil cation exchange capacity based on colorimetric solution image recognition, comprising: Acquire images of the supernatant of soil samples after reaction with methylene blue solution under multi-light source conditions; A visual Transformer-based image segmentation model was used to perform zero-sample semantic segmentation on color patches in the supernatant image to extract the location information of different color regions in the color patches and obtain color partitions. A multiple linear regression model was used to perform color correction on the color partitions to eliminate color deviation under different light source conditions, and the RGB parameters of the methylene blue circular color display area were obtained. The RGB parameters are input into a pre-trained extreme gradient boosting algorithm to fit the numerical relationship between the color concentration of the color region and the soil cation exchange capacity, thereby obtaining the soil cation exchange capacity of the soil to be tested.
[0007] Optionally, an extreme gradient boosting algorithm is trained, specifically including: Images of the supernatant after soil samples reacted with methylene blue solution under various light source conditions and the corresponding measured values of soil cation exchange capacity were obtained. Images of the supernatant after soil samples react with methylene blue solution under various light source conditions are input into an extreme gradient boosting algorithm to obtain predicted values of soil cation exchange capacity. The extreme gradient boosting algorithm is trained with the goal of maximizing the coefficient of determination between the measured and predicted values of soil cation exchange capacity and minimizing the root mean square error between the two values.
[0008] Optionally, the coefficient of determination between the measured and predicted values of soil cation exchange capacity is determined based on the following formula: The root mean square error between the measured and predicted values of soil cation exchange capacity is determined based on the following formula: in, m The number of sample points. y i This is the measured value of soil cation exchange capacity. This is a predicted value for soil cation exchange capacity. y This is the average of the model's predicted values.
[0009] Optionally, images of the supernatant after the soil sample reacts with methylene blue solution under multi-light source conditions are acquired, specifically including: The soil sample to be tested was pretreated to obtain the supernatant after the soil sample reacted with methylene blue solution; the pretreatment included weighing, mixing with methylene blue solution, shaking and centrifugation; After placing the supernatant in a cell culture dish, the cell culture dish and color chart were placed together in the center of an A4 sheet of paper. Images were then taken using a portable smartphone under different color lighting conditions to obtain images of the supernatant of the soil sample after reacting with methylene blue solution under multi-light source conditions.
[0010] Optionally, a visual Transformer-based image segmentation model is used to perform zero-shot semantic segmentation on color patches in the supernatant image to extract the location information of different colored regions within the color patches, thus obtaining color partitioning. Specifically, this includes: The image segmentation model based on the visual Transformer architecture includes: a feature extraction module and a mask decoder connected in sequence. The feature extraction module includes: a parallel image encoder and a cue encoder. An image encoder is used to extract features from color patches in the supernatant image to obtain global feature representations of the color patches and thus obtain image features. A cue encoder is used to convert the spatial location information of color blocks in the supernatant image into feature vectors to obtain cue features; A mask decoder is used to perform cross-attention weighting on image features and cue features to generate target masks corresponding to color patches in the supernatant image, thus obtaining color partitions.
[0011] Optionally, a multiple linear regression model is used to perform color correction on the color partitions to eliminate color deviations under different light source conditions, obtaining the RGB parameters of the methylene blue circular color display area, specifically including: The color values of the color partitions are compared with the set standard color values to obtain the color transformation parameters; Using the color transformation parameters as linear regression coefficients, a multiple linear regression model is constructed based on the following formula: r k = a 11 v 1k + a 12 v 2k + · · · + a 1j v jk ; g k = a 21 v 1k + a 22 v 2k + · · · + a 2j v jk ; b k = a 31 v 1k + a 32 v 2k + · · · + a 3j v jk ; Among them, V 1k V 2k , ..., v jk This represents known color channel values and their combinations; The RGB parameters of the methylene blue circular color region are obtained by correcting the color values of all pixels in the image based on the following formula: Y = V·AV; V={r,g,b,r·b,r·g,g·b,r 2 ,g 2 ,b 2 ,r·b·g}; Where Y represents the corrected color value, A is the color transformation parameter matrix, and V is the color observation value collected by the color patch.
[0012] Optionally, the soil sample to be tested reacts with the methylene blue solution at a temperature between 20°C and 28°C.
[0013] The method for detecting soil cation exchange capacity based on colorimetric solution image recognition provided in this invention has the following advantages compared with the prior art: This invention combines an image segmentation model, a multiple linear regression model, and an extreme gradient boosting algorithm to form an automated analysis chain of "image segmentation-color correction-intelligent prediction." This technical solution transforms the complex chemical detection process into a visual computing task, simplifying the manual chemical process that relies on multiple ion exchanges, washing, and titrations. It not only solves the problems of cumbersome steps and low efficiency in traditional chemical detection methods, significantly improving detection efficiency, but also achieves rapid and high-precision detection of soil cation exchange capacity under multi-light source conditions. Attached Figure Description
[0014] Figure 1 This is an image taken in one embodiment of a method for detecting soil cation exchange capacity based on colorimetric solution image recognition; Figure 2 This is a SAM model color card detection effect diagram of a soil cation exchange capacity detection method based on colorimetric solution image recognition provided in one embodiment; Figure 3 This is a comparison of images before and after correction for a soil cation exchange capacity detection method based on colorimetric solution image recognition provided in one embodiment; Figure 4 A flowchart illustrating the model construction of a soil cation exchange capacity detection method based on colorimetric solution image recognition provided in one embodiment; Figure 5 This is a model performance diagram of a soil cation exchange capacity detection method based on colorimetric solution image recognition provided in one embodiment; Figure 6 This is a schematic flowchart of a soil cation exchange capacity detection method based on colorimetric solution image recognition provided in one embodiment. Detailed Implementation
[0015] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0016] Image processing technology has garnered significant attention and made substantial progress in the scientific community, gradually permeating various fields such as science and engineering. Zhang et al. successfully established a relationship between the RGB values and concentration of potassium permanganate solution using a color solution concentration prediction technique based on machine vision and IDEBPNN. Clara Míguez et al. employed RGB and grayscale models for digital image processing to measure the number of Chlorella cells, achieving high accuracy in a controlled photobioreactor combined with grayscale calibration curves and RGB models. These studies demonstrate the substantial increase in the application of digital image information acquisition methods in analytical fields due to their intuitiveness, ease of operation, and proven high accuracy in various applications.
[0017] This invention provides a method for detecting soil cation exchange capacity based on colorimetric solution image recognition, the method comprising: Images of the supernatant of soil samples reacting with methylene blue solution under multi-light source conditions were obtained.
[0018] A visual Transformer-based image segmentation model was used to perform zero-sample semantic segmentation on color patches in the supernatant image to extract the location information of different color regions in the color patches and obtain color partitions.
[0019] A multiple linear regression model was used to perform color correction on the color partitions to eliminate color deviations under different light source conditions, and the RGB parameters of the methylene blue circular color display area were obtained.
[0020] The RGB parameters are input into a pre-trained extreme gradient boosting algorithm to fit the numerical relationship between the color concentration of the color region and the soil cation exchange capacity, thereby obtaining the soil cation exchange capacity of the soil to be tested.
[0021] The specific implementation is as follows: 1. Image capture.
[0022] Weigh 0.015g of 0.149mm air-dried soil into a 50mL centrifuge tube. Measure 40mL of a 20ppm MB solution into the centrifuge tube, shake for 20 minutes, and centrifuge. Transfer 4mL of the supernatant to a cell culture dish (D×H=35mm×12mm). Place the cell culture dish and the prepared 10-color chart in the center of an A4 sheet of paper. The color chart is used because a color correction model is needed to correct the colors captured by the smartphone, and the parameter information provided by the color chart helps in building this model. Use a Midea desk lamp for light control and take photos under white light, yellowish-white light, yellow light, and natural light conditions using an iPhone 13 camera.
[0023] 2. Image localization and correction.
[0024] To address the failure of traditional image segmentation methods in scenarios with blurred color patch edges, the SegmentAnything Model (SAM) is introduced to achieve sub-pixel-level localization of color patch regions. SAM is based on the visual Transformer architecture and uses a collaborative mechanism of image encoder, prompt encoder, and mask decoder to perform zero-sample semantic segmentation of color patches in the image.
[0025] SAM (Segment Algorithm) achieves accurate segmentation in color swatch localization and segmentation through the collaborative work of an image encoder, a cue encoder, and a mask decoder. The segmentation process includes: first, inputting the image containing the color swatch into the image encoder (based on Vision Transformer) to extract global feature representations; then, inputting the provided bounding box cue information into the cue encoder to convert spatial location information into feature vectors; finally, the mask decoder combines image features and cue features to generate a target mask through a cross-attention mechanism. The color swatch, with its regular geometric shape, clear boundaries, and high contrast, enables the model to effectively distinguish the target from the background, achieving accurate segmentation.
[0026] It is worth noting that SAM's segmentation process does not rely on color information, but rather completes target localization and mask generation through feature representation and cues. Its core lies in employing dynamic convolutional kernels and a boundary-sensitive loss function, endowing the model with topological awareness of blurred boundaries through large-scale pre-training (SA-1B dataset). Furthermore, since the camera parameters of different smartphones may vary significantly, and different lighting conditions can also lead to pixel value deviations, it is necessary to correct for color deviations in images. A multivariate linear regression model is proposed for color correction. By comparing the color values of 10 extracted color patches with known color channel values, the model parameters can be calculated. Let a... 11 a 12 , ..., a 1jLet R channel represent the color transformation parameters. Then, the corrected color can be represented as follows:
[0027] r k = a 11 v 1k + a 12 v 2k + · · · + a 1j v jk ; g k = a 21 v 1k + a 22 v 2k + · · · + a 2j v jk ; b k = a 31 v 1k + a 32 v 2k + · · · + a 3j v jk ; Where V 1k V 2k , ..., v jk This represents known color channel values and their combinations. When k takes values from 1 to the number of color patches n, all color patches and their corresponding standard colors can be used to calculate color transformation parameters.
[0028] To simplify the equation, the matrix form is as follows: Y = V·AT; V={r,g,b,r·b,r·g,g·b,r 2 ,g 2 ,b 2 ,r·b·g}; Where Y represents the corrected color value, A is the color transformation parameter matrix, and V is the known color channel value.
[0029] 3. Parameter input.
[0030] The RGB values (corrected color values Y) of the extracted methylene blue circular color region were used as input parameters. Extreme Gradient Boosting (XGBoost) was selected as the fitting model. XGBoost is an efficient gradient boosting decision tree algorithm that iteratively builds weak decision trees to fit the prediction error of the previous round, optimizes the loss function, and introduces regularization to prevent overfitting. It supports parallel computing, automatically handles missing values, and can be used for tasks such as classification, regression, and ranking. It features fast training speed and strong generalization ability. The database for this model contains more than 600 sets of data, each set containing images under four light sources and CEC measured data, with the training set and test set split in a 7:3 ratio.
[0031] 4. Model detection results.
[0032] by R 2 , RMSE As an evaluation metric for the XGB model, after model training and validation, it performs well on the clay dataset ( R 2 =0.8405, RMSE =0.3452 cmol·g -1 ), under the soil dataset ( R 2 =0.7288, RMSE =0.2715 cmol·g -1 The results show that this method can accurately predict soil CEC values, while greatly simplifying the operation steps and saving detection time.
[0033] ; ; in, m The number of sample points. y i This is the measured value of soil cation exchange capacity. This is a predicted value for soil cation exchange capacity. y This is the average of the model's predicted values.
[0034] The detection temperatures in this invention were all conducted at room temperature (20°C-28°C). Since the adsorption of methylene blue by soil may be affected by temperature, extreme temperature conditions may lead to significant errors in the detection results. 5. Technical effects.
[0035] This invention relates to an innovative technique for establishing a relationship between the color intensity of methylene blue solution after soil adsorption and the concentration of chloroform (CEC) using machine learning image color extraction. This method involves acquiring image data under open lighting conditions, converting the image data to RGB space, using a color chart to obtain a correction matrix for image correction, using the extracted RGB parameters as input features, and fitting the model using an XGB model to finally output the CEC value. This model utilizes a portable smartphone for image acquisition, eliminating reliance on specialized equipment. It exhibits high detection accuracy even in open environments with multiple light sources. Compared to traditional chemical determination methods, it has smaller detection errors and significantly saves time and labor costs.
[0036] The embodiments described above are merely examples of several implementations of the present invention, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these modifications and improvements all fall within the scope of protection of the present invention.
Claims
1. A method for detecting soil cation exchange capacity based on colorimetric solution image recognition, characterized in that, include: Acquire images of the supernatant of soil samples after reaction with methylene blue solution under multi-light source conditions; A visual Transformer-based image segmentation model was used to perform zero-sample semantic segmentation on color patches in the supernatant image to extract the location information of different color regions in the color patches and obtain color partitions. A multiple linear regression model was used to perform color correction on the color partitions to eliminate color deviation under different light source conditions, and the RGB parameters of the methylene blue circular color display area were obtained. The RGB parameters are input into a pre-trained extreme gradient boosting algorithm to fit the numerical relationship between the color concentration of the color region and the soil cation exchange capacity, thereby obtaining the soil cation exchange capacity of the soil to be tested.
2. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 1, characterized in that, Training the extreme gradient boosting algorithm specifically includes: Images of the supernatant after soil samples reacted with methylene blue solution under various light source conditions and the corresponding measured values of soil cation exchange capacity were obtained. Images of the supernatant after soil samples react with methylene blue solution under various light source conditions are input into an extreme gradient boosting algorithm to obtain predicted values of soil cation exchange capacity. The extreme gradient boosting algorithm is trained with the goal of maximizing the coefficient of determination between the measured and predicted values of soil cation exchange capacity and minimizing the root mean square error between the two values.
3. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 2, characterized in that, The coefficient of determination between the measured and predicted values of soil cation exchange capacity is determined based on the following formula: ; The root mean square error between the measured and predicted values of soil cation exchange capacity is determined based on the following formula: ; in, m The number of sample points. y i This is the measured value of soil cation exchange capacity. This is a predicted value for soil cation exchange capacity. y This is the average of the model's predicted values.
4. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 1, characterized in that, The acquisition of images of the supernatant after the reaction of the soil sample with methylene blue solution under multi-light source conditions specifically includes: The soil sample to be tested is pretreated to obtain the supernatant after the soil sample reacts with methylene blue solution; the pretreatment includes weighing, mixing with methylene blue solution, shaking and centrifugation; After placing the supernatant in a cell culture dish, the cell culture dish and color chart were placed together in the center of an A4 sheet of paper. Images were then taken using a portable smartphone under different color lighting conditions to obtain images of the supernatant of the soil sample after reacting with methylene blue solution under multi-light source conditions.
5. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 1, characterized in that, The method employs a visual Transformer-based image segmentation model to perform zero-shot semantic segmentation on color patches in the supernatant image, extracting the location information of different colored regions within the color patches to obtain color partitioning. Specifically, this includes: The image segmentation model based on the visual Transformer architecture includes: a feature extraction module and a mask decoder connected in sequence; the feature extraction module includes: a parallel image encoder and a cue encoder. An image encoder is used to extract features from color patches in the supernatant image to obtain global feature representations of the color patches and thus obtain image features. A cue encoder is used to convert the spatial location information of color blocks in the supernatant image into feature vectors to obtain cue features; A mask decoder is used to perform cross-attention weighting on image features and cue features to generate target masks corresponding to color patches in the supernatant image, thus obtaining color partitions.
6. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 1, characterized in that, The process employs a multiple linear regression model to perform color correction on the color zones, eliminating color deviations under different light source conditions, and obtaining the RGB parameters of the methylene blue circular color display area. Specifically, this includes: The color values of the color partitions are compared with the set standard color values to obtain the color transformation parameters; Using the color transformation parameters as linear regression coefficients, a multiple linear regression model is constructed based on the following formula: r k = and 11 in 1k + and 12 in 2k + · · · + and 1j in jk ; g k = and 21 in 1k + and 22 in 2k + · · · + and 2j in jk ; b k = and 31 in 1k + and 32 in 2k + · · · + and 3j in jk ; Among them, V 1k V 2k , ..., v jk This represents known color channel values and their combinations; The RGB parameters of the methylene blue circular color region are obtained by correcting the color values of all pixels in the image based on the following formula: Y = V·AV; V={r,g,b,r·b,r·g,g·b,r 2 ,g 2 ,b 2 ,r·b·g}; Where Y represents the corrected color value, A is the color transformation parameter matrix, and V is the color observation value collected by the color patch.
7. The method for detecting soil cation exchange capacity based on colorimetric solution image recognition as described in claim 1, characterized in that, The soil samples to be tested were reacted with methylene blue solution at temperatures between 20°C and 28°C.