[WIP] pH "detector/estimator" via computer vision

proculation

Bronze Supporter
Nov 16, 2020
18
Montreal, Canada
Pool Size
16000
Surface
Vinyl
Chlorine
Liquid Chlorine
Hi all !

I'm working on a program to estimate the pH from a picture of a phenol red based comparator test to help getting more precise result than with only eyes (and of course for colorblind people).

I've based my tests using the TF-100 Comparator Block and the results so far are quite good:

img_6088_720_ph_boxes.pngimg_6088_720_results_boxes.pngimg_6088_720_PH.png
image_720.png

I would like to extend the detection to other pH visual test blocks and maybe add machine learning (AI) capability. For that I would need quite a lot of pictures like the one shown above with the actual pH result from a pH meter.

So, if you want to contribute, please send pictures with the real pH result in this thread :cool:
Thanks,
O.
 
  • Like
Reactions: ScottieBones
How much does the background color and lighting affect the accuracy of your app?
 
How much does the background color and lighting affect the accuracy of your app?
Well, of course the background color/lighting behind should be uniform for accuracy. Preferably white/bright with low contrast. The most important factor is the uniformity. I'm doing some statistical calculations along the phenol red column results but if they are very different shades, it would probably be a bad result.

Send some pictures and I will send back the results.
 
Nice. :goodjob:

I am working on an app that reads all chemistry from a picture of the water, but I am not making much progress yet.

I am using A.I to train the app and it is slow going.
I tried to find AI models that would do what I want to do but found nothing that would fit. So I went the "old fashioned" way (statistical comparisons / normalizations). But if I get enough pictures and results, building an adaptable AI model is in the pipeline.
 
  • Like
Reactions: JamesW
There was a thread not so long ago that used a paint matching app or program to directly match the sample to the comparator. Might help.

I would include a rounding rule where your 7.35 reads as 7.4 etc. The extra decimal place is not needed and gives a false sense of accuracy.

Overall though, I think it’s a good idea to use the phenol test to check the accuracy of the handheld…
 
Last edited:
That's the thread that @AUSpool had in mind:

 
  • Like
Reactions: AUSpool
Good idea! How will you account for the variation in the digital photographs?
Hi :wave:!

Since I'm basing the comparisons of the pH "results boxes" column with the actual colors of the pH boxes in the picture instead of the "real" phenol red shades/hues/etc, that "bypasses" this problem. Of course, if the colors of your test kit are off (e.g. leaving your test block weeks outside with this bad guy:🌞), results will be off/bad.

I used the pictures of the thread that @mgtfp shared and here are the detected pH boxes and the "statistically normalized" colors:
1690747179101.png
From this picture:
img_111.png

The pH result:
img_111_PH.png
 
  • Like
Reactions: mgtfp and JamesW
The result should be 7.6, you can’t extrapolate past the precision of the the comparator.

Color comparison is tricky, I’ve made mistakes with that more than I would like to admit. There is actually three distinct pH results or levels to deal with here. The actual pH value of the water which is constantly changing, normally going up. The pH as read my the meter and the pH as indicated on the comparator. There are a bunch of variables to deal with. Sample collection, treatment of the sample, and proper calibration of the meter prior to any test. Unfortunately you have no control over any results that are posted from other users.
 

Enjoying this content?

Support TFP with a donation.

Give Support
The result should be 7.6, you can’t extrapolate past the precision of the the comparator.

Color comparison is tricky, I’ve made mistakes with that more than I would like to admit. There is actually three distinct pH results or levels to deal with here. The actual pH value of the water which is constantly changing, normally going up. The pH as read my the meter and the pH as indicated on the comparator. There are a bunch of variables to deal with. Sample collection, treatment of the sample, and proper calibration of the meter prior to any test. Unfortunately you have no control over any results that are posted from other users.

Hi @AUSpool ,
I forgot to send the reply I had written for your previous post... :oops:

I'm only using extra decimals for the development of my algorithm. In a production application, of course it would not show more than one decimal. That's also why I'm adding two green contours in the result image to show the higher and lower boundaries of it.

I think you misunderstand my goal: it is not to give the exact value of the pH from an image but to give the best estimation of it, with the sample collected and the picture taken. If the collected sample, the comparator, etc are wrong, the result will be wrong.

The end goal would be to maybe create a mobile app that would render your picture taken and give you an estimation of the result. e.g. for colorblind people or to confirm an visual estimation.
 
  • Like
