Colorimetric analysis method of ion concentration detection test paper suitable for mobile phone App

By implementing the test strip colorimetric analysis method based on image processing on the smartphone app, the problems of high subjectivity and low accuracy of test strip colorimetric analysis in the prior art are solved, and convenient and accurate test strip color recognition is achieved, suitable for patients with color vision defects, and maintain high accuracy under different lighting environments.

CN119762455AActive Publication Date: 2025-04-04JILIN UNIVERSITY

Patent Information

Application Number
CN202411833805.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-13
Publication Date
2025-04-04
Estimated Expiration
2044-12-13

AI Technical Summary

Technical Problem

The existing test strip colorimetric analysis methods rely on artificial vision, and have problems such as high subjectivity, low accuracy and unsuitable for patients with color vision defects, especially in different lighting environments to detect the accuracy.

Method used

A test strip colorimetric analysis method based on image processing is designed, using a smartphone app for image acquisition and processing, invalid image filtering, ROI area segmentation, color correction and color information extraction are performed through digital image processing technology, and color similarity is calculated in combination with RGB, HSV, and Lab color spaces and test strip color recognition is performed through voting mechanism.

Benefits of technology

The convenience and accuracy of colorimetric analysis of test strips is achieved, the impact of user subjectivity on the detection results is reduced, and it is suitable for patients with color vision defects, and it maintains a high detection accuracy under different lighting environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119762455A_ABST
    Figure CN119762455A_ABST
Patent Text Reader

Abstract

The invention discloses a colorimetric analysis method of ion concentration detection test paper suitable for a mobile phone App, and belongs to the technical field of test paper colorimetric analysis. The method comprises the following steps: obtaining pictures after a test paper reference color block and a reagent block react with a to-be-detected ion solution through a camera, ensuring the quality of the acquired image through user operation guidance, performing color correction on the test paper image, performing complete reference color block ROI region image detection and extraction based on contour shape features, and determining the detection accuracy of the test paper based on the collinearity of the reference color block. The method comprises the following steps: performing reagent block ROI region image positioning extraction according to a full contour and other position geometrical relationship, extracting color information of a test paper reference color block and a reagent block color development region, calculating color similarity in RGB, HSV and Lab color spaces based on the color information, and performing test paper color identification according to a voting mechanism. The method can provide convenience for patients with color vision defects, has certain self-adaption to different light environments, can reduce the influence of subjectivity and the like on the accuracy of detection results, and is simple and rapid in detection process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of test paper colorimetric analysis, and in particular to a test paper colorimetric analysis detection method based on image processing. Background Art

[0002] The concentration detection of biochemical components is a key research topic in the field of medical and chemical analysis. In the detection of medical and physical examination institutions, test strips are often used to detect the concentration of components. Test strip component detection methods are also widely used in home care, health testing and other fields (such as urine routine, blood glucose test strips). Test strip methods mostly use colorimetric analysis based on color development reactions to achieve detection, and effectively analyze the content of the component to be tested by establishing a relationship between the chromaticity value and the concentration of the test object. However, the process of colorimetric analysis is prone to strong subjectivity due to its reliance on the user's visual sensory system, and the visual sensory system has limited perception of fine differences in color. In addition, the generation of human color vision is a complex process that is easily affected by various factors, and may even produce visual illusions and misjudgments that are difficult to detect. Secondly, in real life, there is a certain proportion of people who suffer from color vision abnormalities, such as red-blind color patients, congenital color vision disorder patients, color agnosia patients, and patients with visual system diseases, who have relatively weak color perception and discrimination abilities. For some older people, the visual system also has relatively poor information processing and color understanding abilities; therefore, the test strip combined with artificial visual inspection is not suitable for such people. Although existing image processing technology can perform certain color analysis, the accuracy of colorimetric analysis is limited without the addition of optical devices, and it is seriously affected by the lighting environment. Therefore, it is urgent to design an automatic detection colorimetric analysis method based on digital images. Summary of the invention

[0003] In order to improve the convenience and accuracy of the colorimetric analysis of the test paper, provide convenience for patients with color vision defects, and avoid misdetection caused by user subjectivity, the present invention proposes a colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App, obtains the test paper reference color block and the picture after the reagent block reacts with the ion solution to be tested through the camera, and completes the filtering of invalid images, ROI area image segmentation extraction, and color correction of the test paper image through a series of digital image processing technologies, and then extracts the color information of the test paper reference color block and the reagent block color development area, and then calculates the color similarity in RGB, HSV, and Lab color space based on the color information, and then performs test paper color recognition according to the voting mechanism. This method is deployed on a smart phone for the analysis and detection of sodium ion concentration, and image acquisition and image processing are completed on the mobile phone side, so that the result display can be realized, and at the same time, data recording, data analysis, data sharing and other functional expansions can be carried out efficiently and conveniently.

[0004] The technical solution adopted by the present invention is specifically as follows:

[0005] A colorimetric analysis method for ion concentration detection test strips suitable for mobile phone apps, the method steps are as follows:

[0006] Step 1: Follow the instructions for use of the test paper, place the reagent block and reference color block that have fully reacted with the test liquid and developed color in the App scanning box, and acquire the frame image I0(x,y) in real time;

[0007] Step 2: For the acquired frame image I0(x,y), calculate the pixel mean and standard deviation in the image to set the threshold, filter out invalid images, and prompt the user to adjust the light environment and re-capture the image until an image I1(x,y) that meets the set threshold is captured;

[0008] Step 3: When the camera collects images in a natural environment, it will be affected by the surrounding lighting environment and cause color deviation. Based on the grayscale world assumption, the gain is calculated according to the average grayscale value to adjust the color channel, eliminate the color deviation caused by uneven lighting, and make the image color balanced; then based on the perfect reflection theory, the reflection gain is calculated according to the maximum value of each channel, and the image I1(x, y) is color corrected so that the maximum value of each channel is close to and does not exceed 255, simulating the perfect reflection under ideal conditions and improving the accuracy of color extraction. The image after color correction is recorded as I(x, y).

[0009] Step 4: Perform mixed filtering, graying, local adaptive thresholding, opening and closing operations, and edge enhancement on the image I(x, y) to obtain the edge-enhanced image J(x, y) to reduce the probability of missed detection during contour search;

[0010] Step 5: Based on the image J(x, y), the reference color block ROI area r of the test paper in the image is extracted from the color-corrected image I(x, y) by using the shape contour feature. i (x, y), i = 0, 1, 2, 3 ..., m-1; where m is the number of reference color blocks. If all reference color blocks are not detected, repeat step 2 to recapture the image and prompt the user to adjust the shooting position and angle; according to the relationship between the contour area and the imaging distance, prompt the user to adjust the shooting distance so that the image size and clarity meet the set requirements;

[0011] Step 6: To facilitate image acquisition and analysis, the placement and angle of the test strip reagent block relative to the reference color block are set to be fixed and consistent during each test. Based on the image J(x,y), the reagent block boundary positioning method is used. According to the congruence and collinearity of the reference color block, an empirical formula is designed to extract the reagent block ROI area t(x,y) from the color-corrected image I(x,y);

[0012] Step 7: Use the jump point sampling mean method to calculate the reference color block ROI area r i(x, y), i = 0, 1, 2, 3..., m-1 respectively perform main color extraction and record it as C i , where m is the number of reference color blocks; the main color calculation of the reagent block ROI area t(x,y) is performed using the jump point sampling mean method, denoted as C t ;

[0013] Step 8: C is analyzed based on RGB, HSV, and Lab color spaces respectively. i and C t The color difference is calculated and the reference color that the reagent block is most similar to is determined based on a voting mechanism.

[0014] Preferably, the specific steps of calculating the pixel mean and standard deviation in the image to set the threshold, filter invalid images, and prompt the user to adjust the light environment and re-capture the image in step 2 are as follows:

[0015] The pixel mean is used to represent the average brightness of the entire image, and the standard deviation can reflect the pixel differences and the content of effective information in the image. The formulas for calculating the mean and standard deviation of image pixels are as follows:

[0016]

[0017] Among them, μ is the mean, I i is the grayscale value of the i-th pixel, and N is the total number of pixels.

[0018]

[0019] Where σ is the standard deviation of the image and μ is the mean.

[0020] Then, a threshold is set to filter out invalid images, prompting the user to adjust the light environment and re-capture images for subsequent detection to avoid affecting subsequent colorimetric analysis results.

[0021] Preferably, the hybrid filtering in step 4 is a median filtering based on Gaussian filtering high frequency enhancement, and the specific steps are as follows:

[0022] (1) First, calculate the Gaussian blurred image of the original image. The operation is shown in the following formula:

[0023] G(x,y)=GaussianBlur(I(x,y),k,σ)

[0024] Where GaussianBlur(·) represents the Gaussian blur operation, I(x,y) is the input image, k is the convolution kernel size, σ is the standard deviation of the Gaussian function, and G(x,y) is the image after Gaussian blur;

[0025] (2) Calculate the difference between the original image and the Gaussian blurred image, i.e., the high-frequency component, as shown in the following formula:

[0026] H(x,y)=I(x,y)-G(x,y)

[0027] Among them, H(x,y) is the high-frequency component image;

[0028] (3) Adjust the high frequency component to 3 times gain, as shown in the following formula:

[0029] H′(x,y)=g·H(x,y)

[0030] Where H′(x,y) is the image after gain, g is the gain factor, g=3.0;

[0031] (4) The enhanced high-frequency component is added to the blurred image to obtain the result of high-frequency enhancement, as shown in the following formula:

[0032] E(x,y)=I(x,y)+H′(x,y)

[0033] Among them, E(x,y) is the image after image superposition;

[0034] (5) Remove noise by median filtering, as shown in the following formula:

[0035] O(x,y)=MedianBlur(E(x,y),k size )

[0036] Among them, O(x,y) is the final output image after median filtering, k size is the convolution kernel size of the median filter (take k size =3×3).

[0037] Preferably, in step 5, based on the image J(x, y), a reference color block ROI region r is extracted from the color-corrected image I(x, y) by using shape contour features. i (x, y), i = 0, 1, 2, 3 ..., m-1, the steps are as follows:

[0038] (1) Initial screening of profile

[0039] The initial screening of contours is performed based on the edge-enhanced image J(x, y) with the help of contour area threshold, shape factor, compact value, and aspect ratio of the minimum circumscribed oblique rectangle, and the index set L1 for initial screening of contours is obtained by screening.

[0040] (2) Contour Second Screen

[0041] Arrange the contours in the L1 set in descending order based on the horizontal coordinates of the contour center points, extract and group the contours in the set L1 according to the number of reference color blocks, perform equidistant and collinearity judgments on the contours in each group, return a contour group index set that meets the conditions, and then calculate the Hu moments of the contours within the group for contour groups that meet the equidistant and collinearity judgments for contour matching, return a contour group index set L2 with the most similar contour Hu moments, and then perform rectangular fitting judgment on each contour. If it meets the conditions, it is the contour index set corresponding to the reference color block.

[0042] (3) Extract reference color block ROI

[0043] Draw a bounding rectangle according to the contour corresponding to the contour group index set L2. To avoid positioning errors caused by factors such as image distortion, the bounding rectangle indented at a certain ratio is used as the reference color block ROI area r to be extracted. i (x, y), i = 0, 1, 2, 3…, m-1; where m is the number of reference color blocks.

[0044] Preferably, in step 6, the method for extracting the reagent block ROI region location in the color-corrected image I (x, y) according to the congruence of the reference color blocks and the collinearity design empirical formula is as follows:

[0045] The horizontal positive direction is horizontal to the right, and the vertical positive direction is vertical downward. The coordinates of the center point of the reference color block are (centerX i , centerY i ), the reference color block width is width i , the reference color block height is height i , where i = 0, 1, 2, 3…, m-1; where m is the number of reference color blocks; according to the spatial position relationship and geometric relationship, it is easy to obtain:

[0046] centerX0 <centerX1<centerX2<...<centerX m-1

[0047] centerY0=centerY1=centerY2=…=centerY m-1

[0048] centerX1-centerX0=centerX2-centerX1=…=centerX m-1 -centerX m-2 >width i

[0049] The coordinates of the center point of the detection reagent block are recorded as (targetX, targetY). Since the target color reagent block can be approximated as a square, its side length is recorded as targetLength, and the empirical formula can be obtained:

[0050] targetLength=s*(height0+height1+…+height m-1 ) / m

[0051] targetX=centerX m-1 +a*width i +b*targetLength

[0052] targetY=(centerY0+centerY1+…+centerY m-1 ) / m

[0053] Where a and b are empirical coefficients, and s represents the scaling ratio.

[0054] According to the coordinates of the center point of the reagent block (targetX, targetY) and the side length targetLength as the boundary rectangle, in order to avoid positioning deviation caused by factors such as image distortion, it is indented at a certain ratio as the extracted reagent block ROI area t(x, y).

[0055] Preferably, in step 7, the step length is p, and the reference color block ROI area r i (x, y) and the effective pixels (i.e., pixels that do not cross the boundary) in the reagent block ROI area t(x, y), accumulate the three color channels of red, green, and blue, and sample every p pixels in the width and height of the image ROI area. According to the sum of the sampled colors, calculate the average value R of each color channel avg , G avg , B avg As the extracted main color value.

[0056] Preferably, in step eight, C is respectively analyzed based on RGB, HSV, and Lab color spaces. i and C t The method for calculating the color difference and determining the most similar reference color of the reagent block according to the voting mechanism is as follows:

[0057] (1) Calculate the weighted color difference in RGB color space

[0058] Assumption C 1,R ,C 1,G ,C 1,B Represents the red component, green component, and blue component of the first color sample (Color 1), respectively. 2,R ,C2,G ,C 2,B Represent the red component, green component, and blue component of the second color sample (Color 2) respectively:

[0059]

[0060] in, Represents the average of the red components of the first color sample (Color 1) and the second color sample (Color 2), which is used to adjust the color difference formula weight.

[0061] ΔR=C 1,R -C 2,R

[0062] ΔG=C 1,G -C 2,G

[0063] ΔB=C 1,B -C 2,B

[0064] Wherein, ΔR, ΔG, and ΔB represent the red component difference, green component difference, and blue component difference between the first color sample (Color 1) and the second color sample (Color 2).

[0065]

[0066] Where, ΔE RGB Represents the color difference between the first color sample (Color 1) and the second color sample (Color 2) using the weighted color difference method of the RGB color model.

[0067] (2) Calculate the color difference in HSV color space

[0068] Calculate the color distance. For two color samples, (h1, s1, v1) and (h2, s2, v2), calculate the corresponding coordinates (x1, y1, z1) and (x2, y2, z2) in the three-dimensional space. The formula for calculating the three-dimensional Euclidean distance is:

[0069]

[0070] Where, ΔE HSV Indicates the color distance calculated based on the HSV color model.

[0071] (3) Calculate the color difference in Lab color space

[0072] First convert the RGB color space to the CIE XYZ color space, then convert the XYZ color space to the Lab color space, and then calculate the perceived color difference using the CIEDE2000 color difference formula:

[0073]

[0074] Where, ΔE Lab Indicates the color difference value, ΔL′ represents the lightness difference, ΔC′ represents the corrected chroma difference, ΔH′ represents the hue difference after the corrected hue angle, S L Represents the weight parameter of brightness, S C Represents the chroma weight, S H Represents the hue weight factor, R T Represents the rotation factor, parameter factor K L ,K C ,K H The value is 1.

[0075] (4) Voting method to determine similar reference color blocks

[0076] According to the color difference formulas in steps (1), (2) and (3) above, C i and C t Calculate the color difference and record the result as ΔE RGB (C i ,C t ), ΔE HSV (C i ,C t ), ΔE Lab (C i ,C t ), record the reference color block index i = 0, 1, 2, 3...; where i Lab ,i HSV ,i RGB They respectively represent the reference color block indexes obtained by calculating and analyzing the color difference formula;

[0077] For the RGB color space, calculate ΔE RGB (C i ,C t ) value is the smallest reference color block index:

[0078] i RGB =argmin i ΔE RGB (C i ,C t )

[0079] For the HSV color space, calculate ΔE HSV (C i ,C t ) value is the smallest reference color block index:

[0080] i HSV =argmini ΔE HSV (C i ,C t )

[0081] For the Lab color space, calculate ΔE Lab (C i ,C t ) value is the smallest reference color block index:

[0082] i Lab =argmin i ΔE Lab (C i ,C t )

[0083] The most similar indices calculated by the three methods are aggregated into one set:

[0084] Results = {i RGB ,i HSV ,i Lab}

[0085] Remember i final To output the corresponding index of the reference color block, count the number of occurrences of each color block index in Results Count(x i ), x i ∈Results.

