Get quantitative value for color on two-color scale

2024/7/7 6:44:58

I have run a chemical test that produces a color depending on how much of a given chemical is in the sample. It is green if there is no chemical, and yellow if there is a saturating amount of chemical. I have used my camera to take pictures of several samples, and also developed a standard curve, where I add known amounts of chemical to the test, and take pictures of the results to compare the color of the result of my sample to these standards.

What I would like to do, is develop an algorithm that creates a two-color scale. One color is the test without any chemical (green), and the other color is the test saturated with chemical (yellow). And then when I input a sample color, the algorithm gives me a % Yellow output.

I have seen people try to create a gradient between to colors, but never read of someone trying to place colors onto that gradient.

I am already able to get the RGB color values of all my samples, so the actaul algorithm is fairly independent of any programming language (although I am familiar with C, C#, VBA, and python).

Can someone point me to a resource to do what I want to do?

Thank you,

Michael

Answer
  1. create table/function RGB = f(concentration)

    It is the opposite of what you want to do. The idea is to convert some continuous scalar variable (concentration) to RGB color (with some physical meaning). Here some examples of mine for this:

    • RGB values of visible spectrum
    • Star B-V color index to apparent RGB color
  2. Camera calibration

    As Mark Ransom suggested this step is necessary. I would try to place some markers in the view area to help with this. For example something like:

    markers

    Now pick the colors in the corner markers, compute how match they differ to your marker real colors and interpolate the whole image bilinear-ly. If you need bi-cubic (much better results) then use 16 markers. This process is very similar to this:

    • Enhancing dynamic range and normalizing illumination

    You will need to experiment what markers to use (just black&white, or just green&yellow or black&red&green&blue or combinations ...) so your results will keep the same for varying light conditions. Also you have to make the dependency shots you will base the #1 on again with markers because without them you could have errors in results ...

    Calibration step can be avoided only if your camera is pre-calibrated, the indicator is always the same color,material,roughness,shininess,... and the image is taken with uniformly constant illumination conditions (inside some box,same bulbs,same exposition,same pupil...) without any shadows,spots,etc... Setups like that are very expensive. The low cost hand held devices are around $10000 USD (usually used for color detection/testing in manufacturing to calibrate machines).

  3. conversion concentration = f(RGB)

    If the dependency in #1 is some kind of simple function then you can make its inverse algebraically and use it directly. If you construct the RGB diagrams as in the linked QA's you will see which channel(s) to use as input (sometimes you need just one).

    If the dependency is too complicated or not a function then you can use:

    • approximation search
    • LUT (look up table) to find 2 closest matches and interpolate
    • Reverse complex 2D lookup table

    In case the dependency is strictly non-increasing or non-decreasing you can also use binary-search for this.

https://en.xdnf.cn/q/119648.html

Related Q&A

how to save python session input and output [duplicate]

This question already has answers here:How to save a Python session, including input and output, as a text?(4 answers)Closed 2 years ago.All of the ways which discussed this question save the history …

flask_mysqldb Delete FROM variable table [duplicate]

This question already has answers here:Python sqlite3 parameterized drop table(1 answer)How do I use SQL parameters with python?(1 answer)Closed 6 years ago.So i use flask_mysqldb in a Flask(Python we…

Syntax Error at the end of a while loop

EDIT: This question was ask at the start of my learning process for python. The Syntax Error was produced by pythons IDLE with no trackback to speak of. This was the main cause of the problem and confu…

Creating an adjacency list class in Python

I was wondering how to create an adjacency list class Here is what I have so far:class AdjNode:def __init__(self, value):self.vertex = valueself.next = Noneclass Graph:def __init__(self):# Add edgesdef…

How can I separate a rust library and the pyo3 exported python extensions which wrap it

I have a rust library which provides useful functionality for use in other rust programs. Additionally I would like to provide this functionality as a python extension (using pyo3 and setuptools-rust, …

how do I count unique words of text files in specific directory with Python? [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

Python convert path to dict

I have a list of paths that need to be converted to a dict ["/company/accounts/account1/accountId=11111","/company/accounts/account1/accountName=testacc","/company/accounts/acc…

Python: How to download images with the URLs in the excel and replace the URLs with the pictures?

As shown in the below picture,theres an excel sheet and about 2,000 URLs of cover images in the F column. What I want to do is that downloading the pictures with the URLs and replace the URL with the…

I cant figure out pip tensorrt line 17 error

I couldnt install it in any way, I wonder what could be the cause of the error. I installed C++ and other necessary stuff I am using windows 11 I installed pip install nvidia-pyindex with no problem. S…

Extracting specific values for a header in different lines using regex

I have text string which has multiple lines and each line has mix of characters/numbers and spaces etc. Here is how a couple lines look like:WEIGHT VOLUME CHA…