Open Access Article
This Open Access Article is licensed under a Creative Commons Attribution-Non Commercial 3.0 Unported Licence

A new method for quantitation of cyanuric acid in water based on image analysis of drying patterns using computer vision

Neta Caspin, Olga Mindlina, Uriah H. Sharon, Vladimir V. Gridin, Maor Manevich and Israel Schechter*
Schulich Faculty of Chemistry, Technion – Israel Institute of Technology, Haifa 32000, Israel. E-mail: israel@technion.ac.il

Received 22nd December 2025 , Accepted 13th February 2026

First published on 23rd February 2026


Abstract

We present a simple, reagent-free method to quantify cyanuric acid (CYA) in tap water by analyzing the drying patterns of CYA solution droplets. The analytical signature is a set of white dendritic columns that grow radially from the droplet perimeter toward the center, a pattern not observed for other common dissolved organic compounds in tap water. Patterns were recorded with a basic optical camera under dark-field illumination, and their morphology varied systematically with CYA concentration. The deposits consist mainly of CYA together with ions naturally present in tap water. Using a deep learning model with data augmentation and statistical analysis, we proposed an algorithm for accurate quantitation over 0–120 ppm. The method performs best under neutral to slightly acidic conditions and is compatible with free-chlorine at the levels used for water sanitation. To our knowledge, this is the first demonstration of quantitation of an analyte in a complex mixture based on image analysis of droplet drying pattern. The approach is low cost and requires only imaging and data analysis, although it does require waiting for droplet drying (ca. 2 h under ambient conditions). The practical constraints include repeatable sampling volume (ca. 50 µL) and keeping illumination conditions as in the calibration set.


1. Introduction

Chlorine is commonly used to sanitize water, with a recommended free chlorine concentration of 1–3 ppm. However, exposure to sunlight can decompose 75–90% of free chlorine within two hours, particularly in outdoor pools. Trichloroisocyanuric acid (TCCA) is often added as both a chlorine source and a stabilizing agent that helps maintain the effective concentration of free chlorine, as illustrated in Fig. 1.1–3
image file: d5ay02122g-f1.tif
Fig. 1 The equilibrium between trichloroisocyanuric acid (TCCA) and cyanuric acid (CYA) in water maintains an effective free chlorine concentration. HOCl is the active disinfecting species.

TCCA is commonly introduced in water in the form of solid tablets that serve as a source of free chlorine. During use, these tablets slowly release chlorine through the decomposition of TCCA into hypochlorous acid (HOCl), the active disinfecting agent, and cyanuric acid (CYA), which acts as a stabilizer. To maintain free chlorine in the desired range, the CYA concentration should be about 30–50 ppm (mg L−1). Because CYA is a very stable compound and is not consumed in the disinfection process, its concentration in water continuously increases with repeated addition of TCCA tablets. WHO guidelines for safe recreational water environments state that the concentration of cyanuric acid should not exceed 100 ppm. For effective sanitation and due to toxicity reasons, water is often replaced when the CYA concentration exceeds 100 or 150 ppm. Consequently, regular monitoring of CYA concentration is essential.

High-performance liquid chromatography (HPLC) provides accurate determination of CYA in water. However, this technique requires expensive instrumentation and skilled operation, making it impractical for routine use in point-of-care testing.4–6 The standard analytical method for CYA determination is based on its complexation reaction with melamine, producing an insoluble white colloidal precipitate.7 The turbidity of the resulting suspension, measured against a calibration curve, provides an estimate of CYA concentration. Commercial kits based on turbidimetric or nephelometric measurements are available. Inexpensive kits (around $100) often yield unreliable results, while more precise instruments (e.g., Palintest, about $1500) require trained technicians and daily calibration using standard solutions.

The analytical error of turbidimetric and nephelometric methods typically ranges from 10 to 70%, depending on the concentration range and the equipment used. Inaccuracies arise from sedimentation of particles, light scattering by contaminants such as dust, and incomplete reagent dissolution.8,9

The drying patterns of aqueous solutions have been studied previously.10–18 For example, Wong et al.19 demonstrated that drying droplets containing polystyrene particles of different sizes (40 nm, 1 µm, and 2 µm) form concentric rings, with smaller particles accumulating in the outer rings and larger ones in the inner rings. This phenomenon was attributed to capillary flow induced by the coffee-ring effect (CRE), which dominates particle–particle interactions during rapid drying. Tap water20 and milk21 classification were achieved from images of the coffee-ring effect. Dried droplets were suggested for the quality control of medicines.22 The applications of coffee-ring effects in analytical chemistry have been recently reviewed.23 Dried deposits have been analysed using optical spectrometric methods (e.g., Raman) and by secondary ion mass spectrometry. However, to the best of our knowledge, no quantitative analytical method for a component in a mixture has been developed based on image analysis such drying patterns.

In this work, we introduce a new analytical approach for quantifying CYA concentrations in tap water by analyzing the drying patterns of CYA solution droplets. This method is simple and more cost-effective than existing techniques and can be applied on-site.

2. Experimental

2.1 Tap water

