Ask Your Question

Isolating a change in color in OpenCV.

asked 2015-08-03 18:58:26 -0500

DDS_Mytheral gravatar image

updated 2015-08-03 19:03:39 -0500

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 flag offensive close merge delete


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

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-08-04 02:27:04 -0500 )edit

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

DDS_Mytheral gravatar imageDDS_Mytheral ( 2015-08-04 07:41:08 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-03 19:16:57 -0500

unxnut gravatar image

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.
edit flag offensive delete link 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.

DDS_Mytheral gravatar imageDDS_Mytheral ( 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.

unxnut gravatar imageunxnut ( 2015-08-04 12:42:54 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2015-08-03 18:58:26 -0500

Seen: 66 times

Last updated: Aug 03 '15