Reactions: mgtfp
What I’m saying is that you are basing your results on flawed input data. You have no control over the “actual“ pH value provided by unknown users, from unknown pH meters without any knowledge how they have been calibrated. The opening post assumes that any pH meter value is more accurate then the phenol red test which is just not true. I’m no expert in statistics or data collection but I think my old statistics professor would not be happy with the outcome based on the input data.

I think your app idea has merit but you would need more control over the input data with multiple sample collections done in a controlled lab environment. But even more control over the input date I fear your heading down into pool store spin disk territory.
 
What I’m saying is that you are basing your results on flawed input data. You have no control over the “actual“ pH value provided by unknown users, from unknown pH meters without any knowledge how they have been calibrated. The opening post assumes that any pH meter value is more accurate then the phenol red test which is just not true. I’m no expert in statistics or data collection but I think my old statistics professor would not be happy with the outcome based on the input data.

I think your app idea has merit but you would need more control over the input data with multiple sample collections done in a controlled lab environment. But even more control over the input date I fear your heading down into pool store spin disk territory.
I totally understand your point. I don't want to use "unknown users'" pH meter as input data in what I'm doing. You are correct that unverified data don't belong in a statistical model. Again, my goal of gathering pictures is not about using them as "input data" per se. It's about testing different angles/models of pH block comparator/tuning element detections.

My model is not based on any selected/input data except what the picture contains: boxes shapes, pH number shown, color, position, shades/hues/etc. It attempts to extract the fundamentals of what the picture shows and estimate a result.
 
  • Like
Reactions: AUSpool
The result should be 7.6, you can’t extrapolate past the precision of the the comparator.

Color comparison is tricky, I’ve made mistakes with that more than I would like to admit. There is actually three distinct pH results or levels to deal with here. The actual pH value of the water which is constantly changing, normally going up. The pH as read my the meter and the pH as indicated on the comparator. There are a bunch of variables to deal with. Sample collection, treatment of the sample, and proper calibration of the meter prior to any test. Unfortunately you have no control over any results that are posted from other users.
PH is a tricky one. I have reservations of my abilities to compare colors so I normally ask family members for a second or third opinion.
We have a lab at work so I had the idea of taking a sample in and testing it there. I filled the sample bottle to the brim and tested it as soon as I arrived. The device I was using is a $2500 bit of gear that is apparantly calibrated daily. The results for this machine were about 0.3-0.4 lower than what I was getting on the drop test kits.
There was a second tester in a different location at work that would be somewhat cheaper than the first and it was reading about 0.2 lower than the drop test.

I don't know what to believe!
 
Make sure to take the drop test to work and test again at the same time of the fancy test. For example, chlorine could get reduced a bit (by oxidising the bottle surface), which reduces pH. Always compare test values of the exact same sample, and that includes the parameter "time".

And also make sure that the work equipment has been recently calibrated. EDIT: Just because someone ticked a box on a checklist doesn't mean that it actually had been done. It's like trusting the cleaning schedule at the Macca's toilets.
 
I always thought that the cya test could easily be estimated with computer vision. That should lend itself to a cell phone app given how simple the cv problem is.

I think your ph approach should work well since you are not really busy looking for a color but the relationship of a color to reference colors in the same image. As an estimator that sounds plausible to me and should help remove concerns about underlying noise from different cameras etc
 
I always thought that the cya test could easily be estimated with computer vision.

What do you mean by computer vision. Photo analysis adds extra layers of potential error. Zeroing the meter, condition of cuvetts, light source selection of conversion factor.

Hi :wave:!

Since I'm basing the comparisons of the pH "results boxes" column with the actual colors of the pH boxes in the picture instead of the "real" phenol red shades/hues/etc, that "bypasses" this problem. Of course, if the colors of your test kit are off (e.g. leaving your test block weeks outside with this bad guy:🌞), results will be off/bad.

I used the pictures of the thread that @mgtfp shared and here are the detected pH boxes and the "statistically normalized" colors:
View attachment 518459
From this picture:
View attachment 518460

The pH result:
View attachment 518461

I often take a photo of my comparator to second guess myself. It’s best to edit out everything other than the sample and comparison squares. The extra information can trick the eye. Photos should also be taken with a while background behind. In the pic below I’m 7.6 with the taken with a white light box behind.

IMG_5938.jpeg
 
Thread Status
Hello , This thread has been inactive for over 60 days. New postings here are unlikely to be seen or responded to by other members. For better visibility, consider Starting A New Thread.