Tap water was collected from the Technion and from 5 different districts in Haifa area. The hardness was in the range of 80–120 ppm, alkalinity: 150–200 ppm, conductivity: 540–570 µS cm−1, TOC: 0.8–1.0 ppm, clorine: 0.2–0.3 ppm, fluoride: 0.4 ppm, iron, copper and lead below 1 ppm, and turbidity: 0.2–0.3 NTU.

2.2 Cyanuric acid solutions

Aqueous solutions of cyanuric acid (CYA) were prepared by accurately weighing solid CYA (99%, Alfa Aesar) on an analytical balance. The weighed CYA was dissolved in deionized water using a magnetic stirrer and subsequently diluted to the desired concentrations (10–150 ppm).

2.3 Other reagents

Na2CO3 (BDH chemicals ltd, England, 99.9%), CaCl2 (spectrum chemical, USA, 95%), and MgSO4 (BDH chemicals ltd, England, 99%), were used for the investigation of the contribution of ions in water to the development of the dendritic precipitate.

2.4 Preparation of drying patterns

Droplets of 50 ± 1 µL were deposited on various substrates and left to dry. This droplet volume was optimal for the stability of the drying patterns. Disposable polystyrene (PS) Petri dishes (Miniplast Ein-Shemer, Israel, 90 × 15 mm, produced in clean room), were found to be the most suitable surface. No cleaning or surface treatment were needed. The relatively high contact angle of water on PS provided droplet stability even when the dishes were moved. In addition, the transparency of the Petri dishes allowed straightforward imaging of the white residues against a dark background. Drying was performed both under ambient laboratory conditions (17–20 °C, 50–70% relative humidity) and in a box of controlled temperature and humidity (in the same range). Although the drying time (of ca. 2 h) is somewhat affected by these parameters, no significant influence on the final drying pattern was observed.

2.5 Imaging of drying patterns

The drying patterns were imaged using a simple Dino-Lite optical camera with no magnification and a resolution of 1024 × 1280 pixels. For measurements of pattern area, uniform top illumination was provided by eight LEDs. For dark-field imaging, the LEDs were switched off, and side illumination (90° angle) was supplied by a E27, 220 V 3 W, 6500 K LED lamp. The distance of the lamp to the center of the Petri dish was ca. 15 cm and the illumination geometry was kept constant throughout all experiments: the optical camera was places ca. 1 cm above the droplet. A glossy black paper background was used to achieve high contrast in the recorded images. All images were processed using ImageJ software to remove occasional reflections and artifacts out of the droplet area, caused by dust or surface imperfections. The automatic image processing options were turned off, and no filters or thresholds criteria were applied.

3. Results and discussion

3.1 Drying pattern of cyanuric acid solutions

After evaporation, droplets of tap water (TW) left faint turbid spots on the surface of polystyrene Petri dishes. In contrast, droplets of CYA solutions in TW produced distinctive drying patterns. Under side illumination, white dendritic columnar structures were observed, extending from the droplet perimeter toward its center. As illustrated in Fig. 2, increasing CYA concentration resulted in longer and more prominent columns. This figure provides intuitive impression of potential correlation between image characteristics and CYA concentration. This characteristic pattern was consistently reproduced in numerous samples prepared with tap water collected from different locations in the Haifa area, each containing added CYA. Under these conditions, the zero-ppm concentration resulted in practically black image with a few white lines at the perimeter (without the characteristic columnar dendritic shape). The proper quantitation algorithm will be presented in the following. Note that many photo replicates were taken, and each of them were slightly different. They were all used in the machine learning algorithm for the development of the calibration model.
image file: d5ay02122g-f2.tif
Fig. 2 Representative images of dried droplets at various CYA concentrations.

3.2 Uniqueness of the dendritic columns

For the drying pattern to serve as a reliable indicator of CYA concentration in tap water, it must be unique and specifically attributable to cyanuric acid. To verify this, drying patterns were examined for a variety of compounds that may occur in tap water. These compounds differed in solubility and molecular weight, yet none produced a pattern identical to that of CYA.

Some substances exhibited patterns that were somewhat similar, but clearly distinguishable. For example, urea produced deposits lacking the geometric crystals and elongated columns characteristic of CYA. Uric acid formed white solids with 90° angular features distributed across the entire spot, without the radial extension from the perimeter toward the center observed for CYA. Caffeine (though unlikely to be present in tap water) produced the most comparable pattern, displaying white columns; however, these were thinner and not radially oriented. Although the existence of other compounds with similar drying patterns cannot be completely ruled out, it is unlikely that such substances are present in tap water.

Another distinctive feature of this phenomenon is that the dendritic columnar pattern appears only when CYA is dissolved in tap water, and not in distilled or deionized water. In double-distilled water (DDW), drying of CYA droplets resulted in geometrically shaped crystalline sediments rather than radial columns, suggesting a conventional single-crystal growth process (Fig. 3, for 30 ppm CYA). The formation of columnar dendritic structures occurs only in solutions containing dissolved salts, highlighting the essential role of several ionic species naturally present in tap water.


