# Isolating a change in color in OpenCV.

So I've been attempting some image manipulation and I've come across a problem which seems simple but I can't seem to wrap my head about.

How do you isolate a change in color?

Say you have a grey colored dot with a value of Red 100, Green 100, Blue 100

Then you put a blue overlay with values of R 4, G 10, B 251 with 50% opacity on that dot and end up with values of Red 72, Green 74, Blue 124

So the change is roughly Red -28, Green -26, Blue +24

The best Idea I have is to only take the positive values but even that seems wrong as R 0, G 0, B 24 is a far cry from R 4, G 10, B 251.

Is there a stupid easy function I'm missing or am I just over thinking it?

edit retag close merge delete

wouldn't it be easier to use hue, from HSV, then R,G,B values?

( 2015-08-04 02:27:04 -0500 )edit

With HSV wouldn't you still need the average for the H, S & V values individually?

( 2015-08-04 07:41:08 -0500 )edit

Sort by » oldest newest most voted

Two ways to solve your problem:

1. Take absolute difference between pixels. You will get the difference but lose the direction of difference.
2. Scale the difference such that -minval corresponds to 0. For example, you could scale it such that -255 is zero. In that case, your red which is -28 will show up as 227. You can adjust the code semantics to handle the rest.
more

The minval method is nice for showing a change but I just wanted some clarification. You said -28 would show up as 227 and I'm assuming a positive 28 would still show up as 28.

( 2015-08-04 12:32:34 -0500 )edit

No, the positive value will show up as 255+28=283. You will have to allocate at least a short rather than a char to hold the data. One possibility to do everything in 8 bits is to possibly divide by 2 and handle it accordingly but you will lose precision.

( 2015-08-04 12:42:54 -0500 )edit

Official site

GitHub

Wiki

Documentation