A colorimetric analysis method of ion concentration test paper suitable for mobile phone app
The colorimetric analysis of test strips is realized on the mobile phone app through image processing technology, which solves the subjective errors and lighting effects caused by human visual dependence and provides a convenient and accurate detection solution.
Patent Information
- Application Number
- CN202411833805.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-12-13
AI Technical Summary
The existing test paper colorimetric analysis method relies on artificial vision, has large subjective errors, is unusable by patients with color vision abnormalities, and is severely affected by the lighting environment.
An image processing-based method is used to collect test strip images through a mobile phone app, and image filtering, ROI region segmentation, color correction and color similarity calculation are performed. RGB, HSV and Lab color spaces are combined, and a voting mechanism is used to identify the color of the reagent block to achieve automatic colorimetric analysis.
It improves the accuracy and convenience of test paper colorimetric analysis, is suitable for patients with color vision deficiency, reduces the impact of the lighting environment, and realizes convenient detection on a mobile platform.
Smart Images

Figure CN119762455B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of test paper colorimetric analysis, and particularly relates to a test paper colorimetric analysis detection method based on image processing. BACKGROUND
[0002] The concentration detection of biochemical components is a key research topic in the fields of medical treatment and chemical analysis. In the detection of medical treatment and physical examination institutions, the detection of component concentration is often realized by means of test paper. The test paper component detection method is also widely used in the fields of home care and health detection (such as urine routine and blood glucose test paper). Most of the test paper methods are based on color development reaction to realize detection through colorimetric analysis. The content of the detected component is effectively analyzed by establishing the relationship between the color value and the concentration of the detected component. However, in the process of colorimetric analysis, strong subjectivity is easily generated due to the dependence on the visual sense system of the user. In addition, the visual sense system has limited ability to perceive fine differences in color. Moreover, the generation of human color vision is a complex process, which is easily affected by various factors, and even produces visual illusion and self-unaware misjudgment. Secondly, in real life, a certain proportion of people are patients with color vision deficiency, such as red-blind color weakness patients, congenital color vision disorder patients, color agnosia patients and visual system disease patients, and the color perception and discrimination ability of these people is relatively weak. For some older people, the visual system has relatively poor information processing and color understanding ability. Therefore, the test paper combined with artificial visual visual inspection method is not suitable for such people. Although the existing image processing technology can perform certain color analysis, the accuracy of colorimetric analysis is limited without additional optical devices, and is seriously affected by the light environment. Therefore, it is urgent to design an automatic detection colorimetric analysis method based on digital image. SUMMARY
[0003] In order to improve the convenience and accuracy of test paper colorimetric analysis detection, provide convenience for color vision deficiency patients, and avoid misjudgment caused by user subjective factors, the present application proposes a colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App. The method acquires pictures of test paper reference color blocks and reagent blocks after reaction with the ion solution to be detected through a camera. Through a series of digital image processing technologies, invalid images are filtered, ROI region image segmentation and extraction are completed, test paper image color correction is performed, color information of the color development regions of the test paper reference color blocks and the reagent blocks is extracted, and then color similarity is calculated based on the color information in RGB, HSV and Lab color spaces. The test paper color is identified according to the voting mechanism. The method is deployed on a smart phone for sodium ion concentration analysis and detection. Image acquisition and image processing are completed on the phone, the result display is realized, and functions such as data recording, data analysis and data sharing can be efficiently and conveniently expanded.
[0004] The technical solutions adopted by the present application are as follows:
[0005] A colorimetric analysis method of ion concentration detection test paper suitable for mobile phone App, the method steps are as follows:
[0006] Step one: according to the operation instruction of test paper, the reagent block and reference color block after color development are placed in the App scanning frame, and the frame image I0(x,y) is acquired in real time;
[0007] Step two: for the acquired frame image I0(x,y), the mean value and standard deviation of the image are calculated to set the threshold value, filter out invalid images, and prompt the user to adjust the light environment and reacquire the image until the image I1(x,y) that meets the set threshold value is acquired;
[0008] Step three: when the camera is collecting in the natural environment, the color deviation caused by the surrounding light environment will be caused. Based on the gray world assumption, the gain is calculated according to the average gray value to adjust the color channel, eliminate the color deviation caused by uneven light, and make the image color balanced. Based on the perfect reflection theory, the reflection gain is calculated according to the maximum value of each channel, the color of the image I1(x,y) is corrected, the maximum value of each channel is close to and does not exceed 255, the perfect reflection under ideal conditions is simulated, the accuracy of color extraction is improved, and the image after color correction is recorded as I(x,y),
[0009] Step four, the mixed filter, gray scale, local adaptive threshold, open-close operation and edge enhancement processing are carried out on the image I(x,y) to obtain the edge enhanced image J(x,y), which reduces the probability of missing detection when searching for the outline;
[0010] Step five, based on the image J(x,y), the reference color block ROI area r i (x,y) is extracted in the color corrected image I(x,y) through the shape contour feature, i=0,1,2,3…,m-1; Wherein m is the number of reference color blocks. If all reference color blocks are not detected, repeat step two to reacquire 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, the user is prompted to adjust the shooting distance, so that the imaging size and clarity meet the set requirements;
[0011] Step six, in order to facilitate image acquisition and analysis, the placement position and angle of the test reagent block during each detection are set to be fixed and consistent with the reference color block position, based on the image J(x,y), the reagent block ROI area t(x,y) is extracted in the color corrected image I(x,y) through the reagent block boundary positioning method, according to the experience formula of the congruence and collinearity of the reference color block;
[0012] Step seven, the jump point sampling mean method is used to extract the reference color block ROI area r i(x, y), i = 0, 1, 2, 3…, m-1 respectively i , where m is the number of reference color blocks; using the skip point sampling mean method to calculate the main color of the reagent block ROI region t(x, y) is denoted as C t ;
[0013] Step eight, respectively based on RGB, HSV, Lab color space respectively C i and C t Calculate the color difference, and determine the most similar reference color of the reagent block according to the voting mechanism.
[0014] Preferably, the step two calculates the mean and standard deviation of the pixels in the image to set a threshold, filter out invalid images, and prompt the user to adjust the light environment and reacquire the image. The specific steps are as follows:
[0015] The mean of the pixels is used to represent the average brightness of the whole image, and the standard deviation can reflect the difference of the pixels and the content of the effective information. The formula for calculating the mean and standard deviation of the image pixels is as follows:
[0016]
[0017] Where μ is the mean, I i is the gray 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 set a threshold to filter out invalid images, prompt the user to adjust the light environment and reacquire the image for subsequent detection, and avoid affecting the subsequent colorimetric analysis results.
[0021] Preferably, the mixed filter in step four is a median filter based on high-frequency enhancement of Gaussian filter. The specific steps are as follows:
[0022] (1) First, calculate the Gaussian blurred image of the original image, as 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] wherein H(x, y) is a high frequency component image;
[0028] (3) adjusting the high frequency component to 3 times gain, as shown in the following formula,
[0029] H'(x, y) = g H(x, y)
[0030] wherein H'(x, y) is the image after gain, g is a gain factor, g = 3.0;
[0031] (4) adding the enhanced high frequency component to the blurred image to obtain the high frequency enhanced result, as shown in the following formula,
[0032] E(x, y) = I(x, y) + H'(x, y)
[0033] wherein E(x, y) is the image after image superposition;
[0034] (5) removing noise by median filtering, as shown in the following formula,
[0035] O(x, y) = MedianBlur(E(x, y), k size )
[0036] wherein O(x, y) is the final output image after median filtering, k size is the convolution kernel size of median filtering (take k size = 3 x 3).
[0037] Preferably, in step five, the reference color block ROI region r i (x, y) is extracted in the color corrected image I(x, y) based on the image J(x, y) by shape contour features.
[0038] (1) contour primary screening
[0039] The contour primary screening is based on the edge enhanced image J(x, y), and is realized by means of contour area threshold, shape factor, compact value, and width-height ratio of minimum circumscribed rectangle, and the index set L1 of the contour primary screening is obtained by screening.
[0040] (2) contour secondary screening
[0041] The contours in the L1 set are arranged in descending order based on the contour center point abscissa, the contours in the set L1 are extracted according to the number of reference color blocks, the adjacent contour equidistance judgment and collinearity judgment are performed on the contours in each group, the group index set of the contours meeting the conditions is returned, the contour Hu moment of the contours meeting the equidistance judgment and collinearity judgment is calculated respectively, the contour group index set L2 of the most similar contour Hu moment is returned, and the rectangular fitting judgment is performed on each contour. If it meets the condition, it is the contour index set corresponding to the reference color block.
[0042] (3) Extracting the reference color block ROI
[0043] The boundary rectangle is drawn according to the contour corresponding to the contour group index set L2, in order to avoid positioning errors caused by image distortion and other factors, the boundary rectangle is retracted by a certain multiple as the reference color block ROI area r to be extracted i (x,y), i=0,1,2,3..., m-1; wherein m is the number of reference color blocks.
[0044] Preferably, the method for positioning and extracting the reagent block ROI area in step six according to the congruence and collinearity of the reference color block after color correction of the image I(x,y) is as follows:
[0045] Taking the horizontal right as the horizontal positive direction and the vertical downward as the vertical positive direction, the center point coordinates of the reference color block are recorded as (centerX i , centerY i ), the width of the reference color block is width i , and the height of the reference color block is height i , wherein i=0,1,2,3..., m-1; wherein 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. Then 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 factor.
[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 magnification 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 valid pixels (i.e., pixels that do not cross the boundary) in the reagent block ROI area t(x, y), accumulate the red, green, and blue color channels, sample the width and height of the image ROI area every p pixels, and calculate the average value R of each color channel based on the sum of the sampled colors 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 based on 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, blue component of the second color sample (Color 2) respectively:
[0059]
[0060] wherein, represent the average of the red component of the first color sample (Color 1) and the second color sample (Color 2), used to adjust the weight of the color difference formula.
[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, ΔB represent the red component difference, green component difference, blue component difference of the first color sample (Color 1) and the second color sample (Color 2).
[0065]
[0066] wherein, ΔE RGB represents the color difference of the first color sample (Color 1) and the second color sample (Color 2) by the RGB color model weighted color difference method.
[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), (x2, y2, z2) in three-dimensional space, then calculate the three-dimensional Euclidean distance formula:
[0069]
[0070] wherein, ΔE HSV represents 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 CIE XYZ color space, then convert from XYZ color space to Lab color space, and then calculate the perceived color difference, using the CIEDE2000 color difference formula:
[0073]
[0074] where ΔE Lab represents the color difference value, ΔL' represents the lightness difference, ΔC' represents the corrected chroma difference, ΔH' represents the corrected hue angle difference, S L represents the lightness weight parameter, S C represents the chroma weight, S H represents the hue weight factor, R T represents the rotation factor, and the parameter factor K L ,K C ,K H is equal to 1.
[0075] (4) Voting method to determine similar reference color blocks
[0076] According to the color difference formula in steps (1), (2), and (3) above, the color differences of C i and C t are calculated in the RGB, HSV, and Lab color spaces, respectively, and the results are denoted as ΔE RGB (C i ,C t ), ΔE HSV (C i ,C t ), and ΔE Lab (C i ,C t ), respectively, with the reference color block index i = 0, 1, 2, 3, …; wherein i Lab ,i HSV ,i RGB represent the reference color block indexes obtained by color difference formula analysis, respectively.
[0077] For the RGB color space, the reference color block index that minimizes the value of ΔE RGB (C i ,C t ) is calculated as follows:
[0078] i RGB = argmin i ΔE RGB (C i ,C t )
[0079] For the HSV color space, the reference color block index that minimizes the value of ΔE HSV (C i ,C t ) is calculated as follows:
[0080] i HSV = argmini ΔE HSV (C i ,C t )
[0081] For Lab color space, calculate the reference patch index that makes ΔE Lab (C i ,C t ) value minimum:
[0082] i Lab = argmin i ΔE Lab (C i ,C t )
[0083] Collect the most similar index calculated by three methods into a set:
[0084] Results = {i RGB ,i HSV ,i Lab}
[0085] Let i final be the final output reference patch corresponding index, count the number of occurrences of each patch index in Results Count(x i ), x i ∈Results.
[0086] If there is Count(x i )> = 2, that is, there is a duplicate value in the Results set, select the index with the most occurrences as the most similar reference patch i final :
[0087]
[0088] Otherwise, the elements in Results are not repeated, that is, i RGB , i HSV , i Lab correspond to values that are not equal to each other, at this time, according to the table lookup method, the most similar reference patch i final :
[0089] When i RGB , i HSV , i Lab values are not repeated, i RGB , i HSV , i LabEnumerate all possible permutations of the index list of elements, extract the middle element value of the permutation and arrange it from small to large to form the corresponding combination, when the element value in the combination is an arithmetic sequence, consider the detection valid, at this time record the flag as the middle value of the element in the combination, otherwise, consider the detection invalid, record the flag as-1, and prompt the user to re-detect. final =flag corresponding reference color block color is the most similar reference color of the reagent block, otherwise, consider the detection invalid and prompt the user to re-detect.
[0090] The beneficial effects of the present application are:
[0091] The present application designs a test paper image colorimetric analysis algorithm, which can be deployed based on mobile platforms such as smart phones, and for urine sodium detection test paper based on color reaction, without additional external devices, it has certain self-adaptation to different light environments, provides convenience for color vision deficiency patients to identify test paper colors, reduces the influence of subjectivity on the accuracy of the detection results, and the detection process is simple and fast. BRIEF DESCRIPTION OF DRAWINGS
[0092] Figure 1 The technical roadmap of the method of the present application is;
[0093] Figure 2 The urine sodium detection test paper sample graph used in the method of the present application is;
[0094] Figure 3 The user operation guide flowchart when collecting images is;
[0095] Figure 4 The effect diagram of edge enhancement processing when collecting images is;
[0096] Figure 5 The effect diagram of finding and drawing contours based on the enhanced edge graph is;
[0097] Figure 6 The boundary rectangle and the indented boundary rectangle of the reference color block drawn based on the shape contour feature detection are;
[0098] Figure 7 The placement position diagram of the test reagent block of the test paper strip is;
[0099] Figure 8 The boundary rectangle and the indented boundary rectangle of the test reagent block drawn based on the position and geometric relationship are;
[0100] Figure 9 The detection result based on the colorimetric analysis of the reference color block and the reagent block is. DETAILED DESCRIPTION
[0101] The application will be further described in conjunction with the drawings and specific implementation methods, which are not limitations to the protection scope of the application.
[0102] The application relates to a colorimetric analysis method of an ion concentration detection test paper suitable for a mobile phone App. Figure 1 The detection method is shown in the technical roadmap as shown in the figure, and a urine sodium detection test paper is used as a detection object. Figure 2 The complete detection steps of the method are as follows:
[0103] Step one: according to the operation instruction of the test paper, the reagent block and the reference color block after color development are placed in the App scanning frame, and a frame image I0(x, y) is acquired in real time.
[0104] Step two: for the acquired frame image I0(x, y), the mean value and the standard deviation of the pixels in the image are calculated to set a threshold value, invalid images are filtered, and the user is prompted to adjust the light environment and reacquire the image until an image I1(x, y) meeting the set threshold value is acquired; the specific steps are as follows:
[0105] In the application, the mean value of the pixels is used to represent the average brightness of the whole image, and the standard deviation can reflect the pixel difference and the content of the effective information of the image.
[0106]
[0107] Wherein, μ is the mean value, I i is the gray value of the i-th pixel, and N is the total number of pixels.
[0108]
[0109] Wherein, σ is the standard deviation of the image, and μ is the mean value.
[0110] The threshold value is selected as μ>=5 and σ>=2 through experimental test, when μ<5 or σ<2, the image is filtered as an invalid image, the user is prompted to adjust the light environment and reacquire the image for subsequent detection, so as to avoid affecting the subsequent colorimetric analysis result.
[0111] In the subsequent step, the image integrity is determined by detecting the reference color block number of the image I1(x, y), if the acquired image is incomplete, the image needs to be reacquired, and the user is prompted to adjust the shooting position and angle; according to the relationship between the contour area and the imaging distance, the user is prompted to adjust the shooting distance to control the imaging size and definition.
[0112] The user is prompted to adjust the image acquisition operation through the above method until a complete, clear and effective image is acquired, and the implementation process is shown in the figure. Figure 3
[0113] Step three: The camera will be affected by the surrounding light environment when collecting in natural environment, causing color deviation. Based on the gray world assumption and perfect reflection theory, the gain is calculated based on the average gray value to adjust the color channel, eliminate the color deviation caused by uneven illumination, and make the image color balanced. Then, the reflection gain is calculated based on the maximum value of each channel to correct the color of the image I1(x,y), so that the maximum value of each channel is close to and does not exceed 255, simulating the perfect reflection under ideal conditions, improving the accuracy of color extraction. The image after color correction is recorded as I(x,y).
[0114] The method of calculating the gain based on the average gray value to adjust the color channel is as follows:
[0115] (1) Calculate the average value of the R, G, and B channels of the image, respectively recorded as
[0116]
[0117] Where M and N are the width and height of the image, 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).
[0118] (2) Calculate the average gray value of the image
[0119] According to the average value of the three color channels, the average gray value of the image is calculated as
[0120]
[0121] (3) Calculate the gain of each channel
[0122] Based on the gray world theory, the gain of each color channel is calculated as R gain G gain B , to ensure that each channel remains balanced during the gray conversion process:
[0123]
[0124] (4) Apply the gain to adjust the color channel
[0125] Adjust the gain of each color channel, and the new color channel values are R'(i,j), G'(i,j), and B'(i,j), respectively:
[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] By adjusting RGB channels through the above steps, color deviation caused by uneven illumination is eliminated, and the accuracy of color extraction is improved.
[0130] After the above adjustment, 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, the maximum value of each channel after adjustment R max , G max , B max is calculated respectively:
[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 respectively, denoted as reflectGain R , reflectGain G , reflectGain B :
[0136]
[0137] (3) Apply the 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, complete color correction, R″(i,j), G″(i,j), B″(i,j) are the R, G, B component values of the pixel points after adjustment 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 processed through hybrid filtering, grayscale conversion, local adaptive thresholding, opening and closing operations, 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 as follows:
[0153] G(x,y)=GaussianBlur(I(x,y),k,σ)
[0154] Wherein, GaussianBlur(·) represents the Gaussian blur operation, I(x,y) is the input image, k is the convolution kernel size (k=3×3 in the present invention), σ is the standard deviation of the Gaussian function (σ=5 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 formula:
[0156] H(x,y)=I(x,y)-G(x,y)
[0157] where 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] where H'(x, y) is the image after gain, 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 enhanced result, as shown in the following formula,
[0162] E(x, y) = I(x, y) + H'(x, y)
[0163] where 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] where O(x, y) is the final output image after median filtering, k size is the convolution kernel size of median filtering (take k size = 3 x 3).
[0167] Through the above processing, noise can be effectively removed while protecting and enhancing edges and details.
[0168] (2) Image graying
[0169] For the filtered image O(x, y), use the weighted average method to weight average the three components with different weights to obtain a gray 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 gray value of position (i, j) in the image.
[0172] (3) Local adaptive threshold segmentation
[0173] In the scanning detection scene, it is difficult to guarantee the uniform illumination environment. The local adaptive threshold segmentation can deal with the problems of uneven illumination and noise interference, and can be used for multi-object segmentation in complex scenes. The adaptive threshold processing is performed on the image G(x, y) to obtain the image H(x, y).
[0174] Given the input image G(x, y), the mean value of the pixels in the field window is calculated:
[0175]
[0176] Where |W(x, y)| represents the area of the field window.
[0177] The local threshold T(x, y) is calculated:
[0178] T(x, y) = M(x, y) - C
[0179] Where C is a constant offset.
[0180] The local threshold T(x, y) is used for binaryzation processing of the image to obtain the output image H(x, y):
[0181]
[0182] (4) Opening and closing operation
[0183] Opening and closing operation are basic operation of mathematical morphology, which are erosion, dilation, opening and closing operation respectively. The principle of opening operation is to perform erosion operation first and then dilation operation, and opening operation can remove noise and eliminate small objects; closing operation is an opposite operation of opening operation, which is to perform dilation operation first and then erosion operation, and is usually used to fill small holes in foreground objects or erase small black spots on foreground objects. The opening and closing operation is performed on the image H(x, y) to remove irrelevant noise points and obtain the image L(x, y). The opening and closing operation process is as follows:
[0184] Opening operation is to perform erosion operation first and then dilation operation. A is opened with B mathematically defined as:
[0185]
[0186] Closing operation is to perform dilation operation first and then erosion operation. A is closed with B mathematically defined as:
[0187]
[0188] Where A is the original set or image, B is the structure element, and represents dilation operation, represents 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 images compared to other operators, so it is suitable for image processing tasks with high detail requirements. It can be used to detect edges, contours and other features in images. The Scharr operator is used for edge enhancement to strengthen its edge features.
[0191] The Scharr operator is a convolution kernel (also known as a convolution template) used to calculate the gradient of an image. It contains two 3x3 convolution kernels, one for calculating the gradient in the horizontal direction and the other for calculating the gradient in the vertical direction. These two convolution kernels can be represented as:
[0192] Horizontal direction Scharr convolution kernel:
[0193]
[0194] Vertical direction Scharr convolution kernel:
[0195]
[0196] Calculate the gradients in the horizontal and vertical directions, i.e., x and y directions, respectively:
[0197]
[0198] where 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 values of the x and y direction gradients to unsigned type:
[0200] |G x |=abs(G x )
[0201] |G y |=abs(G y )
[0202] Perform a weighted average of the x and y direction gradients to get the comprehensive gradient G:
[0203] G=0.5×|G x |+0.5×|G y |
[0204] Perform edge enhancement to get the processed image J(x,y).
[0205] The edge-enhanced image J(x, y) obtained by the above steps helps to improve the accuracy of the contour search detection, and the effect diagram after processing is as shown in Figure 4
[0206] Step five, based on the image J(x, y), the reference color block ROI region r i (x, y) in the color-corrected image I(x, y) is extracted by shape contour features, i = 0, 1, 2, 3…, m-1; if all reference color blocks are not detected, repeat step two to reacquire 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 imaging size and clarity meet the set requirements;
[0207] Step five, based on the image J(x, y), the reference color block ROI region r i (x, y) in the color-corrected image I(x, y) is extracted by shape contour features, i = 0, 1, 2, 3…, m-1; if all reference color blocks are not detected, repeat step two to reacquire 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 imaging size and clarity meet the set requirements;
[0208] (1) Contour preliminary screening
[0209] Based on the edge-enhanced image J(x, y), the preliminary screening of the contour is realized mainly by means of the contour area threshold, shape factor, compactness value, and width-height ratio of the minimum circumscribed rectangle, and the index set L1 of the preliminary screened contour is obtained.
[0210] a) Contour area threshold
[0211] According to the geometric optical imaging principle, the imaging area is inversely proportional to the square of the distance: when the distance of the object from the lens increases by one time, the imaging area in the image will be reduced to one fourth of the original; on the contrary, when the distance of the object from the lens is reduced by half, the imaging area will be increased to four times the original. If we know the imaging area A1 at a distance d1, the imaging area A2 at another distance d2 can be represented as:
[0212]
[0213] In order to ensure the imaging quality of the collected image, the shooting distance is set between 18 cm and 5 cm in the experiment, and the contour area value of the reference color block is about [1100, 14000], so that the area threshold [1100, 14000] can be set to retain the contour of the target reference color block and screen out other irrelevant target contours that exceed the area threshold range.
[0214] b) Shape factor and compactness value
[0215] After the profile area threshold method screening processing, there are still a large number of character symbols, test paper edge, noise light and shadow interference profile, through comparative analysis and experimental verification can be used shape feature (shape factor and compact value) to exclude interference profile. Shape factor describes the compactness (also known as elongation) of the region to some extent, which is not sensitive to scale change, and is not sensitive to rotation except for rounding error caused by discrete region rotation. Set the profile perimeter P, profile area A, then the shape factor F is calculated as follows:
[0216] F = P 2 / 4πA
[0217] Shape compactness measure compact value A P is the ratio of profile area and perimeter:
[0218]
[0219] Where A P is the area perimeter ratio, A is the profile area, P is the profile perimeter.
[0220] After many experimental tests, and based on the comparison analysis of other interference profile numerical relationship, set the shape factor F threshold value for [1.0, 1.6], A P value range [10, 24] can retain the reference color block profile while filtering interference profile well.
[0221] c) Minimum circumscribed oblique rectangle width height ratio
[0222] The width height ratio of the minimum circumscribed rectangle can reflect the elongation of the graph, and for the same shape but without similar relationship, the width height ratio of the minimum circumscribed oblique rectangle is also different.
[0223] R a = max(w, h) / min(w, h)
[0224] Where R a is the width height ratio of the minimum circumscribed oblique rectangle of the profile, w is the width of the profile circumscribed oblique rectangle, h is the height of the profile circumscribed oblique rectangle (assuming the actual width of the test paper reference color block is greater than the actual height).
[0225] (2) Profile two 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 the contour group index set that meets the conditions is returned. The contour Hu moments of the contours in the group that meet the equidistant and collinear judgments are calculated for contour matching, and the 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 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] 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, collinearity judgment is performed again. 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 y iis the horizontal and vertical coordinates of each point in the point set, n is the number of points. When |R| approaches 1, it means that there is a very strong linear relationship between the two variables, and the points are basically collinear. When |R| approaches 0, it means that there is no linear relationship between the two variables, and the point set is not collinear.
[0238] The contour group that meets the equidistance and collinearity can be matched by means of Hu moment, and the most similar contour group index in the contour group is returned.
[0239] Hu moment is a set of seven invariant moments based on image or shape, proposed by Hu, used to describe the shape features of two-dimensional image, which is a linear combination of normalized central moments. By combining different normalized central moments, an invariant function reflecting different features can be obtained, which has scale, rotation, scaling, mirror mapping (except h1) invariance. The calculation process of Hu moment is as follows.
[0240] a) original moment of image
[0241]
[0242] where I(x, y) is the pixel value of the image at coordinates (x, y).
[0243] b) centroid coordinates of image
[0244]
[0245] where, and represent the horizontal and vertical coordinates of the centroid coordinates, which are used for centering the image.
[0246] c) central moment
[0247]
[0248] where the central moment μ pq quantifies the shape features of the image with respect to the centroid.
[0249] d) normalized central moment η pq
[0250] where
[0251] normalized central moment η pq , the central moment is normalized to adapt to different scale images, with 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] where, Hu i represents the i-th Hu moment, seven invariants for describing shape features, which has robustness to translation, rotation and scale changes.
[0261] The contour Hu moment distance is calculated, and the formula is:
[0262]
[0263] where, represents the k-th Hu moment value of the i-th contour.
[0264]
[0265] Adjust the threshold huThreshold, if all distances d ij are less than the set threshold huThreshold, return the contour group index set L2 with the smallest Hu moment distance, which is the contour group index of the reference color block. The contour drawing effect diagram based on the search result is shown in Figure 5 .
[0266] (3) Extracting the reference color block ROI
[0267] According to the contour drawing boundary rectangle 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, picture distortion, shooting angle, etc., resulting in inaccurate position and size, so that the background area is selected out of bounds, reducing the signal-to-noise ratio of the image, and further affecting the subsequent color analysis. The urine sodium test paper used in this method has four concentration level reference color blocks of 0mM, 60mM, 180mM and 360mM, so the inlaid boundary rectangle is intercepted based on the boundary rectangle in the color corrected image I(x, y) as the ROI area r i (x, y), i = 0, 1, 2, 3, and the drawing of the reference color block boundary rectangle and the inlaid boundary rectangle is shown in Figure 6 .
[0268] Step six, for the convenience of image acquisition experiment analysis, set the test strip reagent block placement position, angle relative to the reference color block position fixed consistent, based on the similarity of reference color block, collinear position geometry relationship design experience formula can realize the detection of reagent block region positioning extraction, also to ensure the accuracy of the boundary extraction, a certain degree of indentation on the boundary after color correction image I(x, y) segmentation intercept as the extraction of the color developing reagent block ROI region t(x, y). The specific steps are as follows:
[0269] The placement position of the test strip detection reagent block relative to the reference color block is shown in Figure 7 , the four concentration levels of 0 mM, 60 mM, 180 mM and 360 mM rectangular reference color blocks are arranged equidistantly along the same horizontal line from left to right, with the color from light to deep.
[0270] Assuming that the horizontal right is the horizontal positive direction, and the vertical downward is the vertical positive direction, the center point coordinates of the 0 mM, 60 mM, 180 mM and 360 mM color blocks are recorded as (centerX i , centerY i ), the width of the reference color block is width i , and the height of the reference color block is height i , where i=0, 1, 2, 3. According to the spatial position relationship and geometric relationship, we have:
[0271] centerX0<centerX1<centerX2<centerX3
[0272] centerY0=centerY1=centerY2=centerY3
[0273] centerX1-centerX0=centerX2-centerX1=centerX3-centerX2>width i
[0274] Let the center point coordinates of the detection reagent block be (targetX, targetY), and since the target color developing reagent block can be approximated as a square, let its side length be targetLength, then the experience formula is:
[0275] targetLength=s*(height0+height1+height2+height3) / 4
[0276] targetX=centerX3+a*width3+b*targetLength
[0277] targetY = (centerY0 + centerY1 + centerY2 + centerY3) / 4
[0278] wherein a, b are empirical coefficients, s represents the scaling ratio, a = 1.15, b = 0.5, s = 0.8.
[0279] According to the test agent block center point coordinates (targetX, targetY), and the side length targetLength, the boundary rectangle can be drawn, but the drawn boundary rectangle may also be caused by calculation error, shooting angle, image distortion, etc. The color developing reagent block positioning deviation, the size is not accurate enough, the false frame selection background area leads to the reduction of the signal-to-noise ratio of the image, and the accuracy of the colorimetric analysis is affected, so the boundary rectangle is based on a certain scaling ratio to be indented as the extracted reagent block ROI area t(x,y), and the detected ROI area t(x,y) is drawn as shown in the boundary rectangle and the indented boundary rectangle. Figure 8
[0280] Step seven, using the jump point sampling mean method to extract the main color of the reference color block ROI area r i (x,y), i = 0, 1, 2, 3…, m-1, and record it as C i , wherein m is the number of reference color blocks; using 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 .
[0281] The step seven proposes a jump point sampling mean method to extract the main color of the ROI area r i (x,y), i = 0, 1, 2, 3 of 0mM, 60mM, 180mM, 360mM reference color block and the main color of the reagent block ROI area t(x,y), and the implementation process is as follows.
[0282] (1) Color value accumulation
[0283] For valid pixels (i.e. non-border pixels), take the step length as p jump point sampling, and accumulate the red, green and blue color channels:
[0284]
[0285] Wherein, W, H represent the width and height of the ROI area respectively, R total , G total , B total are the accumulated total of the red, green and blue color channels respectively, R(i,j), G(i,j), B(i,j) represent the red, green and blue color channel values of the pixel located at row i and column j.
[0286] (2) Actual sampling pixel number
[0287] Every p pixels in the image ROI region width and height in two dimensions are sampled, and the number of sampled pixels is:
[0288]
[0289] Wherein, n sample represents the total number of pixels actually sampled.
[0290] (3) Calculate the average color
[0291] According to the sum of the sampled color, the average value of each color channel is calculated:
[0292]
[0293] Wherein, R avg , G avg , B avg is the average value of red, green, blue color channel in the image block.
[0294] Step eight, respectively based on RGB, HSV, Lab color space respectively C i and C t Calculate the color difference, and determine the most similar reference color of the reagent block according to the voting mechanism.
[0295] The step eight proposes a method of calculating the color difference of C i and C t respectively based on RGB, HSV, Lab color space respectively, and determining the most similar reference color of the reagent block according to the voting mechanism, and the implementation idea is as follows:
[0296] From the point of view of physics, the perception of color is derived from the spectral energy distribution of electromagnetic radiation stimulating the retina, but human color perception is also related to many physical phenomena, neuropsychological effects and physiological behaviors, and the relationship is relatively complex. Colorimetric method of test paper is designed based on human color perception, so color similarity judgment based on multi-color space through color difference can fully utilize the color information in the image, and improve the robustness and accuracy.
[0297] (1) RGB color space weighted color difference
[0298] The traditional RGB color model does not model the way human beings perceive colors, specifically, human eye color perception is nonlinear and not completely orthogonal. Human eyes have different color discrimination abilities for different colors, and the perception of brightness is also nonlinear, for example, blue has little contribution to the perception of brightness, but human vision has very good color discrimination ability for blue. The use of traditional RGB model standard Euclidean distance formula for color similarity comparison is not ideal, and the use of RGB color model weighted color difference method is more consistent with human visual color perception and has better stability.
[0299] Assume C 1,R ,C 1,G ,C 1,B respectively represent the red component, green component, and blue component of the first color sample (Color 1), C 2,R ,C 2,G ,C 2,B respectively represent the red component, green component, and blue component of the second color sample (Color 2). Then an RGB weighted color difference formula is as follows:
[0300]
[0301] wherein, represents the average of the red components of the first color sample (Color 1) and the second color sample (Color 2), used to adjust the weight of the color difference formula.
[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] wherein, ΔE RGB represents the color difference of the first color sample (Color 1) and the second color sample (Color 2) by the RGB color model weighted color difference method.
[0308] (2) HSV color space color difference
[0309] HSV model is also a model based on human color perception, which is more suitable for image algorithms facing visual perception and color processing analysis.
[0310] a) RGB to HSV
[0311] In HSV color space, color is represented by hue (H), saturation (S) and value (V). h represents hue (H), ranging from [0, 360), s represents saturation (S), ranging from [0, 1], and v represents value (V), ranging from [0, 1]. Let r, g, b represent the red, green, and blue color channel components of the input color sample, respectively. Then:
[0312]
[0313] v = max
[0314] where max = max(r, g, b), min = min(r, g, b), and max and min represent the maximum and minimum values in the given color component.
[0315] b) Color distance calculation
[0316] To calculate the difference between two colors, first map the HSV space color value to a three-dimensional space coordinate system coordinate marked as (x, y, z), which mainly includes the following processes:
[0317] For the HSV value (h, s, v) of a color, its coordinate point (x, y, z) in three-dimensional space is defined, and the coordinate calculation formula is:
[0318]
[0319]
[0320] where R represents the maximum dimension of the HSV space, and angle represents the inclination angle of the HSV space.
[0321] To calculate the color distance, for two color samples, (h1, s1, v1) and (h2, s2, v2), substitute the coordinate calculation formula to get the corresponding coordinates (x1, y1, z1), (x2, y2, z2), then calculate the three-dimensional Euclidean distance formula:
[0322]
[0323] where ΔE HSV represents the color distance calculated based on the HSV color model.
[0324] (3) Lab color space color difference
[0325] Lab color space is a uniform color space, which is consistent with human visual perception, and is convenient for color difference calculation. When the color difference is recognized by the human eye and the difference is less than the color difference value of adjacent two levels in the Munsell system, it can reflect the actual perception of the observer to 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 the human eye to brightness, it is necessary to compensate for distortion to make the image look consistent with the characteristics of the human eye. The image is often gamma corrected. Before conversion to CIE XYZ, inverse gamma correction needs to be performed on the RGB values to make them linear RGB values r, g, b, and then mapped to CIE XYZ through matrix operation.
[0328]
[0329] Wherein, r, g, b are the RGB values after gamma correction.
[0330] Linear RGB values r, g, b are mapped to CIE XYZ color space, and X, Y, Z are calculated through the following matrix operation:
[0331]
[0332] Secondly, convert the CIE XYZ color space to the CIE Lab color space, and the conversion formula is:
[0333] Take the reference white point value as X r = 0.950456, Y r = 1.0, Z r = 1.088754, and normalize X, Y, Z relative to the reference white point X r , Y r , Z r :
[0334]
[0335] Apply the following nonlinear function to x r , y r , z r for nonlinear adjustment:
[0336]
[0337] Where ∈ = 0.008856, k = 903.3.
[0338] fx = f(x r ), f y = f(y r ), f z = f(z r ).
[0339] From the non-linear function results f x , f y , f z , calculate the three components of CIE Lab: L, a, b:
[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 two color points, CIELab values: (L1, a1, b1) and (L2, a2, b2), the color difference calculation process is as follows.
[0345] Calculate the lightness difference:
[0346] ΔL' = L2 - L1
[0347] Average lightness:
[0348]
[0349] Calculate the weight parameter of lightness:
[0350]
[0351] Calculate the chroma:
[0352]
[0353] Calculate the average chroma:
[0354]
[0355] Chroma 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 chroma difference:
[0363] AC' = C'2 - C'1
[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 be positive:
[0367] h i ' = h i ' + 2π (if h i ' < 0)
[0368] Corrected average hue angle:
[0369]
[0370] Calculate the hue difference:
[0371]
[0372]
[0373] Correction factor T:
[0374]
[0375] Hue weight factor S H :
[0376] S H = 1 + 0.015 · C' · T mean
[0377] Chroma weight S C :
[0378] S C = 1 + 0.045 · C' mean
[0379] Rotation factor R T :
[0380]
[0381] RT = -R C sin(2ΔΘ)
[0382] CIEDE2000 color difference formula:
[0383]
[0384] where, ΔE Lab represents the color difference value, generally, the parameter factor K L ,K C ,K H is 1.
[0385] (4) Voting method determines similar reference color blocks
[0386] In the method, the urine sodium test paper has four reference color blocks and one target reagent block (as shown in Figure Two ), which correspond to the color sets of 0 mM, 60 mM, 180 mM, and 360 mM concentration levels, respectively (the indexes are 0, 1, 2, and 3, respectively).
[0387] c = {C0, C1, C2, C3}
[0388] The reference color block main color value C i calculated by the skip-point sampling mean value method:
[0389]
[0390] The target test reagent block main color value C t calculated by the skip-point sampling mean value method:
[0391]
[0392] According to the color difference formula in (1), (2), and (3), the color differences of C i and C t are calculated in RGB, HSV, and Lab color spaces, respectively, and the results are denoted as ΔE RGB (C i ,C t ), ΔE HSV (C i ,C t ), and ΔE Lab (C i ,C t ), respectively, and the reference color block index i = 0, 1, 2, 3. Wherein i Lab ,i HSV ,i RGB respectively represent the reference color block indexes obtained by color difference formula calculation and analysis.
[0393] For RGB color space, compute the reference tile index that makes the ΔE RGB (C i ,C t ) value smallest:
[0394] i RGB = argmin i∈{0,1,2,3} ΔE RGB (C i ,C t )
[0395] For HSV color space, compute the reference tile index that makes the ΔE HSV (C i ,C t ) value smallest:
[0396] i HSV = argmin i∈{0,1,2,3} ΔE HSV (C i ,C t )
[0397] For Lab color space, compute the reference tile index that makes the ΔE Lab (C i ,C t ) value smallest:
[0398] i Lab = argmin i∈{0,1,2,3} ΔE Lab (C i ,C t )
[0399] Collect the most similar indices computed by the three methods into a set:
[0400] Results = {i RGB ,i HSV ,i Lab}
[0401] Let i final be the final output reference tile corresponding index, count the occurrence of each tile index in Results, Count(x i ), x i ∈ Results.
[0402] If there exists Count(x i )> = 2, i.e., there exists duplicate value in Results set, then consider the detection valid, select the index with the most occurrence as the most similar reference tile i final :
[0403]
[0404] Otherwise, the elements in Results are not repeated, i.e. i RGB , HSV , Lab The corresponding values are not equal to each other, at this time the most similar reference color block i final :
[0405] When i RGB , HSV , Lab The values are not repeated, i RGB , HSV , Lab Enumerate all possible permutations of the element index list, extract the middle element value of the permutation and arrange it from small to large to form the corresponding combination, when the element value in the combination is an arithmetic sequence, it is considered valid, at this time flag is the middle value of the combination; Otherwise, it is considered invalid, flag is-1, and the user is prompted to re-detect, as shown in Table 1. When it is considered valid, i final = flag corresponds to the most similar reference color index, otherwise it is considered invalid and the user is prompted to re-detect.
[0406] Table 1
[0407]
[0408] In summary, when it is considered valid, the most similar reference color index can be determined by voting method, and the color of the reference color block corresponding to the concentration level of the index is the closest color of the reagent block.
[0409] The method in the application is deployed to the mobile phone end through the App to scan and detect the urine sodium detection test paper after the color reaction, and the color closest to the reference color block is obtained by colorimetric analysis, so as to indirectly realize the determination of the concentration of sodium ions in urine, and the detection result is as shown in Figure 9 .
[0410] The above detailed description of the implementation of the application is combined with the drawings, although specific terms are used for description, but the protection scope of the patent cannot be limited by this, those skilled in the art can change or modify it after understanding the spirit and principles of the patent to achieve equivalent purposes, and such equivalent changes and modifications shall be covered within the scope defined by 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 the test strips and place the reagent block and reference color block that have fully reacted with the test liquid into the App scanning box to capture the frame image in real time. ; Step 2: For the acquired frame image , 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-collect the image until the image that meets the set threshold is collected ; Step 3: When the camera is collecting data in a natural environment, it will be affected by the surrounding lighting environment, causing 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, eliminating the color deviation caused by uneven lighting and making the image color balanced; then the reflection gain is calculated based on the maximum value of each channel to adjust the image. Perform color correction so that the maximum value of each channel is close to but not exceeding 255, simulating perfect reflection under ideal conditions and improving the accuracy of color extraction. The image after color correction is recorded as , Step 4: Image Perform hybrid filtering, grayscale, local adaptive threshold, opening and closing operations, and edge enhancement to obtain an edge-enhanced image. , reduce the probability of missed detection during contour search; Step 5: Image-based Image after color correction by shape contour features Extract the reference color block ROI area of the test paper in the image , =0, 1, 2, 3…, -1; among them is the number of reference color blocks; if not all reference color blocks are detected, repeat step 2 to recapture 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, 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, set the position and angle of the test strip reagent block relative to the reference color block to be fixed during each test. Through the reagent block boundary positioning method, according to the congruence and collinearity of the reference color blocks, the empirical formula is designed to obtain the image after color correction. Extract the reagent block ROI area ; Step 7: Use the jump point sampling mean method to calculate the reference color block ROI area , =0, 1, 2, 3…, -1 respectively extract the main color and record it as ,in is the number of reference color blocks; The reagent block ROI area was analyzed using the jumping point sampling mean method. The main color calculation is recorded as ; Step 8: Compare the color space in RGB, HSV and Lab respectively. and Calculate the color difference and record the results as 、 、 , let the reference color block index i = 0,1,2,3…; where They represent the reference color block indexes obtained by calculating and analyzing the color difference formula; For the RGB color space, the calculation makes The reference color patch index with the smallest value: For the HSV color space, the calculation makes The reference color patch index with the smallest value: For the Lab color space, the calculation makes The reference color patch index with the smallest value: The most similar indices calculated by the three methods are summarized into one set: remember The corresponding index of the final output reference color block is counted. The number of occurrences in , ; If exists >=2, that is If there are duplicate values in the set, the detection is considered valid and the index with the largest number of occurrences is selected as the most similar reference color block. : otherwise, The elements in are not repeated, that is 、 、 The corresponding values are not equal to each other. At this time, the most similar reference color block is obtained according to the table lookup method. : when 、 、 When the values do not repeat, 、 、 Enumerate all possible permutations of the element index list, extract the element values in the permutation and arrange them from small to large to form corresponding combinations. When the element values in the combination are an arithmetic progression, the detection is considered valid, and the flag is recorded as the median value of the elements in the combination; otherwise, the detection is considered invalid, the flag is recorded as -1, and the user is prompted to re-test; when the detection is considered valid, that is, the flag is not -1, =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.
2. A colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App according to claim 1, characterized in that, The specific steps of calculating the pixel mean and standard deviation in the image, setting the threshold, filtering invalid images, and prompting the user to adjust the lighting environment and re-capture the image in step 2 are as follows: The formulas for calculating the mean and standard deviation of image pixels are as follows: in, is the mean, is the image pixel value, is the total number of pixels; in is the standard deviation of the image, is the mean, It is The grayscale value of each pixel; When the mean and standard deviation of image pixels are less than the set threshold, the image is filtered out and the user is prompted to adjust the lighting environment and re-capture the image before subsequent testing to avoid affecting the subsequent colorimetric analysis results.
3. The colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App according to claim 1, characterized in that: The hybrid filtering in step 4 is a median filter based on Gaussian filtering and high-frequency enhancement, and the specific steps are as follows: (1) First, calculate the Gaussian blurred image of the original image. The operation is as follows: in, represents the Gaussian blur operation, is the input image, is the convolution kernel size, is the standard deviation of the Gaussian function, is the image after Gaussian blur; (2) Calculate the difference between the original image and the Gaussian blurred image, that is, the high-frequency component, as shown in the following formula: in, is the high-frequency component image; (3) Adjust the high frequency component to 3 times the gain, as shown in the following formula: in, is the image after gain, is the gain factor, = 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: in, is the image after image superposition; (5) Remove noise by median filtering, as shown in the following formula: in, is the final output image after median filtering, is the convolution kernel size of the median filter, =3×3.
4. The colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App according to claim 1, characterized in that: In step 5, based on the image Image after color correction by shape contour features Extract the reference color block ROI area , =0, 1, 2, 3…, The steps for -1 are as follows: (1) Initial screening of profile Based on edge enhancement image Perform preliminary screening of the contours using the contour area threshold, shape factor, compactness value, and aspect ratio of the minimum circumscribed oblique rectangle to obtain the index set for preliminary screening of the contours. ; (2) Contour secondary screening Will The contours in the set are sorted in descending order based on the horizontal coordinates of the contour center points, and the set is sorted according to the number of reference color blocks. Extract and group the contours in the , perform adjacent contour equidistant judgment and collinearity judgment on the contours in each group, return the index set of contour groups that meet the conditions, and then calculate the Hu moment of the contours in the group that meet the equidistant judgment and collinearity judgment for contour matching, and return the index set of the contour group with the most similar Hu moment. , and then perform rectangular fitting on each contour. If it meets the requirements, it is the contour index set corresponding to the reference color block; (3) Extract reference color block ROI Index collection by contour group Get the corresponding outline boundary rectangle, and use the boundary rectangle after a certain ratio of indentation as the reference color block ROI area to be extracted , =0, 1, 2, 3…, -1; among them is the number of reference color blocks.
5. The colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App according to claim 1, characterized in that: In the step 6, the empirical formula is designed based on the congruence and collinearity of the reference color blocks to obtain the image after color correction. The method for realizing the location extraction of the reagent block ROI area is as follows: The horizontal positive direction is rightward, and the vertical positive direction is downward. The coordinates of the center point of the reference color block are ( , ), the reference color block width is , the reference color block height is ,in =0, 1, 2, 3…, -1; among them is the number of reference color blocks; according to the spatial position relationship and geometric relationship, it is easy to get: The coordinates of the center point of the detection reagent block are recorded as ( , ), because the target color reagent block can be approximated as a square, and its side length is , then we can get the empirical formula: in , is the empirical coefficient, Indicates the zoom ratio; Therefore, according to the coordinates of the center point of the reagent block ( , ), and the side length As the bounding rectangle, it is indented at a certain magnification as the extracted reagent block ROI area .
6. The colorimetric analysis method for ion concentration detection test paper suitable for 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 is sampled. and reagent block ROI area Valid pixels, that is, pixels that do not cross the boundary, accumulate the red, green, and blue color channels, sample every p pixels in the width and height of the image ROI area, and calculate the average value of each color channel based on the sum of the sampled colors 、 、 As the extracted main color value.
7. The colorimetric analysis method for ion concentration detection test paper suitable for mobile phone App according to claim 1, characterized in that: In the step eight, the RGB, HSV and Lab color spaces are used to respectively and The steps to calculate color difference are as follows: (1) Calculate the weighted color difference in RGB color space Assumptions , , Respectively represent the red component, green component, and blue component of the first color sample Color 1. , , 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; in, 、 、 Represents 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; in, 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, they are and , calculate the corresponding coordinates in three-dimensional space , , then the formula for calculating the three-dimensional Euclidean distance is: in, 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: in, Indicates the color difference value, Represents brightness difference, represents the corrected saturation difference, represents the hue difference after the corrected hue angle, represents the weight parameter of brightness, represents the chroma weight, represents the hue weight factor, Represents the rotation factor, parameter factor , , The value is 1.
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