[0086] If there is Count(x i )>=2, that is, there are duplicate values ​​in the Results set, then the index with the most occurrences is selected as the most similar reference color block i final :

[0087]

[0088] Otherwise, the elements in Results are not repeated, that is, i RGB 、i HSV 、i Lab The corresponding values ​​are not equal to each other. At this time, according to the table lookup method, the most similar reference color block i final :

[0089] when i RGB 、i HSV 、i Lab When the values ​​are not repeated, i RGB 、i HSV 、i LabEnumerate all possible permutations of the element index list, extract the value of the element in the permutation and arrange it from small to large to form a corresponding combination. When the value of the element in the combination is an arithmetic progression, the detection is considered valid, and the flag is recorded as the median value of the element in the combination; otherwise, the detection is considered invalid, the flag is recorded as -1, and the user is prompted to re-detect. When the detection is considered valid, that is, the flag is not -1, i final =The reference color block color corresponding to flag is the most similar reference color of the reagent block, otherwise the test is considered invalid and the user is prompted to retest.

[0090] Beneficial effects of the present invention:

[0091] The present invention designs a test paper image colorimetric analysis algorithm, which can be deployed based on mobile platforms such as smart phones. For test papers based on color development reactions such as urine sodium detection test papers, the algorithm has a certain degree of adaptability to different lighting environments without the need for additional external devices, thereby providing convenience for color vision deficiency patients to perform test paper color recognition, reducing the impact of subjectivity on the accuracy of test results, and the detection process is simple and quick. BRIEF DESCRIPTION OF THE DRAWINGS

[0092] Figure 1 A technical roadmap for the method of the present invention;

[0093] Figure 2 A sample diagram of a urine sodium test strip used in the method of the present invention;

[0094] Figure 3 A flowchart for guiding user operations when acquiring images;

[0095] Figure 4 The effect diagram of edge enhancement processing for the acquired image;

[0096] Figure 5 An effect diagram for finding and drawing contours based on an enhanced edge map;

[0097] Figure 6 Draw a bounding rectangle and an indented bounding rectangle of a reference color block for shape contour feature detection;

[0098] Figure 7 This is a diagram showing the placement of the test strip detection reagent block;

[0099] Figure 8 A detection reagent block boundary rectangle and an indented boundary rectangle drawn based on position and geometric relationship;

[0100] Fig. 9 It is the test result of colorimetric analysis based on reference color block and reagent block. DETAILED DESCRIPTION

[0101] The present invention is further described below in conjunction with the accompanying drawings and specific implementation methods, which does not limit the protection scope of the present invention.

[0102] The present invention relates to a colorimetric analysis method for ion concentration detection test strips suitable for mobile phone apps. The technical roadmap of the detection method is as follows: Figure 1 As shown, urine sodium test strips are used as the test object, and the sample picture of urine sodium test strips is as follows Figure 2 The complete detection steps of the method of the present invention are as follows:

[0103] Step 1: Follow the instructions for use of the test paper, place the reagent block and reference color block that have fully reacted with the test liquid and developed color in the App scanning box, and acquire the frame image I0(x,y) in real time.

[0104] Step 2: For the acquired frame image I0(x,y), calculate the pixel mean and standard deviation in the image to set the threshold, filter out invalid images, and prompt the user to adjust the light environment and re-capture the image until the image I1(x,y) that meets the set threshold is captured; the specific steps are as follows:

[0105] The present invention uses the pixel mean to represent the average brightness of the entire image, and the standard deviation can reflect the pixel differences and the content of effective information of the image. The formulas for calculating the mean and standard deviation of image pixels are as follows:

[0106]

[0107] Among them, μ is the mean, I i is the grayscale value of the i-th pixel, and N is the total number of pixels.

[0108]

[0109] Where σ is the standard deviation of the image and μ is the mean.

[0110] After experimental testing, the threshold values ​​are selected as μ≥5 and σ≥2. When μ<5 or σ<2, the invalid image is filtered out, prompting the user to adjust the light environment and re-capture the image for subsequent detection to avoid affecting the subsequent colorimetric analysis results.

[0111] In the subsequent steps, the image integrity is determined by detecting the number of reference color blocks in the image I1(x, y). If the acquired image is incomplete, it is necessary to re-acquire the image and prompt the user to adjust the shooting position and angle. Based on the relationship between the contour area and the imaging distance, the user is prompted to adjust the shooting distance to control the image size and clarity.

[0112] The above methods prompt the user to adjust the image acquisition operation until a complete, clear and effective image is acquired, and the process is implemented as follows: Figure 3 shown.

[0113] Step 3: When the camera collects data in a natural environment, it will be affected by the surrounding lighting environment and cause color deviation. Based on the grayscale world hypothesis and perfect reflection theory, the gain is first calculated based on the average grayscale value to adjust the color channel, eliminate the color deviation caused by uneven lighting, and make the image color balanced; then the reflection gain is calculated based on the maximum value of each channel, and the image I1(x, y) is color corrected so that the maximum value of each channel is close to and does not exceed 255, simulating perfect reflection under ideal conditions and improving the accuracy of color extraction. The image after color correction is recorded as I(x, y).

[0114] The method for calculating the gain based on the average gray value to adjust the color channel is as follows:

[0115] (1) Calculate the average values ​​of the R, G, and B channels of the image, which are respectively

[0116]

[0117] Where M and N are the width and height of the image, and R(i,j), G(i,j), and B(i,j) represent the red, green, and blue channel components of the color image I1(x,y) at position (i,j), respectively.

[0118] (2) Calculate the average gray value of the image

[0119] Calculate the average gray value of the image based on the average value of the three color channels

[0120]

[0121] (3) Calculate the gain of each channel

[0122] Based on the grayscale world theory, the gain of each color channel is calculated separately R 、gain G 、gain B , to ensure that each channel remains balanced during grayscale conversion:

[0123]

[0124] (4) Apply gain to adjust the color channel

[0125] Adjust the gain of each color channel separately, and the new color channel values ​​are R′(i,j), G′(i,j), and B′(i,j):

[0126] R′(i,j)=gain R ×R(i,j)

[0127] G′(i,j)=gainG ×G(i,j)

[0128] B′(i,j)=gain B ×B(i,j)

[0129] Through the above steps, the RGB channels are adjusted to eliminate the color deviation caused by uneven lighting and improve the accuracy of color extraction.

[0130] After completing the above adjustments, the reflection gain is calculated based on the maximum value of each color channel, and the image color channel is adjusted based on the reflection gain:

[0131] (1) Calculate the maximum value of each color channel

[0132] Based on the perfect reflection assumption, calculate the maximum value R of each channel after adjustment max , G max , B max :

[0133]

[0134] (2) Calculate the reflection gain

[0135] In order to adjust the maximum value to 255, the reflection gain of each channel is calculated and recorded as reflectGain R 、reflectGain G 、reflectGain B :

[0136]

[0137] (3) Apply reflection gain to adjust the color channel

[0138] Adjust the value of each color channel again so that the maximum value is close to 255 to complete the color correction. R″(i,j), G″(i,j), and B″(i,j) are the R, G, and B component values ​​of the adjusted pixel points respectively:

[0139] R″(i,j)=reflectGain R ×R′(i,j)

[0140] G″(i,j)=reflectGain G ×G′(i,j)

[0141] B″(i,j)=reflectGain B ×B′(i,j)

[0142] (4) Prevent overflow

[0143] Limit the adjusted color channels to ensure that the pixel value of each channel does not exceed 255. final (i,j),G final (i,j),B final (i, j) are the R, G, and B component values ​​of the pixel after adding overflow limit adjustment:

[0144] R final (i,j)=min(R″(i,j),255)

[0145] G final (i,j)=min(G″(i,j),255)

[0146] B final (i,j)=min(B″(i,j),255)

[0147] (5) Merge the adjusted color channels

[0148] I(x,y)=[R final (i,j),G final (i,j),B final (i,j)]

[0149] Finally, the color component values ​​of the final adjusted pixels are combined as the corrected image I(x,y).

[0150] Step 4: Then, the image I(x, y) is subjected to mixed filtering, graying, local adaptive threshold, opening and closing operation, and edge enhancement image processing technology to obtain the edge-enhanced image J(x, y) to reduce the probability of missed detection during contour search; the specific implementation process is as follows:

[0151] (1) Hybrid filtering

[0152] (i) First, calculate the Gaussian blurred image of the original image. The operation is shown in the following formula:

[0153] G(x,y)=GaussianBlur(I(x,y),k,σ)