image file: d5ay02122g-f3.tif
Fig. 3 Typical drying pattern of a droplet of cyanuric acid solution in double-distilled water (DDW). The deposits exhibit geometrical crystal shapes rather than the radial dendritic columns observed in tap water solutions.

We examined the effect of various salts typically present in tap water to determine which components are essential for the formation of the characteristic drying pattern of CYA. The results revealed that three salts play a critical role: Na2CO3, CaCl2, and MgSO4. The critical ions are Ca2+, Mg 2+ and CO32−.

In order to demonstrate the critical involvement of these ions, we performed energy-dispersive X-ray spectroscopy (EDS) analysis of the dendrites. The results are shown in Fig. 4.


image file: d5ay02122g-f4.tif
Fig. 4 Energy-dispersive X-ray spectrum (top), secondary electrons image and EDS elemental mapping (bottom) for drying pattern of a double distilled water solution contains CYA, Mg2+, Ca2+, Na+, CO32−, SO42−, Cl. The solution was allowed to dry on a silicon wafer.

This figure presents mapping images of dendritic structure in drying pattern of CYA and the three essential salts in DDW (∼100 ppm of MgSO4, CaCl2, Na2CO3, pH ≈ 6.9–7.1). EDS reveals that the dendritic solid contains CYA, since nitrogen (N) comes only from CYA in this solution. The solid also contains magnesium and calcium. The Mg is more dispersed, while the calcium is more located at the spheres observed in the SEM images. The location of these elements may indicate that the CYA grows on a thin layer of Ca and Mg salts that first precipitate from the solution. In that case, the tree may be composed of sodium (Na), since co-crystals of Na ions and CYA have been documented.

Na, Ca and Mg come as cations, so negative ions are needed for balancing. As can be seen, sulfur (S), that comes only from sulfate anions (SO42−) is very localized in its mapping EDS image. Sulfur is localized in the spheres on the dendritic structure, so it can be assumed that the spheres are composed of calcium sulfate (CaSO4) or one of its hydrates. Since chloride (Cl) is not a part of the dendritic structure, it can be concluded that the negative ions balancing the charges at the structure are carbonates (CO32−). MgCO3 and CaCO3 have a common phase diagram containing various types of co-crystals.

Oxygen and carbon EDS mapping are of low value because they compose both the CYA and the carbonate ions. The surface of silicon wafers itself is covered by a thin layer of silica (SiO2) that naturally formed in air.

Furthermore, the distinctive dendritic pattern was observed only within a pH range of 5.3–8.4, which definitely covers normal tap water. As shown in Fig. 5, out of this pH range, the dendritic sedimentation disappears.


image file: d5ay02122g-f5.tif
Fig. 5 Representative drying patterns of drops of cyanuric acid (∼90 ppm) in acidic (pH = 3), neutral, and basic (pH = 11) solutions. Only solutions in the neutral range result in the characteristic dendritic pattern.

Acidity can affect ingredients that have already been shown to be essential to the dendritic drying pattern: the CYA is a weak acid and the carbonate and sulphate ions, which are both bases. Probably a specific form of one of these compounds is essential for the dendritic growth, thus different acidity can prevent the dendritic growth. Also, the pH influences CYA speciation and interactions with Ca2+ and Mg2+, which are involved in the dendritic pattern formation.

The characteristic concentration of free chlorine in municipal tap water typically ranges from 0.2 to 2.0 ppm. Our experiments showed that free chlorine within 0–4 ppm range has no detectable effect on the drying pattern of CYA. This indicates that the observed pattern is associated with both CYA and TCCA species.

3.3 Algorithmic quantitation of CYA in tap water

Several computational algorithms were evaluated for detecting the characteristic drying pattern of CYA in tap water and for quantifying its concentration within the relevant range. The tested approaches included different methods of counting white pixels and measuring the diagonal lengths of the nth longest dendritic structures identified in each image. These algorithms showed a strong correlation between image features and CYA concentration, and, after appropriate optimization, yielded moderate calibration plots.

In order to improve the calibration plots, the performance of several deep learning models was examined. The most successful approach, described below, was based on a neural network architecture. Two different approaches were tested for neural network modelling:

The first approach is “simple model”, which assumes that only the CYA concentration influences the dried droplet patterns, while the effects of external conditions are neglected. Under this approach, all droplet images in the dataset are grouped solely by concentration, and their belonging to the same solution or to different solutions with the same concentration is not taken into account. Consequently, for this type of modeling, images of droplets from the same solution may appear in both the training and test sets.

The second approach is “safe model”, in which potential impact of external conditions is taken into account, and the assignment of droplet images to the same solution is important when splitting the data into training and test sets. For this type of modeling, images of droplets from the same solution are included in only one set: either the training set or the test set, but not both.

Dataset: the initial dataset consisted of 1503 images of dried droplets of CYA solutions in tap water, each representing a specific CYA concentration. The images had a resolution of 1280 × 1024 pixels. From each image, the non-zero region containing the dried drop was automatically cropped and resized to 256 × 256 pixels. These cropped regions formed the dataset used for training and testing the computer vision model. In total, 49 concentration levels were included, relatively evenly distributed across the range of 0–120 ppm. A detailed description of the dried drops dataset, including the distribution of image counts across different concentrations, is shown in Table 1.

