Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflowdiskussion on stackoverflow on the topic.

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the LabLab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.

Source Link
René
  • 421
  • 3
  • 7

You can use the fact that colors make up a (three dimensional) color space and calculate a distance in this color space. You then need to define a metric in this color space to find the distance between two colors.

E.g. the distance in a euclidean space between two points x = (x1, x2, x3) and y = (y1, y2, y3) is given by d(x,y) = sqrt( (y1-x1) * (y1-x1) + (y2-x2) * (y2-x2) + (y3-x3) * (y3-x3) ).

Now you can calculate the distance between a balls color and your background color and if it is too small, create a new random color and test again.

You will find that neither RGB nor even HSV are good color spaces for this task. The wikipedia article on color difference employs the Lab color space and gives several possible metrics.

There is also a diskussion on stackoverflow on the topic.