[0154] Wherein, GaussianBlur(·) represents a Gaussian blur operation, I(x, y) is the input image, k is the convolution kernel size (k=3×3 is set in the present invention), σ is the standard deviation of the Gaussian function (σ=5 is set in the present invention), and G(x, y) is the image after Gaussian blur.

[0155] (ii) Calculate the difference between the original image and the Gaussian blurred image, i.e., the high-frequency component, as shown in the following equation:

[0156] H(x,y)=I(x,y)-G(x,y)

[0157] Among them, H(x,y) is the high-frequency component image.

[0158] (iii) Adjust the high frequency component to 3 times gain, as shown in the following formula:

[0159] H′(x,y)=g·H(x,y)

[0160] Wherein, H′(x, y) is the image after gain, and g is the gain factor (here g=3.0).

[0161] (iv) Add the enhanced high-frequency component to the blurred image to obtain the high-frequency enhancement result, as shown in the following formula:

[0162] E(x,y)=I(x,y)+H′(x,y)

[0163] Among them, E(x,y) is the image after image superposition.

[0164] (v) Remove noise by median filtering, as shown in the following formula:

[0165] O(x,y)=MedianBlur(E(x,y),k size )

[0166] Among them, O(x,y) is the final output image after median filtering, k size is the convolution kernel size of the median filter (take k size =3×3).

[0167] The above processing can effectively remove noise while protecting and enhancing edges and details.

[0168] (2) Image grayscale

[0169] For the filtered image O(x, y), the weighted average method is used to perform weighted averaging of the three components with different weights to obtain a grayscale image denoted as G(x, y).

[0170] Gray(i,j)=0.299*R(i,j)+0.578*G(i,j)+0.114*B(i,j)

[0171] Where R(i,j), G(i,j), and B(i,j) represent the red, green, and blue channel components of the color image at position (i,j), respectively, and Gray(i,j) represents the grayscale value of position (i,j) in the image.

[0172] (3) Local adaptive threshold segmentation

[0173] In scanning and detection scenarios, it is difficult to ensure a uniform lighting environment. Local adaptive threshold segmentation can deal with problems such as uneven lighting and noise interference. It can be used for multi-target segmentation in complex scenes and perform adaptive threshold processing on the image G(x,y) to obtain the image H(x,y).

[0174] Given an input image G(x,y), calculate the mean of the pixels in the neighborhood window:

[0175]

[0176] Among them, |W(x,y)| represents the area of ​​the domain window.

[0177] Calculate the local threshold T(x,y):

[0178] T(x,y)=M(x,y)-C

[0179] Where C is a constant offset.

[0180] Use the local threshold T(x,y) to binarize the image and get the output image H(x,y):

[0181]

[0182] (4) Open and close operations

[0183] Opening and closing are the basic operations of mathematical morphology, namely erosion, dilation, opening and closing. The principle of opening is to first perform an erosion operation and then a dilation operation. Opening can remove noise and eliminate small objects. Closing is the opposite of opening, which is to first perform dilation and then erosion. It is usually used to fill small holes in foreground objects or to erase small black spots on foreground objects. Perform opening and closing operations on the image H(x,y) to remove irrelevant noise and obtain the image L(x,y). The opening and closing operation process is as follows:

[0184] The opening operation is to first erode and then expand. The mathematical definition of opening A with B is:

[0185]

[0186] The closing operation is to first dilate and then erode. The mathematical definition of closing A with B is:

[0187]

[0188] Where A is the original set or image, B is the structural element, ⊕ represents the dilation operation, Represents an erosion operation.

[0189] (5) Edge enhancement

[0190] The Scharr operator is mainly used for image edge detection, especially for images with more edge details. It can provide stronger edge response and more accurately detect subtle changes in the image than other operators. Therefore, it is suitable for image processing tasks that require high details. It can be used to detect features such as edges and contours in images. Use the Scharr operator to enhance edges and strengthen their edge features.

[0191] The Scharr operator is a convolution kernel (also called a convolution mask) used to calculate the gradient of an image. It contains two 3×3 convolution kernels, which are used to calculate the gradient of the image in the horizontal and vertical directions respectively. These two convolution kernels can be expressed as:

[0192] Horizontal Scharr convolution kernel:

[0193]

[0194] Vertical Scharr convolution kernel:

[0195]

[0196] Calculate the gradients in the horizontal and vertical directions, i.e., the x and y directions, respectively, as:

[0197]

[0198] Among them, L(x,y) represents the input image, G x and G y are the gradient matrices in the x and y directions respectively.

[0199] Convert the absolute value of the gradient in the x and y directions to unsigned types:

[0200] |G x |=abs(G x )

[0201] |G y |=abs(G y )

[0202] Perform weighted average of the gradients in the x and y directions to obtain the comprehensive gradient G:

[0203] G=0.5×|G x |+0.5×|G y |

[0204] Edge enhancement is performed to obtain the processed image J(x,y).

[0205] The edge-enhanced image J(x,y) obtained through the above steps helps to improve the accuracy of contour detection. The effect after processing is shown in the figure below: Figure 4 shown.

[0206] Step 5: Based on the image J(x, y), the reference color block ROI area r of the test paper in the image is extracted from the color-corrected image I(x, y) by using the shape contour feature. i (x, y), i = 0, 1, 2, 3 ..., m-1; where m is the number of reference color blocks; if all reference color blocks are not detected, repeat step 2 to re-capture the image, and prompt the user to adjust the shooting position and angle; according to the relationship between the contour area and the imaging distance, prompt the user to adjust the shooting distance so that the image size and clarity meet the set requirements;

[0207] In step 5, based on the image J(x, y), the reference color block ROI region r is extracted from the color-corrected image I(x, y) by using the shape contour feature i (x, y), i = 0, 1, 2, 3 ..., m-1, the steps are as follows:

[0208] (1) Initial screening of profile

[0209] The initial screening of contours is performed based on the edge-enhanced image J(x,y), mainly by means of contour area threshold, shape factor, compact value, and aspect ratio of the minimum circumscribed oblique rectangle, and the index set L1 for initial contour screening is obtained by screening.

[0210] a) Contour area threshold

[0211] According to the principle of geometric optical imaging, the imaging area is inversely proportional to the square of the distance: when the distance of the object from the lens doubles, its imaging area in the image will be reduced to one-fourth of the original; conversely, when the distance of the object from the lens is reduced by half, its imaging area will increase to four times the original. If we know the imaging area A1 at a certain distance d1, then the imaging area A2 at another distance d2 can be expressed as:

[0212]

[0213] In order to ensure the imaging quality of the collected images, the experiment set the shooting distance between 18cm and 5cm, and the reference color block contour area value is approximately [1100,14000]. Therefore, by setting the area threshold [1100,14000], the contour of the target reference color block can be retained and other irrelevant interfering target contours that exceed the area threshold range can be screened out.

[0214] b) Form factor and compactness

[0215] After the contour area threshold method screening, there are still a large number of interfering contours such as text symbols, test paper edges, noise and light shadows. After comparative analysis and experimental verification, the shape features (shape factor and compactness value) can be used to eliminate the interfering contours. The shape factor describes the compactness (also known as elongation) of the region to a certain extent. It is insensitive to scale changes and is also insensitive to rotation except for the rounding error caused by the rotation of the discrete region. Assuming the contour perimeter is P and the contour area is A, the calculation formula of the shape factor F is:

[0216] F=P 2 / 4πA

[0217] The measure of shape compactness is the compactness value A P is the ratio of the contour area to the perimeter:

[0218]

[0219] Among them A P is the area-to-perimeter ratio, A is the contour area, and P is the contour perimeter.

[0220] After multiple experimental tests and based on comparative analysis of other interference contour numerical relationships, the shape factor F threshold is set to [1.0, 1.6], A P The value range [10,24] can retain the reference color block contour while filtering out interference contours well.

[0221] c) Minimum circumscribed oblique rectangle aspect ratio

[0222] The aspect ratio of the minimum circumscribed rectangle can reflect the elongation of the figure. For shapes that are the same but do not have a similar relationship, the aspect ratio of their minimum circumscribed oblique rectangle is also different.

[0223] R a =max(w,h) / min(w,h)

[0224] Where R a is the aspect ratio of the minimum oblique rectangle circumscribing the outline, w is the width of the oblique rectangle circumscribing the outline, and h is the height of the oblique rectangle circumscribing the outline (assuming that the actual width of the reference color block of the test paper is greater than the actual height).

[0225] (2) Contour Second Screen

