## 2 Materials and Methods
### Algorithm Design  
The overall flow of the algorithm is shown in Figure 5:  
* Step 1: Using threshold segmentation to find the control line  
Control lines on immunohistochemical stratigraphic strips tend to be dark and stable, and in this case, a binarization method is used to find the control line with good results. To determine the sum of pixel values for each column in the image, the following formula is used:  
\[S_{j}=\sum_{i=1}^{h}I_{i,j} \tag{1}\]  
where \(S_{j}\) is the sum of pixel values in the \(j\)th column, and \(I_{ij}\) is the pixel value at position [\(i\),\(j\)]. To obtain a threshold for binarization, the minimum pixel value in this one-dimensional image is added to an external value \(I=30\) (as determined from Figure 6 below). This result is then multiplied by the image height to yield the threshold:  
\[Threshold=(MinValue+I)^{H} \tag{2}\]  
Figure 4: The overall process of lateral flow immunoassay quantitative detection. Figure 5: Overall flowchart of the algorithm. where _MinValue_ is the minimum pixel value in the one-dimensional image that changes according to the pixel value of the image; and \(i\) is an externally set value. The _MinValue_ and \(I\) are added together and multiplied by \(H\). The result is the binarized threshold, which is just enough to segment the control line at this point. The left half of the image is horizontally flipped and then multiplied, mirroring the image for comparison. This process determines the width of the control line and obtains the position of the rightmost end of the control line. If the width of the control line is greater than 5 (a threshold set based on experimental experience to ensure algorithm performance and accuracy) and the numerical value of the rightmost end is greater than 0, the control line has successfully been segmented and detected. Subsequently, the width and position results are then output. * Step 2: Denoise processing  
After zooming in on the image of the test strip taken by the smartphone, we noticed that there are noises between the lines. Unfortunately, these noises are not fully eliminated by threshold segmentation in areas where the test strip is lighter in color. To address this, we implemented a denoising algorithm. After several experiments, median filtering was selected as the optimal method, which could effectively remove noises while retaining the image edge and detail information, thus improving reliability and accuracy. The median filtering results are shown in Figure 7.  
To binarize the image, the image pixel average is multiplied by a factor to determine the threshold, which is applied to the left half. This factor is reduced by 0.05, and pixel accumulation on the left half is used to calculate the signal-to-noise ratio (SNR). An SNR below 0.75 indicates significant remaining noise, which is addressed using morphological operations. The binarization results after noise removal are shown in Figure 8c. Figure 6: Graph showing the reasons for choosing threshold value I.  
Figure 7: Median filtering principle and an example of the effect. Step 3: Use of convolution and binarization to locate test lines  
When locating the control lines, the left half of the image is isolated and flipped horizontally. This flipped section is then subjected to dot-product operation with the initial unflipped region before the column vectors in the photo are summed into an array. A convolution operation is performed between this vector array and the result of the earlier dot-product operation:  
\[D(x,y)=I\_left(x,y)\times I\_flipped(x,y) \tag{3}\]  
\[\mathrm{C(K)}=\sum D(x,k)\times I\_column(x) \tag{4}\]  
In these calculation processes, _I_left(x,y)_ indicates the left half portion of _I(x,y)_ image, adopting image values of _I(x,y)_ on the image's left side while setting all other values as 0. _I_flipped(x,y)_ refers to a horizontal flip operation of _I(x,y)_ image, specifically represented by _I(width-x,y)_ wherein width is the image width. C(K) represents the _k_-th element in the convolution results.