Color recognition and concentration determination method and system based on artificial intelligence model
By using image feature extraction and color constraint correction through artificial intelligence models, the detection deviations caused by changes in lighting and equipment in nitrite concentration detection have been resolved, thereby improving the accuracy and reliability of the detection results.
Patent Information
- Application Number
- CN202611374287.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-07
- Publication Date
- 2026-11-24
AI Technical Summary
Existing image recognition-based methods for detecting nitrite concentration are prone to deviations in detection results when lighting conditions and image acquisition equipment change. Furthermore, they lack model feedback correction and stability evaluation, resulting in insufficient accuracy and reliability of the detection results.
A color recognition and concentration determination method based on an artificial intelligence model is adopted. Through image feature extraction, main regression branch and color constraint correction branch, regression feature correction parameters are generated using color deviation features. Multiple corrections and equivalent image transformations are performed to improve the consistency and reliability of detection results.
It improves the accuracy and reliability of nitrite concentration detection, solves the problem of the influence of light and equipment changes on the detection results, and realizes the stability and reliability judgment in complex environments.
Smart Images

Figure CN123160901A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence detection technology, specifically to a method and system for color identification and concentration determination based on an artificial intelligence model. Background Technology
[0002] Nitrite concentration detection is widely used in food safety, water quality testing, and environmental monitoring. Current nitrite detection methods typically employ a chemical colorimetric reaction, where the sample reacts with a colorimetric reagent to produce a color change, and the concentration is determined based on the degree of this color change.
[0003] In existing concentration detection methods based on image recognition, the model mainly predicts based on the correspondence between image features and concentration data. When the lighting conditions, image acquisition equipment, and sample color development state in the detection environment change, it is easy to cause a deviation between the acquired color information and the color development state corresponding to the actual concentration, thus affecting the accuracy of the concentration prediction results.
[0004] Meanwhile, existing AI models, after completing concentration prediction, typically lack a method to feedback and correct the prediction results by incorporating standard colorimetric relationships. This prevents them from further adjusting the model's predictions based on the deviation between the actual color and the color corresponding to the predicted concentration. Furthermore, existing methods usually determine the final detection concentration based on a single prediction result, lacking evaluation of the model's output stability under different input conditions, leading to insufficient reliability of the detection results. Summary of the Invention To address the shortcomings of existing technologies, the technical solution of this invention is as follows: A color recognition and concentration determination method based on an artificial intelligence model includes the following steps: S1, image acquisition of the sample to be tested after the nitrite colorimetric reaction, and the colorimetric image to be tested is obtained by light calibration, noise reduction, color normalization and colorimetric region extraction, and the color features to be tested are extracted. S2, input the colorimetric image to be tested into the artificial intelligence model. The artificial intelligence model includes an image feature extraction network, a main regression branch and a color constraint correction branch. The image feature extraction network extracts deep image features, and the main regression branch forms regression features based on the deep image features to obtain the initial concentration prediction results. S3. Based on the initial concentration prediction results, the reference color features are determined from the standard color relationship. The color deviation features are obtained by comparing the color features to be tested with the reference color features. The color constraint correction branch generates regression feature correction parameters based on the color deviation features. The regression features are corrected and the corrected concentration prediction results are obtained. S4. Based on the corrected concentration prediction results, the reference color features are redefined and the color deviation features are updated. Based on the color deviation features before and after the correction, it is determined whether the color constraint correction has converged. When converged, the equivalent image transformation is performed on the color image to be tested. The equivalent transformed image is input into the artificial intelligence model to obtain multiple equivalent concentration prediction results. S5 determines the detection reliability result based on the dispersion of multiple equivalent concentration prediction results. When the output conditions are met, the corrected concentration prediction result is used as the detection concentration, and the detection confidence and concentration error range are determined. If the convergence is not achieved or the output conditions are not met, the colorimetric image to be tested is reacquired.
[0005] Furthermore, the main regression branch in the artificial intelligence model includes a first regression layer, a second regression layer, and a concentration output layer connected in sequence; The first regression layer obtains the first regression feature based on the deep image features; The second regression layer obtains the regression features based on the first regression feature; The color constraint correction branch is connected between the second regression layer and the concentration output layer. The regression feature correction parameter is applied to the regression feature to obtain the corrected regression feature, and the concentration output layer obtains the corrected concentration prediction result based on the corrected regression feature.
[0006] Furthermore, the image feature extraction network adopts the EfficientNet-B0 network. The first regression layer maps the deep image features into 512-dimensional first regression features, and performs batch normalization, nonlinear activation and random deactivation processing in sequence. The second regression layer maps the first regression feature to the 128-dimensional regression feature, and performs batch normalization, nonlinear activation and random deactivation processing in sequence; The concentration output layer maps the modified regression features to a single concentration value and obtains the modified concentration prediction result through a non-negative activation function.
[0007] Furthermore, the color features to be tested include the red channel information, green channel information, blue channel information, saturation, and brightness of the color-developing region in the color-developing image to be tested; Obtain the color features corresponding to standard colorimetric samples of different known concentrations, establish the standard colorimetric relationship based on the correspondence between the true concentration and color features of each standard colorimetric sample, and determine the center value and fluctuation range of color features corresponding to different concentrations respectively.
[0008] Furthermore, based on the initial concentration prediction result, the corresponding color feature center value and color feature fluctuation range are determined in the standard color development color relationship, and the color development deviation feature is obtained based on the deviation of the color feature to be tested relative to the color feature center value and the corresponding color feature fluctuation range; The color constraint correction branch generates scale correction parameters and offset correction parameters based on the color deviation characteristics, modulates the regression features based on the scale correction parameters and the offset correction parameters to obtain the corrected regression features, and obtains the corrected concentration prediction result based on the corrected regression features.
[0009] Furthermore, the amount of color deviation before correction is determined based on the aforementioned color deviation characteristics; The reference color features are re-determined from the standard colorimetric relationship based on the corrected concentration prediction results; The color feature to be tested is compared with the redefined reference color feature to update the color deviation feature, and the corrected color deviation amount is determined. When the corrected color deviation is within the allowable deviation range, and the change in the corrected color deviation relative to the original color deviation satisfies the convergence condition, the color constraint correction is determined to be converged.
[0010] Furthermore, when the color constraint correction has not converged, the deviation change ratio is determined based on the ratio of the corrected color deviation to the uncorrected color deviation. When the deviation change ratio is less than 1 and the corrected color deviation amount does not enter the allowable deviation range, the correction direction corresponding to the scale correction parameter and the offset correction parameter is maintained, and the correction amplitude of the next feature modulation is set to the product of the current correction amplitude and the first adjustment coefficient, where the first adjustment coefficient is not less than 1. When the deviation change ratio is not less than 1, the correction amplitude of the next feature modulation is set to the product of the current correction amplitude and the second adjustment coefficient, where the second adjustment coefficient is greater than 0 and less than 1, and the corrected regression feature and the corrected concentration prediction result are re-determined based on the adjusted scale correction parameter and the offset correction parameter.
[0011] Furthermore, after the color constraint correction converges, an equivalent image transformation is performed on the color image to be tested, while maintaining the meaning of color concentration in the color region, to obtain multiple equivalent transformed images. The equivalent image transformation includes at least one of position transformation, scale resampling, and region cropping; Multiple equivalent transformed images are input into the artificial intelligence model to obtain multiple equivalent concentration prediction results, and the prediction dispersion is determined based on the distribution of the multiple equivalent concentration prediction results relative to the corrected concentration prediction results.
[0012] Furthermore, the detection reliability result is determined based on the convergence state of the color constraint correction and the predicted dispersion. When the color constraint correction converges and the prediction dispersion is within the allowable range, the corrected concentration prediction result is determined as the detection concentration, and the detection confidence and the concentration error range are determined based on the corrected color deviation and the prediction dispersion. When the color constraint correction converges and the predicted dispersion exceeds the allowable range, the color image to be tested is reacquired. When the color constraint correction fails to converge, the regression feature correction parameters are re-determined based on the change between the color deviation before and after the correction, or the image standardization process is re-performed on the color image to be tested.
[0013] A color recognition and concentration determination system based on an artificial intelligence model includes an image acquisition and processing module, a concentration prediction module, a color constraint correction module, a feedback convergence control module, and a reliability evaluation module. The image acquisition and processing module acquires images of the sample after the nitrite color development reaction, and obtains the color development image of the sample after light calibration, noise reduction, color normalization and color development region extraction, and extracts the color features of the sample. The concentration prediction module inputs the colorimetric image to be tested into an artificial intelligence model. The artificial intelligence model includes an image feature extraction network, a main regression branch, and a color constraint correction branch. The image feature extraction network extracts deep image features, and the main regression branch forms regression features based on the deep image features to obtain the initial concentration prediction result. The color constraint correction module determines the reference color feature from the standard color rendering relationship based on the initial concentration prediction result, compares the color feature to be tested with the reference color feature to obtain the color rendering deviation feature, and the color constraint correction branch generates regression feature correction parameters based on the color rendering deviation feature to correct the regression feature and obtain the corrected concentration prediction result. The feedback convergence control module redetermines the reference color features and updates the color deviation features based on the corrected concentration prediction results. It determines whether the color constraint correction has converged based on the color deviation features before and after the correction. When convergence occurs, it performs an equivalent image transformation on the color image to be tested and inputs the equivalent transformed image into the artificial intelligence model to obtain multiple equivalent concentration prediction results. The reliability evaluation module determines the detection reliability result based on the dispersion of multiple equivalent concentration prediction results. When the output conditions are met, the corrected concentration prediction result is used as the detection concentration, and the detection confidence and concentration error range are determined. If the convergence is not achieved or the output conditions are not met, the colorimetric image to be tested is reacquired.
[0014] The beneficial effects of this invention are as follows: 1. By inputting the colorimetric image to be tested into an artificial intelligence model including an image feature extraction network, a main regression branch, and a color constraint correction branch, and determining the corresponding reference color features based on the initial concentration prediction results, the regression feature correction parameters are generated using the colorimetric deviation features between the colorimetric features to be tested and the reference color features to correct the regression features. This solves the problem in the existing technology that relies solely on image features for concentration prediction, which is easily affected by changes in illumination, differences in acquisition equipment, and changes in the colorimetric state of the sample, leading to reduced accuracy of the detection results.
[0015] 2. By redetermining the reference color features based on the corrected concentration prediction results, and judging whether the color constraint correction has converged based on the color deviation characteristics before and after correction, the regression feature correction parameters are adjusted when the convergence condition is not met. This solves the problem that the output results of artificial intelligence models in the existing technology lack feedback correction process and cannot further optimize the prediction results based on the actual color state, thus improving the consistency between the concentration prediction results and the actual color state.
[0016] 3. By performing an equivalent image transformation on the color image to be tested after color constraint correction, multiple equivalent concentration prediction results are obtained. The detection reliability result is determined based on the dispersion of the multiple equivalent concentration prediction results. This solves the problem that single image prediction is easily affected by image acquisition errors in the existing technology, making it difficult to judge the stability of the detection results, and improves the reliability of concentration detection results in complex detection environments. Attached Figure Description
[0017] Figure 1 This is a schematic diagram of the overall process of the color recognition and concentration determination method of the artificial intelligence model of the present invention; Figure 2 This is a schematic diagram of the artificial intelligence model structure and the connection relationship of the color constraint correction branches in this invention; Figure 3 This is a schematic diagram of the regression feature iterative correction process for color deviation feedback in this invention; Figure 4 This is a schematic diagram of the reliability evaluation process for the detection of equivalent image transformation according to the present invention. Detailed Implementation
[0018] The technical solution of the present invention will be clearly and completely described below with reference to specific embodiments. The listed embodiments are used to illustrate the specific implementation process of the present invention and the processing methods under different operating states. Those skilled in the art can implement the corresponding technical solutions based on the technical content recorded in this specification.
[0019] Example 1 Please see Figures 1-4 Specifically, in this embodiment, a liquid sample after the nitrite colorimetric reaction is completed is used as the detection object. A colorimetric image is acquired through a mobile terminal, and the nitrite concentration is determined by combining the deep image information and color physical information in the colorimetric image. The sample to be tested is a liquid sample that has completed the nitrite colorimetric reaction and is waiting for image detection. The colorimetric image to be tested is an image formed after light calibration, noise reduction, color normalization, and colorimetric region extraction of the original acquired image of the sample to be tested. The color features to be tested are the red channel information, green channel information, blue channel information, saturation, and brightness obtained from the corresponding colorimetric region of the colorimetric image to be tested. The standard colorimetric relationship is used to record the standard colorimetric state corresponding to different nitrite concentrations and its normal fluctuation. The colorimetric deviation feature is used to record the direction and degree of deviation of the color features to be tested relative to the standard colorimetric state corresponding to the current predicted concentration. The regression feature correction parameters include the scale correction parameter and the offset correction parameter acting on the regression features inside the artificial intelligence model.
[0020] In this embodiment, the data used for model building and detection are divided into a standard color calibration sample set, a model training sample set, a model validation sample set, and an independent test sample set. The standard color calibration sample set is used to establish standard color relationships, the model training sample set is used to update the network parameters of the artificial intelligence model, the model validation sample set is used to evaluate the model training process and determine the judgment conditions related to color deviation, correction feedback, and prediction stability after the model parameters are fixed, and the independent test sample set is used to complete the detection effect verification after model training and judgment parameter fixing.
[0021] When preparing the standard colorimetric calibration sample set, ten standard nitrite concentration levels were set: 0, 0.10, 0.25, 0.50, 1.00, 2.00, 4.00, 6.00, 8.00, and 10.00 mg / L. Twenty standard colorimetric samples were prepared independently for each concentration level. For each standard colorimetric sample, 2 mL of sample solution was taken, and p-aminobenzenesulfonic acid colorimetric reagent and naphthylethylenediamine hydrochloride colorimetric reagent were added in the same order. The samples were allowed to stand for 5 min at 20–25℃ to complete the color development. The samples used for subsequent model training, model validation, and independent testing were treated with the same colorimetric reagents, sample addition order, and color development time.
[0022] In addition, 300 independent colorimetric samples with concentrations ranging from 0 to 10.00 mg / L were prepared to establish the model training sample set and the model validation sample set. One original colorimetric image was acquired for each colorimetric sample under standard white light, warm LED light, and natural diffused light conditions, resulting in a total of 900 model images. The model training sample set and the model validation sample set were divided according to the colorimetric sample number at a ratio of 80% and 20%, respectively. All images of the same colorimetric sample obtained under different lighting conditions were assigned to the same dataset to maintain the independence of the training samples and the validation samples at the sample source level.
[0023] For each model sample, the corresponding true nitrite concentration was obtained by spectrophotometry, and the true concentration was bound to the image acquired from the same colorimetric sample. The continuous concentration values were determined as the training true concentration labels. The concentration unit was mg / L in the training process, model validation process and formal detection process. When the original record was expressed in g / mL, it was converted to mg / L according to the same value to keep the data units of model supervision input, model output and application detection results consistent.
[0024] The artificial intelligence model includes an image feature extraction network, a main regression branch, and a color constraint correction branch. The output of the image feature extraction network is connected to the main regression branch. The color constraint correction branch receives the color deviation features formed based on the current model prediction results and generates regression feature correction parameters that can enter the main regression branch.
[0025] The image feature extraction network adopts the EfficientNet-B0 network, removes the original network classification output part, and uses the data after global average pooling as the output of the image feature extraction network. The image feature extraction network receives a three-channel color image with a size of 2242243 and outputs 1280-dimensional deep image features. The deep image features record the deep visual information formed by the color distribution, brightness and darkness distribution and local spatial changes in the color region.
[0026] The main regression branch consists of a first regression layer, a second regression layer, and a concentration output layer connected in sequence. The first regression layer maps 1280-dimensional deep image features to 512-dimensional first regression features, followed by 512-dimensional batch normalization, ReLU nonlinear activation, and random deactivation processing, with the random deactivation probability set to 0.4.
[0027] The second regression layer maps the 512-dimensional first regression feature to a 128-dimensional regression feature, and then performs 128-dimensional batch normalization, ReLU nonlinear activation, and random deactivation in sequence, with the random deactivation probability set to 0.2.
[0028] The concentration output layer receives 128-dimensional input data and maps it to a continuous concentration value. The output concentration is limited to greater than or equal to 0 by Softplus non-negative activation.
[0029] Batch normalization is performed by calculating the mean and variance of the corresponding feature dimensions for each training batch, and adjusting the corresponding features of the current batch to a uniform data scale according to the mean and variance. At the same time, the network's ability to adjust to different feature dimensions is preserved through trainable scaling and offset. ReLU nonlinear activation sets negative values in the input data to zero and retains positive values. Random deactivation is performed by randomly disabling some feature nodes according to the corresponding deactivation probability only during the training phase. During the model validation and formal detection phases, random deactivation is turned off and the complete network nodes are used for inference.
[0030] The color constraint correction branch receives five-dimensional color deviation features. It first completes the joint mapping of five-dimensional color deviation information through a fully connected feature mapping layer with 32 output nodes. After ReLU activation, it enters two parallel 128-node parameter generation layers. The first parameter generation layer outputs 128-dimensional scale correction parameters, and the second parameter generation layer outputs 128-dimensional offset correction parameters. The scale correction parameters and offset correction parameters together constitute the regression feature correction parameters. Both parameter outputs correspond one-to-one with the 128-dimensional regression features in dimensional order.
[0031] In this embodiment, the scale correction parameter is limited to the range of 0.88 to 1.12, and the offset correction parameter is limited to the range of -0.10 to 0.10. When modulating the 128-dimensional regression features, the scale correction parameter is first used to adjust the scale of the current regression features according to the same dimension, and then the corresponding offset correction parameter is added. After all 128 dimensions are processed, a 128-dimensional corrected regression feature is formed, and the corrected regression feature is input into the concentration output layer to obtain the corrected concentration prediction result.
[0032] The basic data connection relationship of the artificial intelligence model is 2242243. After the input image feature extraction network of the colorimetric image to be tested, a 1280-dimensional deep image feature is formed. The 1280-dimensional deep image feature is passed through the first regression layer to form a 512-dimensional first regression feature. The 512-dimensional first regression feature is passed through the second regression layer to form a 128-dimensional regression feature. When the regression feature is directly input into the concentration output layer, an initial concentration prediction result is generated. The initial concentration prediction result is then used to obtain the corresponding standard colorimetric state and form a five-dimensional colorimetric deviation feature. The colorimetric deviation feature is passed through the color constraint correction branch to generate scale correction parameters and offset correction parameters, which are then applied to the regression feature. Finally, the corrected concentration prediction result is obtained based on the corrected regression feature.
[0033] When training the artificial intelligence model, the colored region images in the model training sample set are uniformly adjusted to 224224 pixels. The total training cycle of the model is set to 60, the batch size is set to 16, the initial learning rate is set to 110^-4, the random seed is set to 42, the existing model weights of EfficientNet-B0 are loaded as the initial network parameters of the image feature extraction network, and the Adam optimizer is used to perform model parameter updates.
[0034] The first to 40 training cycles are defined as the first training phase. In the first training phase, the color constraint correction branch is temporarily stopped from participating in the model output. Each training image passes through the image feature extraction network, the first regression layer, the second regression layer, and the concentration output layer in sequence to obtain the initial concentration prediction result. The initial concentration prediction result is compared with the training true concentration label corresponding to the current sample. The Smooth L1 loss is used to record the continuous concentration prediction error. Then, the trainable parameters in the image feature extraction network and the main regression branch are updated through backpropagation.
[0035] The 41st to 60th training cycles are defined as the second training phase. In the second training phase, the color constraint correction branch is enabled. Each training image first obtains the initial concentration prediction result through the main regression branch. Then, based on the initial concentration prediction result, the corresponding reference color features are obtained from the standard color rendering relationship. The five-dimensional color information actually extracted from the current training image is compared with the reference color features to obtain the five-dimensional color rendering deviation features. Then, the color constraint correction branch forms 128-dimensional scale correction parameters and 128-dimensional offset correction parameters. After using the two parameters to perform dimension-by-dimensional feature modulation on the regression features, the corrected regression features and the corrected concentration prediction results are obtained.
[0036] In the second training phase, the Smooth L1 loss between the corrected concentration prediction result and the training true concentration label is used as the main training error and weighted at 1. The Smooth L1 loss between the initial concentration prediction result and the training true concentration label is used as the auxiliary training error and weighted at 0.25. At the same time, the reference color features are re-obtained based on the corrected concentration prediction result, and five normalized color deviation values are re-formed. The average of the absolute values of the five normalized color deviation values is used as the color constraint training error and weighted at 0.08. Backpropagation and network parameter updates are completed together based on the three parts of training error.
[0037] The initial learning rate for the second training phase is set to 510^-5. When the mean absolute error corresponding to the model validation sample set does not continue to decrease for 5 consecutive training cycles, the current learning rate is adjusted to 50% of the original learning rate, and the lower limit of the learning rate is set to 110^-6. After each training cycle, the mean absolute error is calculated using the model validation sample set, and the complete network parameters corresponding to the lowest validation mean absolute error are retained as the network parameters used for formal detection.
[0038] After the artificial intelligence model is trained, the network parameters of the image feature extraction network, the main regression branch, and the color constraint correction branch are frozen. Then, the judgment parameters used in the formal detection stage are determined using the model validation sample set. The parameter determination work is carried out separately after the model network parameters are fixed, so as to keep the determination process of model training parameters and detection judgment parameters distinct from each other.
[0039] Specifically, the model validation sample set was divided into three concentration ranges: 0–1 mg / L, 1–4 mg / L, and 4–10 mg / L. The absolute error between the model-predicted concentration and the corresponding actual concentration of each validation sample was calculated. The samples were then arranged in ascending order of absolute error for each concentration range. The upper limit of the absolute error that could cover 95% of the validation samples in the corresponding concentration range was taken as the basic error range for that concentration range. In this embodiment, based on the validation data, three basic error ranges of 0.05 mg / L, 0.08 mg / L, and 0.12 mg / L were obtained.
[0040] Verification samples whose actual concentration error is within the corresponding basic error range are used as valid verification data in threshold calibration. Verification samples whose actual concentration error exceeds the corresponding basic error range are used as threshold reverse verification data. For all verification samples, the corrected colorimetric deviation, deviation change ratio, maximum and minimum concentration difference formed by multiple equivalent concentration prediction results, and the average absolute difference of equivalent predictions are recorded. Verification is performed step by step using pre-given candidate thresholds.
[0041] For the allowable deviation range, starting from 0.60, the candidate upper limit value is increased sequentially in steps of 0.05. For each candidate upper limit value, the proportion of valid verification data entering the normal color constraint range and the proportion of threshold reverse verification data entering the normal color constraint range are statistically analyzed. The maximum candidate upper limit value is selected where the coverage ratio of valid verification data is not less than 95% and the error entry ratio of threshold reverse verification data is not higher than 5%. In this embodiment, 0.85 is finally obtained. Therefore, 0 to 0.85 is fixed as the allowable deviation range.
[0042] For the convergence condition, the concentration error changes of the verification samples in the next round are statistically analyzed after the corrected color deviation amount enters the allowable deviation range, and the deviation change ratio is less than 1 and not less than 1. Among them, the deviation change ratio is less than 1, which corresponds to the current color deviation shrinking relative to the previous color deviation. According to the verification results, the corrected color deviation amount being within the allowable deviation range and the deviation change ratio being less than 1 are fixed as the convergence condition for color constraint correction. If any condition is not met, the non-converged state is maintained.
[0043] For the first adjustment coefficient, three verification intervals were defined according to the deviation change ratio: no greater than 0.75, greater than 0.75 but no greater than 0.90, and greater than 0.90 but less than 1. Within each verification interval, 1.02, 1.04, 1.06, 1.08, and 1.10 were used as candidate adjustment coefficients for the next round of feature modulation, respectively. The proportion of samples whose color deviation fell within the allowable deviation range after the next round of correction was counted. At the same time, the absolute error of the average concentration after adjustment was checked. Candidate values with a high proportion of samples falling within the allowable deviation range and whose absolute error of the average concentration was not higher than the result before adjustment were selected. Finally, 1.08, 1.04, and 1.02 were fixed as the first adjustment coefficients for the three intervals, respectively.
[0044] For the second adjustment coefficient, three verification intervals were defined according to the deviation change ratio being greater than or equal to 1 and less than 1.10, greater than or equal to 1.10 and less than 1.25, and not less than 1.25. The next round of correction verification was carried out using 0.40, 0.60, and 0.80, respectively. Based on the proportion of color deviation entering the allowable deviation range after the next round of correction and the change in absolute concentration error, the three intervals were finally fixed at 0.80, 0.60, and 0.40 as the second adjustment coefficients, respectively.
[0045] For the allowable range of predicted dispersion, in validation samples below 1 mg / L, 0.06, 0.07, 0.08, 0.09, and 0.10 mg / L were used as candidate upper limits for the maximum and minimum concentration differences, respectively, and 0.03, 0.04, and 0.05 mg / L were used as candidate upper limits for the equivalent predicted mean absolute difference. The coverage ratio of valid validation data and the entry ratio of threshold reverse verification data were statistically analyzed for each candidate combination. Finally, the allowable range for low-concentration samples was fixed as the maximum and minimum concentration difference not exceeding 0.08 mg / L and the equivalent predicted mean absolute difference not exceeding 0.04 mg / L.
[0046] For validation samples with a concentration of not less than 1 mg / L, candidate upper limits for the maximum and minimum concentration differences are set at 5%, 6%, 7%, 8%, and 9% of the corrected concentration prediction results, respectively. Candidate upper limits for the equivalent prediction mean absolute difference are set at 2.5%, 3.0%, 3.5%, 4.0%, and 4.5%, respectively. According to the same validation rules, the maximum and minimum concentration differences are determined to be no more than 7% of the corrected concentration prediction results, and the equivalent prediction mean absolute difference is determined to be no more than 3.5% of the corrected concentration prediction results, which are then taken as the final allowable range. After the above parameter calibration is completed, each judgment parameter is fixed and saved. The formal detection stage is carried out according to the fixed parameters.
[0047] When establishing standard color relationships using a standard color calibration sample set, the average values of the red channel, green channel, blue channel, saturation, and lightness in the HSV color space are extracted from 20 standard color samples at the same concentration level. The average value of each color information is calculated, and the average value is determined as the color feature center value of the corresponding concentration. At the same time, the standard deviation of the corresponding color information in the 20 samples is calculated, and twice the standard deviation is determined as the corresponding color feature fluctuation range.
[0048] When the color feature fluctuation range of the red channel, green channel or blue channel is less than 1 gray value, it is recorded as 1 gray value. When the color feature fluctuation range of saturation or brightness is less than 0.01, it is recorded as 0.01, so as to limit the amplification of the subsequent color deviation by the fluctuation of the smallest sample. A set of standard color rendering relationships established in this embodiment is shown in Table 1.
[0049] Table 1: Data on the Relationship of Standard Color Development for Different Nitrite Concentrations Nitrite concentration (mg / L) Red Channel Green Channel Blue Channel Saturation Brightness 0.00 2396 2387 2377 0.0180.012 0.9380.021 0.10 2405 2308 2289 0.0510.016 0.9410.020 0.25 2396 2169 21110 0.1190.022 0.9360.024 0.50 2387 19810 19011 0.2010.028 0.9290.026 1.00 2367 17611 16512 0.3010.033 0.9200.029 2.00 2328 15312 14013 0.3970.036 0.9070.031 4.00 2279 12713 11514 0.4930.040 0.8880.034 6.00 2229 11114 10315 0.5420.043 0.8720.036 8.00 21710 9915 9516 0.5790.045 0.8560.039 10.00 21311 9116 8917 0.6030.047 0.8410.041 As shown in Table 1, each standard concentration corresponds to different color feature center values and color feature fluctuation ranges. Among them, the green and blue channels decrease as the nitrite concentration increases, the saturation increases as the nitrite concentration increases, and the brightness decreases as the nitrite concentration increases. At the same time, there are still limited color fluctuations at the same concentration. Therefore, the standard color development relationship preserves both the typical color state and the normal color change range related to the concentration.
[0050] When it is necessary to determine the reference color feature based on continuous concentration, first determine the two adjacent standard concentration nodes where the current initial concentration prediction result is located. Then, based on the position ratio of the current initial concentration prediction result between the two adjacent standard concentrations, perform linear interpolation on the center values and fluctuation ranges of the five color features corresponding to the two standard concentrations respectively. Finally, determine the interpolated center values and the corresponding fluctuation ranges of the five color features as the reference color feature corresponding to the current concentration.
[0051] During formal testing, step S1 is executed. The sample to be tested, after color development and standing for 5 minutes, is placed in a light-shielding calibration card with a white calibration area. The original color image is acquired after automatic focusing and exposure via a mobile terminal. The average values of the red channel, green channel, and blue channel in the white calibration area are read. In this embodiment, the target center value of the three standard white channels is set to 240, and 235 to 245 is set as the allowable range. When the average value of any channel is outside the allowable range, the pixel value of the corresponding color channel in the entire original color image is adjusted according to the proportional relationship between the current channel average value and the target center value, and the adjusted pixel value is limited to the range of 0 to 255.
[0052] After completing the light calibration, a 33 median filter is used to remove local isolated pixel noise. Then, color normalization is performed according to the model input requirements. The continuous longitudinal edges on the left and right sides of the transparent colorimetric container and the position of the liquid surface are detected. Candidate liquid areas are determined between the left and right edges of the container and below the liquid surface. The candidate liquid areas are shrunk inward by 10% of the container width to the left and right respectively. 8% of the height of the liquid area is removed from the liquid surface downwards and 8% of the height of the liquid area is removed from the bottom of the container upwards. The remaining continuous liquid area is determined as the color development area and adjusted to 224224 pixels to obtain the color development image to be tested.
[0053] The average values of the red channel, green channel, and blue channel, as well as the average values of saturation and brightness in the HSV color space, are calculated from the color region corresponding to the color image to be tested. The five-dimensional color features to be tested are formed in a fixed order of red channel, green channel, blue channel, saturation, and brightness. The pixel data entering the image feature extraction network is normalized to the range of 0 to 1. The red, green, and blue channels used for the standard color relationship are kept at a scale of 0 to 255, while the saturation and brightness are kept at a scale of 0 to 1.
[0054] When executing S2, the colorimetric image to be tested is input into the image feature extraction network to obtain 1280-dimensional deep image features. The deep image features are then input into the first regression layer to obtain 512-dimensional first regression features, and then into the second regression layer to obtain 128-dimensional regression features. The regression features are then input into the concentration output layer to obtain the initial concentration prediction result corresponding to the current sample to be tested.
[0055] When executing S3, reference color features are obtained from the standard colorimetric relationship based on the initial concentration prediction results. The red, green, blue, saturation, and lightness of the color features to be tested are compared with the corresponding color feature center values in the reference color features. The directional information of whether the actual color value is higher or lower than the color feature center value is retained. Then, the normalized color deviation value is determined according to the proportional relationship between each color difference and the corresponding color feature fluctuation range. When the actual color value is higher than the corresponding color feature center value by one color feature fluctuation range, it is recorded as positive 1, and when it is lower than one color feature fluctuation range, it is recorded as negative 1. In other cases, the corresponding positive or negative value is determined according to the ratio of the actual difference to the color feature fluctuation range. The five normalized color deviation values are combined in a fixed order to form a five-dimensional colorimetric deviation feature.
[0056] After the five-dimensional color deviation feature is input into the color constraint correction branch, it passes through a 32-node fully connected feature mapping layer and ReLU activation to form intermediate color deviation information. Then, it passes through two 128-node parameter generation layers to form scale correction parameters and offset correction parameters. The 128-dimensional regression feature is adjusted dimension by dimension using the two parameters to obtain the 128-dimensional corrected positive regression feature. The corrected regression feature is then re-input into the concentration output layer to obtain the corrected concentration prediction result.
[0057] When executing S4, the absolute values of the five normalized color deviations formed in the first instance are taken respectively, and the average value of the five absolute values is calculated. The average value is determined as the color deviation before correction. Then, based on the predicted result of the corrected concentration, the standard color relationship is queried again and the reference color feature is re-determined. The five-dimensional color deviation feature is updated according to the same color comparison and normalization method. The average value of the five normalized color deviations after the update is calculated, and the average value is determined as the color deviation after correction.
[0058] The deviation change ratio is determined by dividing the corrected color deviation by the original color deviation. When the original color deviation is less than 0.01, 0.01 is used as the minimum reference for the ratio calculation. When the corrected color deviation is not greater than 0.85 and the deviation change ratio is less than 1, the color constraint correction is determined to meet the convergence condition, and then the equivalent image transformation process is entered.
[0059] When the deviation change ratio is less than 1 and the corrected colorimetric deviation is still higher than 0.85, the first adjustment coefficient is selected according to the range of the deviation change ratio. Specifically, 1.08 is used when the deviation change ratio is not greater than 0.75, 1.04 is used when the deviation change ratio is greater than 0.75 but not greater than 0.90, and 1.02 is used when the deviation change ratio is greater than 0.90 but less than 1.
[0060] When adjusting the scale correction parameters using the first adjustment coefficient, the difference between the scale correction parameters of each dimension and 1 is obtained. The difference is multiplied by the corresponding first adjustment coefficient and then added back to 1, while maintaining the original positive and negative directions of the difference. When adjusting the offset correction parameters using the first adjustment coefficient, the current offset correction parameters of each dimension are multiplied by the first adjustment coefficient while maintaining the original positive and negative directions. The updated scale correction parameters continue to be limited to the range of 0.88 to 1.12, and the offset correction parameters continue to be limited to the range of -0.10 to 0.10. Then, the updated regression feature correction parameters are used to regenerate the corrected regression features and corrected concentration prediction results.
[0061] When the deviation change ratio is not less than 1, the second adjustment coefficient is selected according to the range of the deviation change ratio. Specifically, 0.80 is used when the deviation change ratio is greater than or equal to 1 and less than 1.10, 0.60 is used when the deviation change ratio is greater than or equal to 1.10 and less than 1.25, and 0.40 is used when the deviation change ratio is not less than 1.25. Then, the correction magnitude of the scaling correction parameter relative to 1 and the absolute correction magnitude of the offset correction parameter are compressed using the second adjustment coefficient, and the corrected regression characteristics and corrected concentration prediction results are obtained again.
[0062] In this embodiment, the maximum number of executions of color constraint correction is set to 3. After each correction, the reference color features are obtained again based on the new correction concentration prediction results, and the color deviation features, the amount of color deviation after correction, and the deviation change ratio are recalculated. When the convergence condition is met, the color constraint correction ends. If the convergence condition is not met after 3 consecutive attempts, the light calibration, noise reduction, color normalization, and color region extraction are re-executed. After the image standardization process is completed again, the model inference is executed again. If the convergence condition is not met after the reprocessing, the color image to be tested is re-acquired.
[0063] After the color constraint correction meets the convergence condition, an equivalent image transformation is performed on the original color image to be tested, which preserves the meaning of the color concentration of the color region. In this embodiment, eight equivalent transformation images are generated, namely, shifted 4 pixels to the left, shifted 4 pixels to the right, shifted 3 pixels up, shifted 3 pixels down, scaled and resampled at 96% of the original size and centered, scaled and resampled at 104% of the original size and centered, restored to 224224 pixels after retaining 94% of the center of the color region, and restored to 224224 pixels after retaining 96% of the center of the color region. All equivalent image transformations preserve the data relationship of the red, green, and blue channels, saturation, and brightness of the original image, and only change the spatial position, scale, or cropping range of the color region in the input image.
[0064] Eight equivalent transformed images are input into an artificial intelligence model with fixed parameters. Each equivalent transformed image undergoes the same image feature extraction, initial concentration regression, and color constraint correction process as the original colorimetric image to be tested, resulting in an equivalent concentration prediction result. A total of eight equivalent concentration prediction results are formed.
[0065] The eight equivalent concentration prediction results are arranged according to their concentration values. The difference between the maximum and minimum concentration values is taken and determined as the maximum-minimum concentration difference. At the same time, the absolute difference between the eight equivalent concentration prediction results and the original corrected concentration prediction results is calculated. The average of the eight absolute differences is then calculated and determined as the equivalent prediction average absolute difference. The maximum-minimum concentration difference and the equivalent prediction average absolute difference are used to characterize the prediction dispersion.
[0066] When the corrected concentration prediction result is less than 1 mg / L, the prediction dispersion is considered to be within the allowable range if the maximum and minimum concentration difference does not exceed 0.08 mg / L and the equivalent prediction average absolute difference does not exceed 0.04 mg / L. When the corrected concentration prediction result is not less than 1 mg / L, the prediction dispersion is considered to be within the allowable range if the maximum and minimum concentration difference does not exceed 7% of the corrected concentration prediction result and the equivalent prediction average absolute difference does not exceed 3.5% of the corrected concentration prediction result.
[0067] When executing S5, if the color constraint correction meets the convergence condition and the prediction dispersion is within the allowable range, the detection reliability result is determined to meet the output condition, and the correction concentration prediction result corresponding to the original color image to be tested is determined as the detection concentration.
[0068] For the detection confidence level, it is set to 0.95 when the corrected colorimetric deviation is no greater than 0.50 and the equivalent predicted mean absolute difference does not exceed 50% of the upper limit of the current concentration; it is set to 0.90 when the corrected colorimetric deviation is greater than 0.50 but no greater than 0.70 and the equivalent predicted mean absolute difference does not exceed 75% of the upper limit of the current concentration; and the remaining detection results that meet the output conditions for detection reliability and have a corrected colorimetric deviation of no greater than 0.85 are set to 0.85.
[0069] For the concentration error range, the corresponding basic error range is obtained according to the concentration range in which the current detected concentration is located. When the equivalent predicted average absolute difference is in the first 50% of the corresponding allowable range, the corresponding basic error range is adopted. When the equivalent predicted average absolute difference is in the last 50% of the corresponding allowable range and does not exceed the allowable range, the corresponding basic error range is expanded by 20%, and the obtained range is determined as the current concentration error range.
[0070] When the color constraint correction meets the convergence condition but the prediction dispersion exceeds the allowable range, the detection reliability result is determined as not meeting the output condition and the color image to be tested is reacquired. When the color constraint correction does not meet the convergence condition, the regression feature correction parameters are re-determined according to the first adjustment coefficient or the second adjustment coefficient corresponding to the deviation change ratio. After reaching the maximum number of corrections, the image standardization process is performed again or the color image to be tested is reacquired according to the aforementioned rules.
[0071] To verify the detection effect of this embodiment, 12 additional colorimetric samples that did not participate in the training of the artificial intelligence model, the parameter calibration of the model validation sample set, and the establishment of the standard colorimetric relationship were selected to form an independent test sample set. The corresponding reference concentration was obtained by spectrophotometry. A first control method and a second control method were set up. The first control method adopted the same EfficientNet-B0 network structure as in this embodiment, with 512-dimensional, 128-dimensional and single-concentration output, and directly used the main regression branch to form the concentration result. The second control method used the red channel, green channel, blue channel, saturation and brightness as input and used support vector regression to form the concentration result. The data shown in Table 2 were obtained.
[0072] Table 2: Comparison of Concentration Prediction Results under Different Sample Detection Conditions sample Sample type Reference concentration (mg / L) Second control method (mg / L) First control method (mg / L) The concentration detected in this embodiment is (mg / L). Color deviation before correction Corrected colorimetric deviation Equivalent prediction mean absolute difference (mg / L) V01 drinking water sample 0.12 0.15 0.13 0.13 0.88 0.52 0.018 V02 Pickled product extract 0.18 0.21 0.22 0.19 1.12 0.68 0.027 V03 drinking water sample 0.27 0.31 0.25 0.26 0.76 0.48 0.021 V04 Aquaculture water samples 0.43 0.39 0.47 0.45 1.21 0.73 0.034 V05 Pickled product extract 0.68 0.73 0.63 0.66 0.97 0.61 0.029 V06 Meat product extract 0.95 0.89 0.96 0.98 1.09 0.66 0.035 V07 Meat product extract 1.32 1.43 1.26 1.29 0.84 0.55 0.029 V08 Pickled product extract 1.85 1.71 1.94 1.89 1.18 0.72 0.041 V09 Aquaculture water samples 2.70 2.86 2.76 2.74 1.03 0.59 0.055 V10 Pickled product extract 4.20 4.39 4.10 4.14 0.91 0.57 0.082 V11 Meat product extract 6.10 5.88 6.14 6.18 1.15 0.69 0.110 V12 Meat product extract 8.40 8.66 8.23 8.29 0.89 0.54 0.160 Based on the data in Table 2, the average absolute error of the second control method is 0.111 mg / L, the root mean square error is approximately 0.136 mg / L, and the average relative error is approximately 9.38%. The average absolute error of the first control method is approximately 0.058 mg / L, the root mean square error is approximately 0.072 mg / L, and the average relative error is approximately 6.03%. The average absolute error of this embodiment is approximately 0.038 mg / L, the root mean square error is approximately 0.048 mg / L, and the average relative error is approximately 3.19%. The average absolute error of this embodiment is reduced by approximately 33.3% compared to the first control method. At the same time, the corrected colorimetric deviations in V02, V04, V08, and V11 all fall within the allowable deviation range, indicating that the colorimetric deviation features, after participating in the regression feature modulation, can reduce the overall concentration prediction error of independent samples and improve the consistency between the predicted concentration and the standard colorimetric state.
[0073] In Table 2, V06 and V11 have smaller individual sample errors under the first control method, indicating that there are still local prediction fluctuations in different samples. From the mean absolute error, root mean square error and mean relative error of all tested samples, it can be observed that the overall error distribution decreases after adding the color constraint correction branch and subsequent feedback processing. Therefore, this embodiment forms a quantifiable improvement in concentration detection through data interaction between the image regression path and the standard color development color constraint path.
[0074] Example 2 This embodiment illustrates the process of further adjusting the regression feature correction parameters based on the data generated by the first correction when the convergence condition is not met after the first color constraint correction. The network structure, training method, standard color relationship, and judgment parameter calibration method of the artificial intelligence model are the same as those in Embodiment 1.
[0075] Eight independent samples that did not directly meet the convergence condition after the first color constraint correction were selected. Among them, the deviation change ratio of F01 to F04 was less than 1 and the color deviation after correction was still higher than 0.85. The deviation change ratio of F05 to F08 was not less than 1. The next regression feature correction parameters were adjusted according to the first adjustment coefficient and the second adjustment coefficient fixed in Example 1. The processed data are as follows.
[0076] Table 3: Parameter Adjustment Data Table During Color Constraint Feedback Correction Process sample Reference concentration (mg / L) Initial concentration prediction results (mg / L) Color deviation before correction Color deviation after first correction Deviation change ratio Adjust parameters Color deviation after second correction Final detection concentration (mg / L) F01 0.76 0.88 1.31 0.96 0.73 First adjustment coefficient: 1.08 0.72 0.79 F02 1.24 1.39 1.18 0.93 0.79 First adjustment coefficient: 1.04 0.78 1.27 F03 2.18 2.46 1.31 0.96 0.73 First adjustment coefficient: 1.08 0.71 2.21 F04 4.62 4.91 1.08 0.97 0.90 First adjustment coefficient: 1.04 0.81 4.68 F05 0.81 0.93 0.96 1.09 1.14 The second adjustment coefficient is 0.60. 0.82 0.84 F06 1.67 1.48 1.02 1.07 1.05 The second adjustment coefficient is 0.80. 0.76 1.62 F07 3.41 3.72 0.94 1.18 1.26 The second adjustment coefficient is 0.40. 0.80 3.48 F08 6.28 5.94 1.11 1.23 1.11 The second adjustment coefficient is 0.60. 0.83 6.19 Taking F03 as an example, the initial concentration prediction result was 2.46 mg / L. After obtaining the corresponding reference color feature according to the standard colorimetric relationship, a pre-correction colorimetric deviation of 1.31 was formed. After the first internal feature modulation, the post-correction colorimetric deviation decreased to 0.96 and formed a deviation change ratio of 0.73. The current color deviation has shrunk but is still higher than the upper limit of the allowable deviation range of 0.85. Therefore, based on the range where 0.73 is located, 1.08 was selected as the first adjustment coefficient. After readjusting the scale correction parameter and the offset correction parameter, the post-correction colorimetric deviation decreased to 0.71. The final detected concentration was 2.21 mg / L, and the absolute error between it and the reference concentration of 2.18 mg / L was 0.03 mg / L.
[0077] Taking F05 as an example, the color deviation before the first correction was 0.96, and the color deviation after the first correction was 1.09, forming a deviation change ratio of 1.14. According to the fixed parameter range in Example 1, 0.60 was selected as the second adjustment coefficient, and the correction magnitude of the scale correction parameter relative to 1 and the absolute correction magnitude of the offset correction parameter were compressed respectively. After the second feature modulation was completed, the color deviation after correction was reduced to 0.82 and entered the allowable deviation range. Then, the reliability verification was completed according to the equivalent image transformation and prediction dispersion judgment in Example 1.
[0078] Twenty samples that did not directly enter a stable output state after the first correction were further selected for processing. Among them, 7 samples met the convergence condition after the first color constraint correction. After the second correction was completed for the remaining 13 samples according to the deviation change ratio using the first adjustment coefficient or the second adjustment coefficient, 11 more samples met the convergence condition. The remaining 2 samples entered the third correction. After the third correction, the convergence condition was still not met, and the samples entered the image normalization processing branch according to Example 1. Thus, under the condition of limiting the maximum number of corrections, the internal feature modulation of the model can continue to be controlled according to the previous correction result.
[0079] The feedback data in this embodiment shows that the corrected concentration prediction results continue to participate in the update of the reference color features. The updated color deviation features form a deviation change ratio, which further controls the adjustment range of the regression feature correction parameters in the next round. This forms a data feedback relationship between the previous model correction results and the next internal feature modulation, and provides specific implementation support for the reflux correction defined in claims 6 and 7.
[0080] Example 3 This embodiment illustrates that after the color constraint correction has met the convergence condition, the prediction stability of the artificial intelligence model for different spatial representations of the same color rendering state is further judged by equivalent image transformation. The structure of the artificial intelligence model, the standard color rendering relationship, the color constraint correction process and the parameter calibration method are the same as in Embodiment 1.
[0081] Ten independent colorimetric samples that have met the convergence criteria were selected. The reference color characteristics of each sample were re-obtained based on the corrected concentration prediction results, and the colorimetric deviation after correction was confirmed to be within the allowable deviation range of 0 to 0.85. Subsequently, the eight equivalent image transformations described in Example 1 were performed on the colorimetric image corresponding to each sample, and eight equivalent concentration prediction results were obtained. The model input stability data are shown in Table 4.
[0082] Table 4: Data on independent colorimetric samples with convergence conditions sample Reference concentration (mg / L) Corrected concentration prediction results (mg / L) Corrected colorimetric deviation Maximum and minimum concentration difference (mg / L) Equivalent prediction mean absolute difference (mg / L) Initial test reliability results Reprocessing results S01 0.46 0.45 0.58 0.05 0.020 Satisfy output conditions S02 1.26 1.29 0.63 0.07 0.025 Satisfy output conditions S03 3.05 3.08 0.62 0.31 0.120 Output conditions not met After re-capturing the image, it meets the requirements. S04 2.44 2.48 0.71 0.14 0.061 Satisfy output conditions S05 4.18 4.11 0.55 0.20 0.083 Satisfy output conditions S06 5.62 5.68 0.64 0.47 0.205 Output conditions not met After re-capturing the image, it meets the requirements. S07 6.84 6.91 0.60 0.27 0.098 Satisfy output conditions S08 7.23 7.14 0.68 0.58 0.246 Output conditions not met After re-collecting the images, the requirements are met. S09 0.72 0.74 0.49 0.06 0.026 Satisfy output conditions S10 3.66 3.70 0.73 0.16 0.064 Satisfy output conditions Taking S03 as an example, after color constraint correction, the corrected concentration prediction result is 3.08 mg / L and the corrected color development deviation is 0.62. The current result has met the convergence condition of color constraint correction. The eight equivalent concentration prediction results are 2.92, 2.98, 3.04, 3.07, 3.13, 3.16, 3.19 and 3.23 mg / L, respectively, with a maximum and minimum concentration difference of 0.31 mg / L and an equivalent prediction average absolute difference of 0.12 mg / L. These exceed the allowable upper limits of 7% and 3.5% under the current concentration condition of 3.08 mg / L, respectively. Therefore, the detection reliability result is determined to be that the output condition is not met and the color development image to be tested is reacquired.
[0083] After re-acquiring the S03 image, the same detection procedure was executed again, and the concentration prediction result was corrected to 3.07 mg / L. The eight new equivalent concentration prediction results were distributed between 3.01 and 3.14 mg / L, the maximum and minimum concentration difference was reduced to 0.13 mg / L, and the average absolute difference of equivalent predictions was reduced to 0.05 mg / L. Both data were within the allowable range corresponding to the current concentration, and the detection reliability result was then determined to meet the output conditions.
[0084] S06 and S08 have the same type of detection state. After S06 reacquires the colorimetric image to be tested, the equivalent predicted mean absolute difference decreases from 0.205 mg / L to 0.112 mg / L. After S08 reacquires the colorimetric image to be tested, the equivalent predicted mean absolute difference decreases from 0.246 mg / L to 0.137 mg / L. They both fall within the allowable range specified for their respective concentration intervals.
[0085] Of the 10 samples, all samples met the convergence conditions of color constraint correction in terms of the amount of color deviation and the ratio of deviation change after correction. After further adding the prediction dispersion judgment, three samples, S03, S06 and S08, entered the re-imaging branch. After re-imaging, the absolute concentration error of the three samples was adjusted from 0.03, 0.06 and 0.09 mg / L to 0.02, 0.04 and 0.05 mg / L, respectively, and the prediction dispersion was within the allowable range.
[0086] The above processing shows that the corrected color deviation records the consistency between the model's predicted concentration and the actual color, while the predicted dispersion records the stability of the AI model's output after the same color state has been expressed in different spaces. These two data points come from different processing stages and jointly participate in determining the reliability of the detection results, thereby further verifying the stability of the model input for the concentration results where the color constraints have converged.
[0087] Example 4 This embodiment illustrates the implementation process of light calibration, standard colorimetric relationship and color constraint correction branch continuously participating in concentration detection under different mobile terminals and different lighting conditions. The network structure, training method, threshold determination method and equivalent image transformation of the artificial intelligence model are the same as in Embodiment 1.
[0088] Fifteen independent colorimetric samples with concentrations ranging from 0.20 to 8.00 mg / L were selected. Images of each sample were acquired using three mobile terminals with different camera modules, under standard white light, warm LED light, and natural diffused light conditions, resulting in a total of 135 test images. The three mobile terminals were designated as the first mobile terminal, the second mobile terminal, and the third mobile terminal.
[0089] Under standard white light conditions, the average values of the red, green, and blue channels obtained by the first mobile terminal from the white calibration area are 241, 239, and 240, respectively. Under warm LED conditions, the average values of the three channels obtained by the second mobile terminal are 247, 232, and 221, respectively. Under natural diffused light conditions, the average values of the three channels obtained by the third mobile terminal are 234, 241, and 248, respectively. This results in different input states where the overall color reference is close to the standard, warm color shift is more obvious, and cool color shift is more obvious.
[0090] The results of 135 test images were recorded in three consecutive stages. In the first stage, the concentration results formed by the main regression branch were recorded directly after automatic exposure. In the second stage, the concentration results formed by the main regression branch were recorded after the light calibration, noise reduction and color normalization of the white calibration area were completed. In the third stage, the standard color relationship query, color deviation feature formation, color constraint correction branch processing and color constraint feedback were performed, and the final detected concentration was recorded. The statistical results obtained under different mobile terminals and lighting conditions are shown in Table 5.
[0091] Table 5: Validation data of detection results under different image acquisition conditions Data collection conditions Mean absolute error (mg / L) in the first treatment stage Mean absolute error (mg / L) in the second treatment stage Mean absolute error (mg / L) in the third treatment stage The average relative error in the third processing stage First mobile terminal + standard white light 0.061 0.047 0.039 3.1% First mobile terminal + warm LED 0.089 0.063 0.046 4.0% First mobile terminal + natural diffused light 0.073 0.054 0.043 3.6% Second mobile terminal + standard white light 0.072 0.052 0.041 3.4% Second mobile terminal + warm LED 0.112 0.078 0.054 4.7% Second mobile terminal + natural diffused light 0.086 0.060 0.047 3.9% Third mobile terminal + standard white light 0.068 0.050 0.040 3.3% Third mobile terminal + warm LED 0.104 0.074 0.052 4.5% Third mobile terminal + natural diffused light 0.091 0.064 0.049 4.1% The data above shows that the average absolute error in the first processing stage was 0.061–0.112 mg / L under nine different terminal and lighting combinations. After the second processing stage, the error decreased to 0.047–0.078 mg / L, and after the third processing stage, it decreased to 0.039–0.054 mg / L. This indicates that the front-end color reference adjustment and the color rendering constraint within the model act on different data processing positions and continuously reduce the concentration detection error under multiple terminal and multiple lighting input conditions.
[0092] Taking a 2.50 mg / L reference sample collected by the second mobile terminal under warm-color LED conditions as an example, the first processing stage yielded a concentration result of 2.78 mg / L. After completing light calibration and color normalization, the second processing stage yielded an initial concentration prediction result of 2.64 mg / L. Based on 2.64 mg / L, the corresponding reference color feature was obtained from the standard colorimetric relationship, resulting in a pre-correction color deviation of 1.06. After completing the color constraint correction branch processing, a corrected concentration prediction result of 2.55 mg / L and a post-correction color deviation of 0.67 were obtained. Finally, the absolute error between the detected concentration and the 2.50 mg / L reference concentration was 0.05 mg / L.
[0093] Taking a 5.00 mg / L reference sample collected by a third mobile terminal under natural diffused light conditions as an example, the first processing stage yielded a concentration result of 4.71 mg / L. After completing the second processing stage, an initial concentration prediction result of 4.84 mg / L was obtained. After processing by the standard colorimetric relationship query and color constraint correction branch, a corrected concentration prediction result of 4.94 mg / L was formed. At the same time, the colorimetric deviation before correction was 1.13, and the colorimetric deviation after correction was 0.72, and the convergence condition was met.
[0094] Further statistical analysis of 135 test images revealed that in the first processing stage, 19 images had an absolute concentration error exceeding 0.15 mg / L. In the second processing stage, this was reduced to 8 images, and in the third processing stage, it was reduced to 3 images. Two of these images were further re-acquired due to their prediction dispersion exceeding the allowable range, and they met the output conditions after re-acquisition. The remaining image still failed to meet the convergence condition after three consecutive color constraint corrections, so image standardization and image acquisition processing were re-executed according to Example 1.
[0095] Therefore, the color reference changes caused by different mobile terminals and different lighting conditions are first adjusted at the channel level through the white calibration area. The difference between the actual color rendering state after calibration and the standard color rendering state corresponding to the current predicted concentration continues to form color rendering deviation characteristics and enters the color constraint correction branch. The corrected concentration prediction results are then used for subsequent reliability judgment through color constraint feedback and prediction dispersion evaluation, thus forming a continuous processing process suitable for changes in on-site acquisition conditions of mobile terminals.
[0096] In summary, Example 1 fully discloses the necessary module hierarchy, connection relationships, input data specifications, feature dimensions, training sample sources, true concentration labels, training stages, training cycles, batch size, learning rate, optimizer, training error composition, standard color relationship establishment method, color deviation feature formation method, color constraint correction branch parameter generation method, correction regression feature formation method, convergence condition determination method, allowable deviation range calibration method, verification and selection method of the first and second adjustment coefficients, equivalent image transformation process, prediction dispersion calculation method, and allowable range calibration process of the artificial intelligence model. Example 2 further discloses the feedback adjustment process of regression feature correction parameters when the first color constraint correction is insufficient or the correction result deviates and expands. Example 3 further discloses the verification process of the equivalent concentration prediction result on the stability of the model input when the color constraint has converged. Example 4 further discloses the implementation status of front-end light calibration and continuous operation of internal color constraint of the model under different mobile terminals and different lighting conditions, thereby providing continuous and implementable specific support for the main technical nodes and their non-standard operating states defined in claims 1 to 9.
[0097] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention.
Claims
1. A color recognition and concentration determination method based on an artificial intelligence model, characterized in that, Includes the following steps: S1, image acquisition of the sample to be tested after the nitrite colorimetric reaction, and the colorimetric image to be tested is obtained by light calibration, noise reduction, color normalization and colorimetric region extraction, and the color features to be tested are extracted. S2, input the colorimetric image to be tested into the artificial intelligence model. The artificial intelligence model includes an image feature extraction network, a main regression branch and a color constraint correction branch. The image feature extraction network extracts deep image features, and the main regression branch forms regression features based on the deep image features to obtain the initial concentration prediction results. S3. Based on the initial concentration prediction results, the reference color features are determined from the standard color relationship. The color deviation features are obtained by comparing the color features to be tested with the reference color features. The color constraint correction branch generates regression feature correction parameters based on the color deviation features. The regression features are corrected and the corrected concentration prediction results are obtained. S4. Based on the corrected concentration prediction results, the reference color features are redefined and the color deviation features are updated. Based on the color deviation features before and after the correction, it is determined whether the color constraint correction has converged. When converged, the equivalent image transformation is performed on the color image to be tested. The equivalent transformed image is input into the artificial intelligence model to obtain multiple equivalent concentration prediction results. S5 determines the detection reliability result based on the dispersion of multiple equivalent concentration prediction results. When the output conditions are met, the corrected concentration prediction result is used as the detection concentration, and the detection confidence and concentration error range are determined. If the convergence is not achieved or the output conditions are not met, the colorimetric image to be tested is reacquired.
2. The color recognition and concentration determination method based on an artificial intelligence model according to claim 1, characterized in that, The main regression branch in the artificial intelligence model includes a first regression layer, a second regression layer, and a concentration output layer connected in sequence. The first regression layer obtains the first regression feature based on the deep image features; The second regression layer obtains the regression features based on the first regression feature; The color constraint correction branch is connected between the second regression layer and the concentration output layer. The regression feature correction parameter is applied to the regression feature to obtain the corrected regression feature, and the concentration output layer obtains the corrected concentration prediction result based on the corrected regression feature.
3. The color recognition and concentration determination method based on an artificial intelligence model according to claim 2, characterized in that, The image feature extraction network adopts the EfficientNet-B0 network. The first regression layer maps the deep image features into 512-dimensional first regression features, and performs batch normalization, nonlinear activation and random deactivation processing in sequence. The second regression layer maps the first regression feature to the 128-dimensional regression feature, and performs batch normalization, nonlinear activation and random deactivation processing in sequence; The concentration output layer maps the modified regression features to a single concentration value and obtains the modified concentration prediction result through a non-negative activation function.
4. The color recognition and concentration determination method based on an artificial intelligence model according to claim 1, characterized in that, The color features to be tested include the red channel information, green channel information, blue channel information, saturation, and brightness of the color region in the color image to be tested; Obtain the color features corresponding to standard colorimetric samples of different known concentrations, establish the standard colorimetric relationship based on the correspondence between the true concentration and color features of each standard colorimetric sample, and determine the center value and fluctuation range of color features corresponding to different concentrations respectively.
5. The color recognition and concentration determination method based on an artificial intelligence model according to claim 4, characterized in that, Based on the initial concentration prediction result, the corresponding color feature center value and color feature fluctuation range are determined in the standard colorimetric relationship. The colorimetric deviation feature is obtained based on the deviation of the color feature to be tested relative to the color feature center value and the corresponding color feature fluctuation range. The color constraint correction branch generates scale correction parameters and offset correction parameters based on the color deviation characteristics, modulates the regression features based on the scale correction parameters and the offset correction parameters to obtain the corrected regression features, and obtains the corrected concentration prediction result based on the corrected regression features.
6. The color recognition and concentration determination method based on an artificial intelligence model according to claim 5, characterized in that, The amount of color deviation before correction is determined based on the aforementioned color deviation characteristics; The reference color features are re-determined from the standard colorimetric relationship based on the corrected concentration prediction results; The color deviation feature is updated by comparing the color feature to be tested with the newly determined reference color feature, and the corrected color deviation amount is determined at the same time. When the corrected color deviation is within the allowable deviation range, and the change in the corrected color deviation relative to the original color deviation satisfies the convergence condition, the color constraint correction is determined to be converged.
7. The color recognition and concentration determination method based on an artificial intelligence model according to claim 6, characterized in that, When the color constraint correction has not converged, the deviation change ratio is determined based on the ratio of the corrected color deviation to the uncorrected color deviation. When the deviation change ratio is less than 1 and the corrected color deviation amount does not enter the allowable deviation range, the correction direction corresponding to the scale correction parameter and the offset correction parameter is maintained, and the correction amplitude of the next feature modulation is set to the product of the current correction amplitude and the first adjustment coefficient, where the first adjustment coefficient is not less than 1. When the deviation change ratio is not less than 1, the correction amplitude of the next feature modulation is set to the product of the current correction amplitude and the second adjustment coefficient, where the second adjustment coefficient is greater than 0 and less than 1, and the corrected regression feature and the corrected concentration prediction result are re-determined based on the adjusted scale correction parameter and the offset correction parameter.
8. The color recognition and concentration determination method based on an artificial intelligence model according to claim 7, characterized in that, After the color constraint correction converges, an equivalent image transformation is performed on the color image to be tested to maintain the meaning of color concentration in the color region, resulting in multiple equivalent transformed images. The equivalent image transformation includes at least one of position transformation, scale resampling, and region cropping; Multiple equivalent transformed images are input into the artificial intelligence model to obtain multiple equivalent concentration prediction results, and the prediction dispersion is determined based on the distribution of the multiple equivalent concentration prediction results relative to the corrected concentration prediction results.
9. The color recognition and concentration determination method based on an artificial intelligence model according to claim 8, characterized in that, The detection reliability result is determined based on the convergence state of the color constraint correction and the degree of prediction dispersion. When the color constraint correction converges and the prediction dispersion is within the allowable range, the corrected concentration prediction result is determined as the detection concentration, and the detection confidence and the concentration error range are determined based on the corrected color deviation and the prediction dispersion. When the color constraint correction converges and the predicted dispersion exceeds the allowable range, the color image to be tested is reacquired. When the color constraint correction fails to converge, the regression feature correction parameters are re-determined based on the change between the color deviation before and after the correction, or the image standardization process is re-performed on the color image to be tested.
10. A colorimetric concentration determination system based on an artificial intelligence model, applied to the colorimetric concentration determination method based on an artificial intelligence model as described in any one of claims 1-9, characterized in that, It includes an image acquisition and processing module, a concentration prediction module, a color constraint correction module, a feedback convergence control module, and a reliability evaluation module; The image acquisition and processing module acquires images of the sample after the nitrite color development reaction, and obtains the color development image of the sample after light calibration, noise reduction, color normalization and color development region extraction, and extracts the color features of the sample. The concentration prediction module inputs the colorimetric image to be tested into an artificial intelligence model. The artificial intelligence model includes an image feature extraction network, a main regression branch, and a color constraint correction branch. The image feature extraction network extracts deep image features, and the main regression branch forms regression features based on the deep image features to obtain the initial concentration prediction result. The color constraint correction module determines the reference color feature from the standard color rendering relationship based on the initial concentration prediction result, compares the color feature to be tested with the reference color feature to obtain the color rendering deviation feature, and the color constraint correction branch generates regression feature correction parameters based on the color rendering deviation feature to correct the regression feature and obtain the corrected concentration prediction result. The feedback convergence control module redetermines the reference color features and updates the color deviation features based on the corrected concentration prediction results. It determines whether the color constraint correction has converged based on the color deviation features before and after the correction. When convergence occurs, it performs an equivalent image transformation on the color image to be tested and inputs the equivalent transformed image into the artificial intelligence model to obtain multiple equivalent concentration prediction results. The reliability evaluation module determines the detection reliability result based on the dispersion of multiple equivalent concentration prediction results. When the output conditions are met, the corrected concentration prediction result is used as the detection concentration, and the detection confidence and concentration error range are determined. If the convergence is not achieved or the output conditions are not met, the colorimetric image to be tested is reacquired.