[0226] The contour index L1 set obtained by the initial contour screening is then subjected to the second contour screening. The contours in the L1 set are arranged in descending order based on the horizontal coordinates of the contour center points. The contours in the set L1 are extracted and grouped according to the number of reference color blocks. The adjacent contours in each group are judged to be equidistant and collinear, and a contour group index set that meets the conditions is returned. For the contour groups that meet the equidistant and collinear judgments, the Hu moments of the contours within the group are calculated for contour matching, and a contour group index set L2 with the most similar contour Hu moments is returned. A rectangular fitting judgment is then performed on each contour. If it meets the requirements, it is the contour index set corresponding to the reference color block.

[0227] For contour extraction and grouping, assuming that there are n contours in the L1 set after the initial contour screening, and m contours are extracted from them, the formula for the number of combinations that can be extracted is as follows:

[0228]

[0229] in It represents the number of combinations of selecting m elements from n.

[0230] For the grouped contours, the contour center points are judged to be equidistant. Assuming that there are m point sequences (P1, P2, ..., P m ), the coordinates of each point in m are P i (x i ,y i ). The Euclidean distance between points is defined as:

[0231]

[0232] If adjacent contours are required to be equidistant, the distances between all adjacent points must satisfy:

[0233] |d(P i ,P i+1 )-d(P i+1 ,P i+2 )|≤D,i=1,2,…,m-1

[0234] Where D represents the distance tolerance, which can be determined based on actual conditions.

[0235] For the center points of the contour group that meet the equidistant judgment, a collinear judgment is performed. Assume that there are n center points whose coordinates are (x1, y1), (x2, y2), …, (x n ,y n ) can calculate the correlation coefficient R of the center point set of the contour group:

[0236]

[0237] where x i and iare the horizontal and vertical coordinates of each point in the point set, and n is the number of points. When |R| is close to 1, it means that there is a very strong linear relationship between the two variables and the points are basically collinear. When |R| is close to 0, it means that there is no linear relationship between the two variables and the point set is not collinear.

[0238] For contour groups that meet the equidistant and collinear requirements, contour matching can be performed using the Hu moment, and the index of a contour group with the most similar contour in the contour group is returned.

[0239] The Hu moment is a set of seven invariant moments based on images or shapes, proposed by Hu, used to describe the shape characteristics of two-dimensional images. It is a linear combination of normalized central moments. By combining different normalized central moments, an invariant function that reflects different characteristics can be obtained. This function has scale, rotation, scaling, and mirror mapping (except h1) invariance. The calculation process of the Hu moment is as follows.

[0240] a) The original moment of the image

[0241]

[0242] Where I(x,y) is the pixel value of the image at coordinate (x,y).

[0243] b) The centroid coordinates of the image are

[0244]

[0245] in, and The horizontal and vertical coordinates representing the centroid coordinates are used to center the image.

[0246] c) Central moment

[0247]

[0248] Among them, the central moment μ pq , quantify the shape characteristics of the image with respect to the centroid.

[0249] d) Normalized central moment η pq

[0250] in

[0251] Normalized central moment η pq , the central moment is normalized to adapt to images of different scales and has stronger invariance. The parameter γ is related to p and q.

[0252] e) Hu moment

[0253] Hu1=η 20 +η 02

[0254]

[0255] Hu3=(h 30 -3rd 12 ) 2 +(3rd 21 -or 03 ) 2

[0256] Hu4=(η 30 +n 12 ) 2 +(the 21 +n 03 ) 2

[0257] Hu5=(h 30 -3rd 12 )(or 30 +n 12 )[(or 30 +n 12 ) 2 -3(h 21 +n 03 ) 2 ]+(3rd 21 -or 03 )(or 21 +n 03 )[3(h 30 +n 12 ) 2 -(or 21 +n 03 ) 2 ]

[0258] Hu6=(h 20 -or 02 )[(or 30 +n 12 ) 2 -(or 21 +n 03 ) 2 ]+4th 11 (or 30 +n 12 )(or 21 +n 03 )

[0259] Hu7=(3rd 21 -or 03 )(or 30 +n 12 )[(or 30 +n 12 ) 2 -3(h21 +η 03 ) 2 ]-(η 30 -3η 12 )(η 21 +η 03 )[3(η 30 +η 12 ) 2 -(η 21 +η 03 ) 2 ]

[0260] Among them, Hu i Represents the i-th Hu moment, which is used to describe the seven invariant moments of shape features and is robust to translation, rotation, and scale changes.

[0261] Calculate the contour Hu moment distance, the formula is:

[0262]

[0263] in, Represents the kth Hu moment value of the ith contour.

[0264]

[0265] Adjust the threshold huThreshold, if all distances d ij If all of them are less than the set threshold huThreshold, a set of contour group indexes L2 with the smallest Hu moment distance is returned, which is the contour group index of the reference color block. The contour drawing effect based on the search result is shown in the figure below. Figure 5 shown.

[0266] (3) Extract reference color block ROI

[0267] The boundary rectangle is drawn according to the contour corresponding to the contour group index set L2, but the contour generated based on the edge strength may be affected by factors such as noise, edge detection operator accuracy, image operation, rounding error, image distortion, shooting angle, etc., resulting in inaccurate position and size, thereby out-of-bounds selection of the background area to reduce the signal-to-noise ratio of the image, and further affecting the subsequent color analysis. The urine sodium test strip used in this method has four concentration level reference color blocks of 0mM, 60mM, 180mM, and 360mM, so the indented boundary rectangle is intercepted based on the boundary rectangle in the color-corrected image I(x,y) as the ROI area r of the extracted 0mM, 60mM, 180mM, and 360mM reference color blocks. i (x, y), i = 0, 1, 2, 3, draw the reference color block boundary rectangle and the indented boundary rectangle as shown Figure 6 shown.

[0268] Step 6. To facilitate image acquisition and experimental analysis, set the placement and angle of the test strip reagent block relative to the reference color block during each test to be fixed and consistent. Based on the congruence of the reference color block and the collinear position geometric relationship, an empirical formula is designed to achieve the detection of the reagent block area location extraction. Similarly, to ensure the accuracy of boundary extraction, the boundary is indented to a certain extent. After color correction, the image I (x, y) is segmented and intercepted as the ROI area t (x, y) of the extracted color reagent block. The specific steps are as follows:

[0269] The placement of the test strip detection reagent block relative to the reference color block is as follows Figure 7 As shown, there are four known concentration level rectangular reference color blocks of 0mM, 60mM, 180mM, and 360mM, which are arranged equidistantly along the same horizontal line at a certain distance from left to right from light to dark.

[0270] Assume that the horizontal positive direction is to the right and the vertical positive direction is to the downward. The coordinates of the center points of the four concentration levels of 0mM, 60mM, 180mM, and 360mM are (centerX i , centerY i ), the reference color block width is width i , the reference color block height is height i , where i = 0, 1, 2, 3. According to the spatial position relationship and geometric relationship, it is easy to get:

[0271] centerX0 <centerX1<centerX2<centerX3

[0272] centerY0=centerY1=centerY2=centerY3

[0273] centerX1-centerX0=centerX2-centerX1=centerX3-centerX2>width i

[0274] The coordinates of the center point of the detection reagent block are recorded as (targetX, targetY). Since the target color reagent block can be approximated as a square, its side length is recorded as targetLength, and the empirical formula can be obtained:

[0275] targetLength=s*(height0+height1+height2+height3) / 4

[0276] targetX=centerX3+a*width3+b*targetLength

[0277] targetY=(centerY0+centerY1+centerY2+centerY3) / 4

[0278] Where a and b are empirical coefficients, s represents the zoom ratio, a=1.15, b=0.5, s=0.8.

[0279] The bounding rectangle can be drawn according to the coordinates of the center point of the test reagent block (targetX, targetY) and the side length targetLength. However, the drawn bounding rectangle may also be affected by calculation errors, shooting angles, image distortion, etc., resulting in positioning deviations of the color reagent block and inaccurate sizes. The background area may be incorrectly selected, resulting in a decrease in the signal-to-noise ratio of the image, affecting the accuracy of the colorimetric analysis. Therefore, the bounding rectangle is indented at a certain magnification as the extracted reagent block ROI area t(x, y). The detected ROI area t(x, y) is drawn with a bounding rectangle and an indented bounding rectangle as shown in FIG. Figure 8 shown.

[0280] Step 7: Use the jump point sampling mean method to calculate the reference color block ROI area r i (x, y), i = 0, 1, 2, 3..., m-1 respectively perform main color extraction and record it as C i , where m is the number of reference color blocks; the main color calculation of the reagent block ROI area t(x,y) is performed using the jump point sampling mean method, denoted as C t .

