problem with image analysis

I got a problem where i have to do some color calculations.
I try to optimize a treshold value in a vision related problem.

Essentially i have to find out a treshold value so that from RGB values B + G channel must be lower than a certain threshold, ea something in the range of 9 to 20…
And if the combined RGB value is higher the color should turn Red.

So i used below node setup in cycles.


But i am doubting the results i get with Blender.
I guess that Mix nodes go from 0 to 254 by setting a value from 0 to 1.

In the divide node, the top number should be 9.0 instead of 1.0

But even so i get results that put me in doubts

0-255, the lower number would be 256? 9-20 refers to values in that 8bit range right? The clamping seems unnecessary. Maybe link the algo if it’s still borked.

Edit: If you’re checking values in the render results then I’d suggest outputting to an emission shader. Disable environment and any other lighting influences, or use an emission pass and check values there.

First: Cycles uses normalized color values, so there’s no need to use bits depth; just values from 0 to 1.

Second, if the threshold value is some number in a 8bit range, we need to normalize it. Let’s say that x=20 in a scale from 0 to 255; then |x|=x/255 => |x|= 0.7843

So what you really want is to check if (B+G)<(x/255), where x is your threshold value in the 0-255 scale…