Table 1 Data-splitting schemes applied in our study
  Training set Validation set Test set
No. of samples Description No. of samples Description No. of samples Description
Scheme 1 1295 Different number of images for different CYA concentrations, ranging from 16 to 100 98 Reserved from the training set, 2 images for each CYA concentration 208 16 images for zero concentration, 4 images for each non-zero concentration
Scheme 2 993 Different number of images for different CYA concentrations, ranging from 10 to 86 No Cross-validation with different training/test splitting 510 30 images for zero concentration, 10 images for each non-zero concentration


The relatively large number of images for the zero concentration in Table 1 is due solely to the higher number of zero-concentration images in the initial dataset compared with other concentrations.

For the simple model, both data-splitting schemes were used in the study. For the safe model, only Scheme 2 with a reduced training set was applied because the typical number of dried droplet images per solution in the initial dataset was 10 across different concentrations.

Dataset balancing and augmentation: the training dataset was initially unbalanced, as each class, defined by a specific CYA concentration, contained a different number of images, as described in Table 1. The objective of balancing was to ensure equal representation of all classes during training, allowing each concentration level to contribute equally to model learning. In our research, two different approaches to dataset balancing were applied: (a) data duplication and (b) data augmentation, in which additional images were generated by applying rotational transformations at various angles. Each approach increased the number of images for each concentration in the training set to 100.

Predicting CYA concentration using a neural network: estimating the concentration of CYA from an input image represents a computer vision problem that can be addressed through neural network modelling. Our approach employs transfer learning based on a pre-trained on ImageNet-21k Vision Transformer (ViT) base model.24 Each image of a dried droplet is processed through the pre-trained ViT to extract its final hidden state, which serves as the input to a custom Multi-Layer Perceptron (MLP). The MLP consists of several linear and activation layers, culminating in a fully connected (FC) output layer that produces anumerical value corresponding to the predicted CYA concentration.

Training and testing were performed using sets of ViT-derived hidden states extracted from dried droplet images, paired with their respective CYA concentration labels. It is noteworthy that transfer learning with ViT architecture has been shown to outperform convolutional neural networks trained from scratch, even for specialized image domains such as medical imaging.25,26 The overall architecture of the algorithm is shown in Fig. 6.


image file: d5ay02122g-f6.tif
Fig. 6 Schematic representation of the architecture of the proposed algorithmic system. The last hidden state from the ViT is a tensor with shape (N, 197, 768), and the MLP output is a tensor with shape (N, 197 × 32). Here, N denotes the batch size.

During training, the objective was to minimize the difference between the model's predicted output and the true CYA concentration labels corresponding to the input images from the training set. The Mean Squared Error (MSE) was used as the loss function. Optimization was performed using the Adam algorithm with a variable learning rate, initially set to 0.001 and gradually reduced to 0.0001 over the course of training. The training batches contained 20 samples. For all models discussed in the article, the training process lasted up to 25 epochs, an early-stopping mechanism was applied for Scheme 1, cross-validation was applied for Scheme 2, using three different training–test splits.

Evaluation metrics for the predictive model: the performance of the trained model was evaluated using two standard metrics: the Mean Absolute Error (MAE) and the coefficient of determination (R2), defined as follows:

image file: d5ay02122g-t1.tif

image file: d5ay02122g-t2.tif
where
image file: d5ay02122g-t3.tif

image file: d5ay02122g-t4.tif
Here, yi represents the true concentration values, fi the predicted values, and ȳ the mean of the true concentrations.

In the ideal case, where the predictions exactly match the true values, the R2 score equals 1. A baseline model that simply predicts the mean of the y-values yields an R2 score of 0. Therefore, the closer the MAE is to 0 and the closer the R2 value is to 1, the better the model's performance.

3.3.1 Simple model based on Scheme 1.
3.3.1.1 Performance of the trained prediction model and a statistical approach to model inference. The model was trained on the initial training set balanced through simple duplication of the training samples and evaluated on the test set. Fig. 7a presents a comparison between the ideal and predicted values as a function of CYA concentration, together with the corresponding performance metrics for the trained model. The LOD based on 95% confidence intervals is 7 ppm.
image file: d5ay02122g-f7.tif
Fig. 7 Results from simple model, using Scheme 1, without (a) and with (b) augmentation. Comparison between the ideal and predicted values as a function of CYA concentration, along with the corresponding performance metrics for the trained model.

For each concentration, the predicted value represents the mean of several test samples associated with that concentration. Although the trained model can generate predictions from a single image, using multiple images of dried droplets associated with the same CYA concentration and averaging the individual predictions yields more accurate and stable results. Table 2 illustrates this trend:

Table 2 Model performance as a function of the number of samples associated with the same CYA concentration and averaged for prediction. Simple model, dataset from Scheme 1, without augmentation
  MAE R2
Prediction from a single drop-image 7.62 0.904
Averaging over 3 drops for each non-zero concentration 6.36 0.930
Averaging over 4 drops for each non-zero concentration 5.46 0.949