[0281] In step 7, a jump point sampling mean method is proposed to respectively calculate the ROI area r of the 0mM, 60mM, 180mM, and 360mM reference color blocks. i (x, y), i = 0, 1, 2, 3 extracts the main color and the reagent block ROI area t (x, y) extracts the main color, and the implementation process is as follows.

[0282] (1) Accumulation of color values

[0283] For valid pixels (i.e. pixels that do not cross the boundary), take a step size of p to sample the points and accumulate the red, green, and blue color channels:

[0284]

[0285] Among them, W and H represent the width and height of the ROI area respectively, and R total , G total , B total are the cumulative sum of the red channel, green channel, and blue channel respectively. R(i,j), G(i,j), and B(i,j) represent the red, green, and blue color channel values ​​of the pixel at row i and column j.

[0286] (2) Actual number of sampled pixels

[0287] Every p pixels are sampled in the width and height dimensions of the image ROI area, and the number of sampled pixels is:

[0288]

[0289] Among them, n sample Indicates the total number of pixels actually sampled.

[0290] (3) Calculate the average color

[0291] According to the sum of the sampled colors, calculate the average value of each color channel:

[0292]

[0293] Among them, R avg , G avg , B avg is the average value of the red, green, and blue color channels in the image patch.

[0294] Step 8: C is analyzed based on RGB, HSV, and Lab color spaces respectively. i and C t The color difference is calculated and the reference color that the reagent block is most similar to is determined based on a voting mechanism.

[0295] In step eight, a method is proposed to respectively analyze C based on RGB, HSV, and Lab color spaces. i and C t The color difference is calculated and the method of determining the most similar reference color of the reagent block according to the voting mechanism is implemented as follows:

[0296] From the perspective of physics, the perception of color originates from the spectral energy distribution of electromagnetic radiation that stimulates the retina, but human perception of color is also related to many physical phenomena, neuropsychological effects, and physiological behaviors, and the relationship is relatively complex. The test paper colorimetry method is designed based on human color perception, so color similarity judgment based on color difference in multi-color space can make full use of the color information in the image and improve robustness and accuracy.

[0297] (1) Weighted color difference in RGB color space

[0298] The traditional RGB color model is not modeled in the way humans perceive color. Specifically, human color perception is nonlinear and not completely orthogonal. The human eye has different color discrimination abilities for different colors, and also nonlinear perception of brightness. For example, blue contributes very little to the perception of brightness, but human vision has very good color discrimination for blue. The use of the traditional RGB model standard Euclidean distance formula for color similarity comparison is not ideal. The use of the RGB color model weighted color difference method is more in line with human visual color perception and has better stability.

[0299] Assumption C 1,R ,C 1,G ,C 1,B Represents the red component, green component, and blue component of the first color sample (Color 1), respectively. 2,R ,C 2,G ,C 2,B Represent the red component, green component, and blue component of the second color sample (Color 2) respectively. Then an RGB weighted color difference formula is as follows:

[0300]

[0301] in, Represents the average of the red components of the first color sample (Color 1) and the second color sample (Color 2), which is used to adjust the color difference formula weight.

[0302] ΔR=C 1,R -C 2,R

[0303] ΔG=C 1,G -C 2,G

[0304] ΔB=C 1,B -C 2,B

[0305] Wherein, ΔR, ΔG, and ΔB represent the red component difference, green component difference, and blue component difference between the first color sample (Color 1) and the second color sample (Color 2).

[0306]

[0307] Where, ΔE RGB Represents the color difference between the first color sample (Color 1) and the second color sample (Color 2) using the weighted color difference method of the RGB color model.

[0308] (2) Chromatic difference in HSV color space

[0309] The HSV model is also a model based on human color perception and is more suitable for image algorithms oriented to visual perception and color processing analysis.

[0310] a) RGB to HSV

[0311] In the HSV color space, colors are represented by hue, saturation, and value. h represents hue, ranging from [0,360), s represents saturation, ranging from [0,1], and v represents value, ranging from [0,1]. Assume that r, g, and b represent the red, green, and blue color channel components of the input color sample, respectively. Then:

[0312]

[0313] v=max

[0314] Among them, max = max(r,g,b), min = min(r,g,b), which represent the maximum value and minimum value of a given color component.

[0315] b) Color distance calculation

[0316] In order to calculate the difference between two colors, the HSV space color value is first mapped to a three-dimensional space coordinate system coordinate system (x, y, z), which mainly includes the following process:

[0317] For the HSV value of a color (h, s, v), define its coordinate point (x, y, z) in three-dimensional space. The coordinate calculation formula is:

[0318]

[0319]

[0320] Among them, R represents the maximum scale of the HSV space, and angle represents the inclination angle of the HSV space.

[0321] Calculate the color distance. For two color samples, (h1, s1, v1) and (h2, s2, v2), substitute the corresponding coordinates (x1, y1, z1) and (x2, y2, z2) into the coordinate calculation formula. The three-dimensional Euclidean distance formula is:

[0322]

[0323] Where, ΔE HSV Indicates the color distance calculated based on the HSV color model.

[0324] (3) Color difference in Lab color space

[0325] The Lab color space is a uniform color space that conforms to human visual perception and is convenient for color difference calculation. When the color difference is recognized by the human eye and this difference is smaller than the color difference between two adjacent levels in the Munsell system, it can reflect the actual feeling of the observer on the product. First convert the RGB color space to the CIE XYZ color space, then convert the XYZ color space to the Lab color space, and then calculate the perceived color difference of the color.

[0326] a) Color space conversion

[0327] In order to match the nonlinear perception of brightness by the human eye and make the image look consistent with the characteristics of the human eye, it is necessary to compensate for the distortion, and the image is often gamma corrected. Before converting to CIE XYZ, the RGB value needs to be inversely gamma corrected to convert it into linear RGB values ​​r, g, b, and then mapped to CIE XYZ through matrix operations.

[0328]

[0329] Among them, r, g, b are the RGB values ​​after gamma correction.

[0330] The linear RGB values ​​r,g,b are mapped to the CIE XYZ color space, and X,Y,Z are calculated by the following matrix operation:

[0331]

[0332] Secondly, convert the CIE XYZ color space to the CIE Lab color space. The conversion formula is:

[0333] Take the reference white point value as X r =0.950456,Y r =1.0,Z r = 1.088754, relative to the reference white point X r ,Y r ,Z r Normalize:

[0334]

[0335] x r ,y r , z r Apply the following nonlinear function for nonlinear adjustment:

[0336]

[0337] Where ∈=0.008856, k=903.3.

[0338] Calculate fx =f(x r ),f y =f(y r ),f z =f(z r ).

[0339] According to the nonlinear function result f x ,f y ,f z , calculate the three components L, a, b of CIE Lab:

[0340] L=116·f y -16

[0341] a=500·(f x -f y )

[0342] b=200·(f y -f z )

[0343] b) Lab color space color difference calculation

[0344] For the CIELab values ​​of two color points: (L1, a1, b1) and (L2, a2, b2), the color difference calculation process is as follows.

[0345] Calculate the brightness difference:

[0346] ΔL′=L2-L1

[0347] Average brightness:

[0348]

[0349] Calculate the weight parameter of brightness:

[0350]

[0351] Calculate chroma:

[0352]

[0353] Calculate average chroma:

[0354]

[0355] Color correction:

[0356]

[0357] a1′=a1·(1+G), a′2=a2·(1+G)

[0358] The corrected chroma is:

[0359]

[0360] Calculate the corrected average chroma:

[0361]

[0362] Corrected color difference:

[0363] ΔC′=C′2-C1′

[0364] Calculate the corrected hue angle:

[0365] h1′=atan2(b1,a1′),h′2=atan2(b2,a′2)

[0366] If the hue angle is negative, adjust it to a positive value:

[0367] h i ′=h i ′+2π(if h i ′<0)

[0368] Corrected average hue angle:

[0369]

[0370] Calculate hue difference:

[0371]

[0372]

[0373] Correction factor T:

[0374]

[0375] Hue weight factor S H :

[0376] S H =1+0.015·C′ mean ·T

[0377] Chroma weight S C :

[0378] S C =1+0.045·C′ mean

[0379] Twist factor R T :

[0380]

[0381] RT =-R C sin(2ΔΘ)

[0382] CIEDE2000 color difference formula:

[0383]

