# Comparing two sets of pixels to determine whether they belong to the same object

I have two sets of data, and I want to know if the second set is sufficiently different from the first to be considered different.

More specifically, I have a sample set A from a number of pixels in the vicinity of point X in an image, and another sample B of pixels in the vicinity of point Y in the same image.

I want to know if point X and point Y could be part of the same object in the image (based on color values). For example, if A and B are both mostly blue then the answer is yes, but if A is red and pink and B is blue then the answer is no.

My only idea so far (based on vague memories of a statistics class I took years ago) is to calculate the standard deviation in A and B, and from that calculate a threshold that gives you 95% certainty, and see if they are within a certain distance of each other. Is this correct?

Otherwise, what's the best way to do this?

-
What sort of data you have? It seems like the Kolmogorov-Smirnov test could be appropriate here. It is used to check wether two samples come from the same distribution. It can be easily calculated in R with the command ks.test. –  user10525 May 9 '12 at 23:33
They are pixels from an image. More specifically, I have a border detection algorithm, but I want to verify borders by checking that pixels on opposite sides of the border are "different". –  CaptainCodeman May 9 '12 at 23:52
I'm used to seeing color defined by values on 3 different variables. Are you talking about color as something that can be defined by a value on a single variable? –  rolando2 May 10 '12 at 3:01
No, I'm using all 3 RGB values. So basically, a color is a point in 3D space. –  CaptainCodeman May 10 '12 at 10:44
Well, more accurately, in some parts (e.g. border detection) I'm effectively using one variable: I find the mean, and then use the distance from the mean as a one-dimensional variable. –  CaptainCodeman May 10 '12 at 11:03