Our cross-validation experiments, using different training–test splits, confirmed that increasing the number of drops used for averaging during the model inference step improves prediction accuracy. This implies that for more accurate analysis of CYA, several images of dried droplets from the same solution should be prepared as inputs to the trained prediction system, rather than relying on a single image.


3.3.1.2 Performance of the model trained on augmented datasets. The model was trained using the augmented training dataset and evaluated on the augmented test set. Data augmentation using various image rotations makes the prediction system insensitive to dried droplets image orientation and increases the variability of the dataset. Fig. 7b presents a comparison between the ideal and predicted values as a function of CYA concentration, together with the corresponding performance metrics for the trained model. The LOD based on 95% confidence intervals is 6 ppm.

Our findings show that the prediction accuracy of the model trained on augmented data remarkedly improves when augmentation techniques are also applied to the test images. In practical applications, this implies that an additional image preprocessing step should be incorporated into the prediction pipeline of models trained on augmented data. This step would apply the same model-specific augmentation transformations to incoming images, thereby enabling the use of augmented inputs for more robust and reliable predictions through averaging.

Table 3 illustrates a performance comparison between the model trained and evaluated on the initial dataset and the model trained and evaluated with data augmentation applied. In this table, the original test set refers to 4 drops for each non-zero concentration, while the augmented test set refers to 4 drops for each non-zero concentration augmented by rotations at different angles to yield 20 samples.

Table 3 Model performance with and without data augmentation. Simple model, dataset from Scheme 1
Training set Test set MAE R2
Original Original 5.46 0.949
Augmented Original 5.53 0.950
Original Augmented 6.09 0.925
Augmented Augmented 4.16 0.968


It is evident that the model trained on the original dataset is sensitive to drop-image orientation: a degradation in performance is observed on the augmented test dataset, despite the increased number of drops per concentration used for prediction and averaging. In contrast, the model trained on the augmented dataset and evaluated on the augmented test set demonstrates the best performance.

Our investigation confirmed that increasing the number of initial drops for the same CYA concentration, used for subsequent augmentation, prediction and averaging at the prediction stage, tends to improve prediction accuracy. Table 4 illustrates this trend:

Table 4 Model performance as a function of the number of initial samples associated with the same CYA concentration, augmented by rotations at different angles to yield 20 samples, and averaged for prediction. Simple model, dataset from Scheme 1, augmented
Test set MAE R2
1 drop for each concentration 5.81 0.934
3 drops for each non-zero concentration 4.39 0.966
4 drops for each non-zero concentration 4.16 0.968



3.3.1.3 Smoothing model: analysing the main trends of the prediction model through data grouping. In the original dataset, too many close concentration labels corresponding to different image groups were included, resulting in a relatively large number of classes (49). Such fine resolution increases the sensitivity of the model to measurement errors, which can affect the accuracy of neighbouring concentration values. To reduce the influence of these errors and to better capture the overall trends in the data, we rescaled the labelling by grouping images into broader concentration categories. New training and test datasets were generated accordingly, and a predictive “smoothing model” was trained and evaluated using these sets.

The results are shown in Fig. 8a. The predicted values up to approximately 74 ppm closely match the ground truth, following a trend line with a slope of 1. For predicted values above 74 ppm, however, the results deviate and align along a line with a slope smaller than 1. The LOD based on 95% confidence intervals is 8 ppm. To improve prediction accuracy in this range, a slope correction was applied. Specifically, for predicted values greater than 74 ppm, the slope of the prediction trend line was calculated as the average of the slopes between consecutive test points. For the predicted curve shown in Fig. 8a, the slope of the prediction trend line at high concentrations is 0.62. The results after slope correction are presented, in Fig. 8b. In this case, the LOD based on 95% confidence intervals is 6 ppm.


image file: d5ay02122g-f8.tif
Fig. 8 (a) Results for samplified model, dataset from Scheme 1, augmented, grouped, re-labeled. Comparison between the ideal and predicted values as a function of concentration labels, along with the corresponding performance metrics are shown for the smoothing model. (b) After applying slope correction.

Application of such slope correction must always be carried out with precaution, to avoid unjustified post hoc calibration. In this case the correction is justified because (a) it is supported by independent measurements: we observed the same slope change in calibration plots based on direct measurements of the number of white pixels in the images and of the length of the dendritic columns. (b) There is a physical explanation to the slope change: the physical mechanism of dendritic columnal sedimentation includes diffusion-controlled material supply plus directional preference due to kinetic material transfer (enhanced evaporation at the droplet perimeter and concentration and temperature gradients). Presenting and proving the mechanism responsible for the lower calibration plot slope at high concentrations is beyond the tasks of this paper, however, one can imagine that at high concentrations, the growth of the precipitate in the z direction (against gravity) becomes more significant. At low concentrations, the columns are short, which means that sedimentation is close to the perimeter, where the liquid layer above the surface is shallow. Thus, most sedimentation is parallel to the surface. At high concentrations, the columns continue to grow and reach the central parts of the droplet, where a thick layer of liquid is above them. This allows dendritic growing in the z direction, which cannot be measured by the camera placed from the top. If this, or a similar mechanism, is the reason for the slope change, the suggested correction is justified and not considered post hoc.