[0384] Where, ΔE Lab Indicates the color difference value. Usually, the parameter factor K L ,K C ,K H The value is 1.

[0385] (4) Voting method to determine similar reference color blocks

[0386] In this method, the urine sodium test strip has four reference color blocks and one target reagent block (such as Figure 2 As shown in the figure), the corresponding color sets for the reference color blocks (indexed as 0, 1, 2, and 3, respectively) at the concentration levels of 0mM, 60mM, 180mM, and 360mM are:

[0387] c={C0,C1,C2,C3}

[0388] The main color value C of the reference color block calculated by the jump point sampling average method i :

[0389]

[0390] The main color value C of the target detection reagent block calculated by the jump point sampling mean method t :

[0391]

[0392] According to the color difference formulas in (1), (2), and (3), C i and C t Calculate the color difference and record the result as ΔE RGB (C i ,C t ), ΔE HSV (C i ,C t ), ΔE Lab (C i ,C t ), record the reference color block index i = 0, 1, 2, 3. Lab ,i HSV ,i RGB They respectively represent the reference color block indexes obtained by calculating and analyzing the color difference formula.

[0393] For the RGB color space, calculate ΔE RGB (C i ,C t ) value is the smallest reference color block index:

[0394] i RGB =argmin i∈{0,1,2,3} ΔE RGB (C i ,C t )

[0395] For the HSV color space, calculate ΔE HSV (C i ,C t ) value is the smallest reference color block index:

[0396] i HSV =argmin i∈{0,1,2,3} ΔE HSV (C i ,C t )

[0397] For the Lab color space, calculate ΔE Lab (C i ,C t ) value is the smallest reference color block index:

[0398] i Lab =argmin i∈{0,1,2,3} ΔE Lab (C i ,C t )

[0399] The most similar indices calculated by the three methods are aggregated into one set:

[0400] Results = {i RGB ,i HSV ,i Lab}

[0401] Remember i final To output the corresponding index of the reference color block, count the number of occurrences of each color block index in Results Count(x i ), x i ∈Results.

[0402] If there is Count(x i )>=2, that is, there are duplicate values ​​in the Results set, then the detection is considered valid and the index with the largest number of occurrences is selected as the most similar reference color block i final :

[0403]

[0404] Otherwise, the elements in Results are not repeated, that is, i RGB 、i HSV 、i Lab The corresponding values ​​are not equal to each other. At this time, according to the table lookup method, the most similar reference color block i final :

[0405] when i RGB 、i HSV 、i Lab When the values ​​are not repeated, i RGB 、i HSV 、i Lab Enumerate all possible permutations of the element index list, extract the value of the element in the permutation and arrange it from small to large to form a corresponding combination. When the value of the element in the combination is an arithmetic progression, the detection is considered valid, and the flag is recorded as the median value of the element in the combination; otherwise, the detection is considered invalid, the flag is recorded as -1, and the user is prompted to re-detect, as shown in Table 1. When the detection is considered valid, that is, the flag is not -1, i final = flag corresponds to the most similar reference color index, otherwise the detection is considered invalid and the user is prompted to re-detect.

[0406] Table 1

[0407]

[0408] In summary, when the test is considered valid, the most similar reference color index can be determined by voting, and the reference color block color of the concentration level corresponding to the index is the closest color to the reagent block.

[0409] The method in the invention is deployed to the mobile phone to scan and detect the urine sodium test strip after the color reaction through the App, and the colorimetric analysis obtains the color of the closest reference color block, thereby indirectly realizing the determination of the sodium ion concentration in the urine. The test results are as follows: Fig. 9 shown.

[0410] The above is a detailed description of the implementation of the present invention in conjunction with the accompanying drawings. Although this article uses specific terms to illustrate, it cannot be used to limit the scope of protection of this patent. People familiar with this field can change or modify it after understanding the spirit and principles of this patent to achieve equivalent purposes, and such equivalent changes and modifications should all be covered within the scope defined by the scope of the patent claims.

Claims

1. A colorimetric analysis method for ion concentration detection test strips suitable for mobile phone apps, characterized in that: The steps of this method are as follows: Step 1: Follow the instructions for use of the test paper, place the reagent block and reference color block that have fully reacted with the test liquid and developed color in the App scanning box, and acquire the frame image I0(x,y) in real time; Step 2: For the acquired frame image I0(x,y), calculate the pixel mean and standard deviation in the image to set the threshold, filter out invalid images, and prompt the user to adjust the light environment and re-capture the image until an image I1(x,y) that meets the set threshold is captured; Step 3: When the camera collects images in a natural environment, it will be affected by the surrounding lighting environment and cause color deviation. Based on the grayscale world hypothesis and perfect reflection theory, the gain is first calculated based on the average grayscale value to adjust the color channel to eliminate the color deviation caused by uneven lighting and balance the image color; then the reflection gain is calculated based on the maximum value of each channel, and the image I1(x,y) is color corrected so that the maximum value of each channel is close to and does not exceed 255, simulating perfect reflection under ideal conditions and improving the accuracy of color extraction. The image after color correction is recorded as I(x,y). Step 4: Perform mixed filtering, graying, local adaptive thresholding, opening and closing operations, and edge enhancement on the image I(x, y) to obtain the edge-enhanced image J(x, y) to reduce the probability of missed detection during contour search; Step 5: Based on the image J(x, y), the reference color block ROI area r of the test paper in the image is extracted from the color-corrected image I(x, y) by using the shape contour feature. i (x, y), i = 0, 1, 2, 3 ..., m-1; where m is the number of reference color blocks; if all reference color blocks are not detected, repeat step 2 to re-capture the image, and prompt the user to adjust the shooting position and angle; according to the relationship between the contour area and the imaging distance, prompt the user to adjust the shooting distance so that the image size and clarity meet the set requirements; Step 6: To facilitate image acquisition and analysis, the placement and angle of the test strip reagent block relative to the reference color block are set to be fixed and consistent during each test. Based on the image J(x,y), the reagent block boundary positioning method is used. According to the congruence and collinearity of the reference color block, an empirical formula is designed to extract the reagent block ROI area t(x,y) from the color-corrected image I(x,y); Step 7: Use the jump point sampling mean method to calculate the reference color block ROI area r i (x, y), i = 0, 1, 2, 3..., m-1 respectively perform main color extraction and record it as C i , where m is the number of reference color blocks; Use the jump point sampling mean method to calculate the main color of the reagent block ROI area t(x,y) and record it as C t ; Step 8: C is analyzed based on RGB, HSV, and Lab color spaces respectively. i and C t The color difference is calculated and the reference color that the reagent block is most similar to is determined based on a voting mechanism.

2. A colorimetric analysis method for ion concentration detection test strips suitable for mobile phone apps according to claim 1, characterized in that: The specific steps of calculating the pixel mean and standard deviation in the image to set the threshold, filter invalid images, and prompt the user to adjust the light environment and re-collect the image in step 2 are as follows: The formulas for calculating the mean and standard deviation of image pixels are as follows: Among them, μ is the mean, I i is the image pixel value, N is the total number of pixels; Where σ is the standard deviation of the image, μ is the mean, and I(i) is the grayscale value of the i-th pixel; When the mean and standard deviation of image pixels are less than the set threshold, the image is filtered out, prompting the user to adjust the light environment and re-capture the image for subsequent testing to avoid affecting the subsequent colorimetric analysis results.

3. The colorimetric analysis method of an ion concentration detection test strip suitable for a mobile phone App according to claim 1, characterized in that: The hybrid filtering in step 4 is a median filtering based on Gaussian filtering high frequency enhancement, and the specific steps are as follows: (1) First, calculate the Gaussian blurred image of the original image. The operation is shown in the following formula: G(x,y)=GaussianBlur(I(x,y),k,σ) Where GaussianBlur(·) represents the Gaussian blur operation, I(x,y) is the input image, k is the convolution kernel size, σ is the standard deviation of the Gaussian function, and G(x,y) is the image after Gaussian blur; (2) Calculate the difference between the original image and the Gaussian blurred image, i.e., the high-frequency component, as shown in the following formula: H(x,y)=I(x,y)-G(x,y) Among them, H(x,y) is the high-frequency component image; (3) Adjust the high frequency component to 3 times gain, as shown in the following formula: H′(x,y)=g·H(x,y) Where H′(x,y) is the image after gain, g is the gain factor, g=3.0; (4) The enhanced high-frequency component is added to the blurred image to obtain the result of high-frequency enhancement, as shown in the following formula: E(x,y)=I(x,y)+H′(x,y) Among them, E(x,y) is the image after image superposition; (5) Remove noise by median filtering, as shown in the following formula: O(x,y)=MedianBlur(E(x,y),k size ) Among them, O(x,y) is the final output image after median filtering, k size is the convolution kernel size of the median filter, k size =3×3.

