View Full Version : Comparing two colors in different colorspaces, how?
Chainmax
9th December 2005, 01:51
For RGB, I assume the process is as simple as to use the R, G and B values of each of the two pixels and then do whatever you want with that, but I imagine a similar operation can't be done in YUY2 or YV12. Is there a single way to do this that works on all three colorspaces? If not, how can this be done on YUY2 and YV12?
Guest
9th December 2005, 02:01
If you mean comparing two colors both in (say) YV12, then you just compare the respective Y, U, and V channels.
If you mean comparing a color in one space to a color in another space, then you have to convert one of them to the other first.
Chainmax
9th December 2005, 02:20
Nah, I meant comparing two colors in the same colorspace. One thing though: if comparing only the color, shouldn't Y be avoided then, or am I missing something?
Guest
9th December 2005, 03:07
if comparing only the color, shouldn't Y be avoided then Only if you think white is the same color as black. :)
Normally, one compares colors to within a "distance" tolerance. The distance between the colors can be defined in several ways. One way is to take the deltas of Y, U, and V and then calculate the square root of the sum of the squares of the deltas (Euclidian distance). You can weight Y differently from U and V if that suits your application better.
BTW, "empirical evidence suggests that distances in color spaces such as YUV or YIQ correspond to perceptual color differences more closely than do distances in RGB space." [John Cristy]
Chainmax
9th December 2005, 03:38
I was thinking of using euclidean distance with the deltas or maybe even just the sum of the absolute values of each delta.
So non-RGB colorspaces are better suited for representing color distances as seen by the human eye? That's very interesting, thanks for the heads-up :).
Guest
9th December 2005, 03:46
So non-RGB colorspaces are better suited for representing color distances as seen by the human eye? That's one opinion. Here's another:
http://www.compuphase.com/cmetric.htm
"Several individuals suggested a weighted Euclidean distance in R'G'B'... This function has practically the same result as YUV. Its simplicity and speed of calculation make it a better choice than YUV." [Unless, of course, your data is already in YUV! -- DAG]
Do a Google on "perceptual color distances" for more info than you could ever digest.
I said it just to get you thinking. :)
Chainmax
9th December 2005, 04:04
While we're at it, how slow would you estimate would be to calculate the color distance between all pixels and for example blue in, say, a 720x480 video?
Guest
9th December 2005, 04:27
How fast is your machine? What SIMD does it have? What is the distance algorithm?
I would just write it and then see how it performs. It should be pretty fast if you just use a SAD compared against a threshold.
mg262
9th December 2005, 12:01
Chainmax,
Is this any use?
http://forum.doom9.org/showthread.php?t=99890
Chainmax
9th December 2005, 12:52
neuron2: I wasn't asking for absolute speed, but rather a comparison against other filters based on a rough estimate. Why compare a SAD (going to read up on what it is) against a threshold if I'm just going to calculate euclidean distances and save each distance in an array or matrix?
mg262: ColourStabilise is very close to what I would intend one of the parts of the filter to do but not exactly. I'll have to do tons of reading (including learning C++ and avisynth filter programming) if I ever decide to take this on, so I'd rather try to come up with my own algos.
mg262
9th December 2005, 13:12
including learning C++ and avisynth filter programmingGo for it!
You're more than welcome to the source of that filter if it will be of any use (PM me).
I'm beginning to get curious about what you are trying to build, though...
Chainmax
9th December 2005, 13:15
Thanks. It's actually a very dumb (read: useless) filter, but I thought it would be fun to try and make it. If I wind up not doing it, at the very least I'll hand overthe idea and design to someone.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.