3.3.2 Simple model based on Scheme 2 (“small model”). The small model based on Scheme 2 was trained for further analysis of the prediction model trends. The training and test sets for the small model were augmented in the same way as for the initial model based on Scheme 1. Fig. 9 presents a comparison between the ideal and predicted values as a function of CYA concentration, together with the corresponding performance metrics for the trained small model. The LOD based on 95% confidence intervals is 6 ppm.
image file: d5ay02122g-f9.tif
Fig. 9 Comparison between the ideal and predicted values as a function of CYA concentration, along with the corresponding performance metrics for the trained small model. Simple model, dataset from Scheme 2, augmented.

The small model shows some performance degradation compared with the model trained on the initial augmented training set (Table 4), which is expected because the training set was reduced by approximately 20%. On the other hand, the same trend is observed: increasing the number of initial drops associated with the same CYA concentration, used for subsequent augmentation, prediction, and averaging at the inference stage, tends to improve prediction accuracy. This trend is presented in Table 5, which demonstrates the performance of the small model on different test sets, using varying numbers of samples per concentration for averaging at the prediction stage.

Table 5 Small model performance as a function of the number of initial samples associated with the same CYA concentration, augmented by rotations at different angles to yield 20 samples, and averaged for prediction. Simple model, dataset from Scheme 2, augmented
Test set MAE R2
1 drop for each concentration 6.11 0.930
3 drops for each non-zero concentration 5.14 0.954
4 drops for each non-zero concentration 4.94 0.957
10 drops for each non-zero concentration 4.73 0.962


The small model with smoothing produces a prediction curve is close to that shown in Fig. 8a, with a slope of the prediction trend line at high concentrations of 0.64 when tested on a dataset derived from the initial test set, containing 10 samples for each non-zero concentration.

3.3.3 Safe model based on Scheme 2.
3.3.3.1 Performance and trends of the safe model. For the safe model, images of droplets from the same solution were included in only one set: either the training set or the test set, but not both. The training and test sets were augmented in the same way as for the simple model, discussed earlier. Fig. 10 presents a comparison between the ideal and predicted values as a function of CYA concentration, together with the corresponding performance metrics for the trained safe model. The LOD based on 95% confidence intervals is 8 ppm.
image file: d5ay02122g-f10.tif
Fig. 10 Comparison between the ideal and predicted values as a function of CYA concentration, along with the corresponding performance metrics for the trained model. Safe model, dataset from Scheme 2, augmented.

The safe model shows noticeable performance degradation compared with the small model, which was trained on a dataset of the same size (Table 5). This implies that additional conditions, beyond the CYA concentration, might have an impact on dried droplet patterns. On the other hand, a common trend is still observed: increasing the number of initial drops associated with the same CYA concentration (for the safe model, from the same solution), used for subsequent augmentation, prediction, and averaging at the inference stage, tends to improve prediction accuracy. This is shown in Table 6, which demonstrates the performance of the safe model on different test sets, using varying numbers of samples per concentration for averaging at the prediction stage.

Table 6 Model performance for different number of initial samples from the same solution, augmented by rotations at different angles to yield 20 samples, and averaged for prediction. Safe model, dataset from Scheme 2, augmented
Test dataset MAE R2
1 drop for each concentration 7.43 0.892
3 drops for each non-zero concentration 6.52 0.930
4 drops for each non-zero concentration 5.75 0.943
10 drops for each non-zero concentration 5.59 0.945


Smoothing in the safe model follows the same trend observed for smoothing in the simple model approach. Fig. 11 presents a comparison between the ideal and predicted values as a function of CYA concentration, together with the corresponding performance metrics for the trained safe model with smoothing. The LOD based on 95% confidence intervals is 17 ppm.


image file: d5ay02122g-f11.tif
Fig. 11 Comparison between the ideal and predicted values as a function of concentration labels, along with the corresponding performance metrics for the smoothing model. Safe model, dataset from Scheme 2, augmented, grouped, re-labeled.

For the predicted curve shown in Fig. 11, the slope of the prediction trend line at high concentrations is 0.51.

Cross-validation with different training–test splits confirmed the consistent behavior of the trend lines produced by the smoothing models. The slopes and the prediction trend lines at high concentrations and the corresponding performance metrics for models trained using different training–test splits are shown in Table 7. Test sets 1 and 3 do not overlap, while other pairs of test sets have 30–40% overlap. Based on our experiments, applying slope correction with a common value such as 0.8 tends to improve prediction accuracy.

Table 7 Cross-validation results for safe model
Training test Before slope correction Slope at high concentrations After slope correction
MAE R2 MAE R2
Split 1 5.59 0.945 0.51 5.05 0.957
Split 2 5.17 0.949 0.51 4.48 0.963
Split 3 4.98 0.955 0.63 4.77 0.959



3.3.3.2 Applying slope correction to non-smoothed data in safe model. To further evaluate the improvement in prediction accuracy, slope correction procedure was applied to the original augmented dataset. For predicted values greater than 74 ppm, the corrected prediction was computed using the following equation:
New predicted value = (predicted value − 74)/slope + 74, slope = 0.80