4. The colorimetric analysis method of an ion concentration detection test strip suitable for a mobile phone App according to claim 1, characterized in that: In step 5, based on the image J(x, y), the reference color block ROI region r is extracted from the color-corrected image I(x, y) by using the shape contour feature i (x, y), i = 0, 1, 2, 3 ..., m-1, the steps are as follows: (1) Initial screening of profile Based on the edge-enhanced image J(x,y), the contour is initially screened by using the contour area threshold, shape factor, compact value, and aspect ratio of the minimum circumscribed oblique rectangle, and the index set L1 for initial contour screening is obtained; (2) Contour Second Screen Arrange the contours in the L1 set in descending order based on the horizontal coordinates of the contour center points, extract and group the contours in the set L1 according to the number of reference color blocks, perform equidistant and collinearity determination on the contours in each group, return the contour group index set that meets the conditions, and then calculate the Hu moments of the contours within the group for contour groups that meet the equidistant and collinearity determinations for contour matching, return a contour group index set L2 with the most similar contour Hu moments, and then perform a rectangular fitting determination on each contour. If it meets the conditions, it is the contour index set corresponding to the reference color block; (3) Extract reference color block ROI According to the contour group index set L2, the corresponding contour boundary rectangle is obtained, and the boundary rectangle after a certain ratio is indented is used as the reference color block ROI area r to be extracted i (x, y), i = 0, 1, 2, 3…, m-1; where m is the number of reference color blocks.

5. The colorimetric analysis method of an ion concentration detection test strip suitable for a mobile phone App according to claim 1, characterized in that: In step 6, the method for extracting the reagent block ROI region location in the color-corrected image I (x, y) according to the congruence of the reference color blocks and the collinearity design empirical formula is as follows: The horizontal positive direction is horizontal to the right, and the vertical positive direction is vertical downward. The coordinates of the center point of the reference color block are (centerX i , centerY i ), the reference color block width is width i , the reference color block height is height i , where i = 0, 1, 2, 3…, m-1; where m is the number of reference color blocks; according to the spatial position relationship and geometric relationship, it is easy to obtain: centerX0<centerX1<centerX2<...<centerX m-1 centerY0=centerY1=centerY2=...=centerY m-1 centerX1-centerX0=centerX2-centerX1=...=centerX m-1 -centerX m-2 >width i The coordinates of the center point of the detection reagent block are recorded as (targetX, targetY). Since the target color reagent block can be approximated as a square, its side length is recorded as targetLength, and the empirical formula can be obtained: targetLength=s*(height0+height1+...+height m-1 ) / m targetX=centerX m-1 +a*width i +b*targetLength targetY=(centerY0+centerY1+...+centerY m-1 ) / m Where a and b are empirical coefficients, and s represents the magnification ratio; Therefore, the reagent block center point coordinates (targetX, targetY) and the side length targetLength are used as the boundary rectangle, and are indented at a certain magnification to obtain the extracted reagent block ROI area t(x, y).

6. The colorimetric analysis method of an ion concentration detection test strip suitable for a mobile phone App according to claim 1, characterized in that: In step 7, the step length is p, and the reference color block ROI area r is sampled. i (x, y) and the valid pixels in the reagent block ROI area t(x, y), that is, the pixels that do not cross the boundary, accumulate the three color channels of red, green, and blue, and sample every p pixels in the width and height of the image ROI area. According to the sum of the sampled colors, calculate the average value R of each color channel avg , G avg , B avg As the extracted main color value.

7. The colorimetric analysis method of an ion concentration detection test strip suitable for a mobile phone App according to claim 1, characterized in that: In step eight, C is respectively analyzed based on RGB, HSV, and Lab color spaces. i and C t The method for calculating the color difference and determining the most similar reference color of the reagent block according to the voting mechanism is as follows: (1) Calculate the weighted color difference in RGB color space Assumption C 1,R ,C 1,G ,C 1,B Represents the red component, green component, and blue component of the first color sample (Color 1), respectively. 2,R ,C 2,G ,C 2,B Represent the red component, green component, and blue component of the second color sample (Color 2) respectively: in, Represents the average of the red components of the first color sample (Color 1) and the second color sample (Color 2), which is used to adjust the weight of the color difference formula; ΔR=C 1,R -C 2,R ΔG=C 1,G -C 2,G ΔB=C 1,B -C 2,B Wherein, ΔR, ΔG, ΔB represent the difference of red component, green component, and blue component between the first color sample (Color 1) and the second color sample (Color 2); Where, ΔE RGB Represents the color difference between the first color sample (Color 1) and the second color sample (Color 2) using the weighted color difference method of the RGB color model; (2) Calculate the color difference in HSV color space Calculate the color distance. For two color samples, (h1, s1, v1) and (h2, s2, v2), calculate the corresponding coordinates (x1, y1, z1) and (x2, y2, z2) in the three-dimensional space. The formula for calculating the three-dimensional Euclidean distance is: Where, ΔE HSV Indicates the color distance calculated based on the HSV color model; (3) Calculate the color difference in Lab color space First convert the RGB color space to the CIE XYZ color space, then convert the XYZ color space to the Lab color space, and then calculate the perceived color difference using the CIEDE2000 color difference formula: Where, ΔE Lab Indicates the color difference value, ΔL′ represents the lightness difference, ΔC′ represents the corrected chroma difference, ΔH′ represents the hue difference after the corrected hue angle, S L Represents the weight parameter of brightness, S C Represents the chroma weight, S H Represents the hue weight factor, R T Represents the rotation factor, parameter factor K L ,K C ,K H The value is 1; (4) Voting method to determine similar reference color blocks According to the color difference formulas in steps (1), (2) and (3) above, C i and C t Calculate the color difference and record the result as ΔE RGB (C i ,C t ), ΔE HSV (C i ,C t ), ΔE Lab (C i ,C t ), record the reference color block index i = 0, 1, 2, 3...; where i Lab ,i HSV ,i RGB They respectively represent the reference color block indexes obtained by calculating and analyzing the color difference formula; For the RGB color space, calculate ΔE RGB (C i ,C t ) value is the smallest reference color block index: i RGB =argmin i ΔE RGB (C i ,C t ) For the HSV color space, calculate ΔE HSV (C i ,C t ) value is the smallest reference color block index: i HSV =argmin i ΔE HSV (C i ,C t ) For the Lab color space, calculate ΔE Lab (C i ,C t ) value is the smallest reference color block index: i Lab =argmin i ΔE Lab (C i ,C t ) The most similar indices calculated by the three methods are aggregated into one set: Results={i RGB ,i HSV ,i Lab } Remember i final To output the corresponding index of the reference color block, count the number of occurrences of each color block index in Results Count(x i ), x i ∈Results; If there is Count(x i )>=2, that is, there are duplicate values ​​in the Results set, then the detection is considered valid and the index with the largest number of occurrences is selected as the most similar reference color block i final : Otherwise, the elements in Results are not repeated, that is, i RGB 、i HSV 、i Lab The corresponding values ​​are not equal to each other. At this time, according to the table lookup method, the most similar reference color block i final : when i RGB 、i HSV 、i Lab When the values ​​are not repeated, i RGB 、i HSV 、i Lab Enumerate all possible permutations of the element index list, extract the value of the element in the permutation and arrange it from small to large to form a corresponding combination. When the value of the element in the combination is an arithmetic progression, the detection is considered valid, and the flag is recorded as the median value of the element in the combination; otherwise, the detection is considered invalid, the flag is recorded as -1, and the user is prompted to re-detect; when the detection is considered valid, that is, the flag is not -1, i final =The reference color block color corresponding to flag is the most similar reference color of the reagent block, otherwise the test is considered invalid and the user is prompted to retest.

Citation Information

Patent Citations

  • A computing and image correction method for light source color

    CN101146233A

  • White balance processing method directed towards atypical-feature image

    CN102883168A

  • Method for identifying color of test strip of urine detector

    CN109991216A

  • Color conversion device

    CN113766087A

  • Method for protecting private data in archive table image

    CN114821611A

Cited By

  • Food freshness detection method and system based on image recognition

    CN120672874A

  • Image processing-based urine test paper color change identification method and system

    CN122453736A