Comparing pixels for color difference - taking Alpha into account

161 Views Asked by At

Say I want to compare pixels to see how similar in color they are. This wikipedia article describes how:

https://en.wikipedia.org/wiki/Color_difference

it says:

enter image description here

My question is, there not just a R,G,B component, but there is one more dimension - Alpha, which has to do with opacity. Is there a way to take the Alpha component into account?

Is it just one more independent variable as another dimension? If it's an independent variable, then it seems like we can just do:

$$distance = \sqrt{(R_2-R_1)^2 + (G_2-G_1)^2 + (B_2-B_1)^2 + (A_2-A_1)^2}$$

is that right or does it not make sense? I would prefer the using the squareroot instead of omitting it, to save a smaller number in a database.

1

There are 1 best solutions below

0
On

You should initially ask what the alpha channel means in your specific context. May be you mean the transparency and the color as two distinct concepts, so it would be pointless to compare them mixed up as a single RGBA value. However it is worth to try the four elements version of the formula against your environment, as it may perform quite well on checking whether two pixels differs by a very small RGBA distance.