A comparison between the ideal and predicted values as a function of concentration labels, along with the corresponding performance metrics, for the safe model with slope correction applied, is presented in Fig. 12. The LOD based on 95% confidence intervals is 7 ppm.


image file: d5ay02122g-f12.tif
Fig. 12 Comparison between the ideal and predicted values as a function of CYA concentration, along with the corresponding performance metrics for the trained model with slope correction applied. Safe model, dataset from Scheme 2, augmented.

The performance metrics in Fig. 12 demonstrate improved prediction accuracy compared with those in Fig. 10.

3.3.4 Recommendations for predicting CYA concentration using computer vision algorithm. Based on our research, the following recommendations can be formulated for implementing a quality prediction system:

• Collect a large, well-balanced dataset of dried droplet images covering the entire concentration range.

• Use transfer learning with a pre-trained Vision Transformer as the model architecture.

• At the inference stage, rely on averaging predictions from multiple droplet images rather than on a single droplet image.

• Apply geometric data augmentation, such as image rotations at various angles, during training.

• Include an augmentation block as part of the preprocessing pipeline of the deployed prediction system to augment input images during inference.

• Study the prediction curve trend and apply slope correction at high concentrations.

4. Conclusions

This work establishes a simple, reagent-free method for quantifying cyanuric acid (CYA) in tap water by analysing the drying patterns of 50 µL droplets. The analytical signature is a set of white dendritic columns that extend from the perimeter toward the center, whose morphology varies systematically with concentration. Using image analysis and a transfer learning based on a pre-trained Vision Transformer, we proposed an algorithm for accurate quantification over 0–120 ppm. The effect is observed in the pH range 5.3–8.4 and is not perturbed by free chlorine in the 0–5 ppm range, so the approach is directly compatible with fresh recreational water. Applicability to much more complex matrixes, such as active swimming pool waters, has not been investigated in this work. To our knowledge, this is the first demonstration that a drying pattern can be used for both identification and quantitation of an analyte in a mixture.

We studied two main models based on neural networks: the simple model, which assumes that only the CYA concentration influences the dried droplet patterns, and the safe model, which is more conservative and allows potential unknown influences to be taken into account. The simple model seems to work better using our data set, however, the safe model might be better under a different data set.

Both models seem to work well, however, one should always be suspicious when using such models: Does they work for the right reason, or for a wrong reason? Therefore, we started our investigation using simple and intuitive tests, such as counting white pixels (estimating the precipitate quantity) and measuring the diagonal lengths of the nth longest dendritic structures identified in each image. The results provided similar trends, and the application of the deep learning models just improved the calibration plots. Therefore, we believe that the model works for good reasons.

The analytical performance of the proposed method is less accurate than HPLC and other expensive laboratory methods, but is more accurate than the turbidimetric methods, which their reported error is 10–70%.8,9 This is especially true at higher concentrations where turbidimetric methods fail due to precipitation. In terms of cost, the turbidimetric methods utilizing an optical instrument, are more expensive. The turbidimetric methods based on human vision are less expensive, but the results are subjective.

The suggested method has the potential to be is low cost and suitable for on-site use, requiring only a smartphone camera, a mechanical setup to ensure fix photographing conditions, and software for analysis. Nevertheless, several practical constraints must be respected for reliable results. First, the droplet volume used during measurement should match the volume used for calibration. Second, illumination during acquisition should closely match the calibration setup. These constraints suggest that a dedicated device with fixed droplet dispensing and controlled lighting would be advantageous for routine water monitoring. Alternatively, users can prepare their own calibration sets under their specific imaging conditions. This might anyhow be necessary, since the method has not been validated for tap water from different cities/countries. Using a smartphone camera might also require personal calibration, because the effect of camera variability has not been studies yet. Currently, no such a practical device has been designed and tested. Further research is needed for testing sensitivity to water source, testing analysis in swimming pool environments, extending of the calibrated range, and integration of automated image capture and on-device processing to deliver robust, user-friendly field measurements.

Conflicts of interest

There are no conflicts of interest.

Data availability

The data supporting the findings of this study, including the figures data, are available from the corresponding author upon reasonable request.

Acknowledgements

The authors thank Omer Bachar for contributing the early methods of correlating CYA concentration to white pixels and their metrics.

References

  1. C. Salter and D. L. Langhus, J. Chem. Educ., 2007, 84, 1124,  DOI:10.1021/ed084p1124.
  2. R. Ondo, E. Blanco, L. Vázquez, M. D. Petit-Domínguez, C. Quintana and E. Casero, Microchem. J., 2024, 204, 111020,  DOI:10.1016/j.microc.2024.111020.
  3. A. Peter, B. Réty, C. Vaulot, W. Heni, T. Steinbauer and C. Matei Ghimbeu, Langmuir, 2023, 39, 12041–12052,  DOI:10.1021/acs.langmuir.3c01127.
  4. R. Cantú, O. Evans, F. K. Kawahara, L. J. Wymer and A. P. Dufour, Anal. Chem., 2001, 73, 3358–3364,  DOI:10.1021/ac001412t.
  5. Y. Wei, Y. Yang, B. Chen and B. Yang, Chemosphere, 2022, 292, 133378,  DOI:10.1016/j.chemosphere.2021.133378.
  6. Z. Chen, Y. Su, J. Chen, Z. Li and T. Wang, Front. Public Health, 2024, 11, 1294842,  DOI:10.3389/fpubh.2023.1294842.
  7. F. A. Kappi, G. Z. Tsogas, D. L. Giokas and A. G. Vlessidis, Microchim. Acta, 2014, 181, 623–629,  DOI:10.1007/s00604-014-1163-3.
  8. C. J. Downes, J. W. Mitchell, E. S. Viotto and N. J. Eggers, Water Res., 1984, 18, 277–280,  DOI:10.1016/0043-1354(84)90100-3.
  9. D. Latta, Journal of the Swimming Pool and Spa Industry, 1995, 1(2), 37–39 Search PubMed.
  10. V. Liamtsau, C. Fan, G. Liu, A. J. McGoron and Y. Cai, Anal. Chim. Acta, 2020, 1106, 88–95,  DOI:10.1016/j.aca.2020.01.042.
  11. A. Hussain, D.-W. Sun and H. Pu, Food Addit. Contam.,: Part A, 2019, 36, 851–862,  DOI:10.1080/19440049.2019.1591643.
  12. L. Zhang, P. Li and X. Bu, Anal. Bioanal. Chem., 2018, 410, 7599–7609 Search PubMed.
  13. J. Xu, J. Du, C. Jing, Y. Zhang and J. Cui, ACS Appl. Mater. Interfaces, 2014, 6, 6891–6897,  DOI:10.1021/am500705a.
  14. A. L. Marsico, B. Duncan, R. F. Landis, G. Y. Tonga, V. M. Rotello and R. W. Vachet, Anal. Chem., 2017, 89, 3009–3014,  DOI:10.1021/acs.analchem.6b04538.
  15. J. B. Hu, Y. C. Chen and P. L. Urban, Anal. Chim. Acta, 2013, 766, 77–82,  DOI:10.1016/j.aca.2012.12.044.
  16. X. Wang, W. Zhang, S. Wang, W. Liu, N. F. Liu and D. Zhang, Biochem. Eng. J., 2021, 176, 108176,  DOI:10.1016/j.bej.2021.108176.
  17. D. Zhang, B. Ma, L. Tang and H. Liu, Anal. Chem., 2018, 90, 1482–1486,  DOI:10.1021/acs.analchem.7b03790.
  18. L. Rada, Y. B. Tanrıverdi, Ö. E. Kara, E. M. Hemond and U. Tezel, in Intelligent Computing Systems, ISICS 2022, ed. C. Brito-Loeza, A. Martin-Gonzalez, V. Castañeda-Zeman and A. Safi, Commun. Comput. Inf. Sci., Springer, Cham, 2022, vol. 1569,  DOI:10.1007/978-3-030-98457-1_9.
  19. T. S. Wong, T. H. Chen, X. Shen and C. M. Ho, Anal. Chem., 2011, 83, 1871–1873,  DOI:10.1021/ac102963x.
  20. X. Li, A. R. Sanderson, S. S. Allen and R. H. Lahr, Analyst, 2020, 145, 1511,  10.1039/c9an01624d.
  21. J. N. Molina-Courtois, Y. J. A. Morales, L. Escalante-Zarate, M. Castelán, Y. J. P. Carreón and J. González-Gutiérrez, Appl. Sci., 2025, 15, 5676,  DOI:10.3390/app15105676.
  22. Y. J. P. Carreón, O. Díaz-Hernández, G. J. E. Santos, I. Cipriano-Urbano, F. J. Solorio-Ordaz, J. González-Gutiérrez and R. Zenit, Sensors, 2021, 21, 4048,  DOI:10.3390/s21124048.
  23. M. Yang, D. Chen, J. Hu, X. Zheng, Z. J. Lin and H. Zhu, TrAC, Trends Anal. Chem., 2022, 157, 116752,  DOI:10.1016/j.trac.2022.116752.
  24. Vision Transformer (ViT), https://huggingface.co/docs/transformers/en/model_doc/vit, accessed 22 December 2025.
  25. E. U. Henrya, O. Emebob and C. A. Omonhinmind, Vision Transformers in Medical Imaging: A Review, arXiv, 2022, preprint, arXiv:2211.10043,  DOI:10.48550/arXiv.2211.10043, https://arxiv.org/pdf/2211.10043.
  26. S. Aburass, O. Dorgham, J. Al Shaqsi, M. Abu Rumman and O. Al-Kadi, Vision Transformers in Medical Imaging: a Comprehensive Review of Advancements and Applications Across Multiple Diseases, J. Imaging Inform. Med., 2025, 38, 3928–3971,  DOI:10.1007/s10278-025-01481-y.

This journal is © The Royal Society of Chemistry 2026
Click here to see how this site uses Cookies. View our privacy policy here.