This project has moved. For the latest updates, please go here.

Get distance between colors

Jun 17, 2014 at 10:00 AM
Hello,
Is there any way to compare two colors and get the distance between them?
similar to the command of imagemagick:

compare -metric RMSE xc:Navy xc:blue null:
The return value is: 18844.1 (0.287543)

I tried "CompareTo" but only get 1 or 0
Thanks
Coordinator
Jun 17, 2014 at 11:10 AM
CompareTo only compares the Width*Height of both images. This is what you are looking for:
using (MagickImage navy = new MagickImage("xc:navy"))
{
  using (MagickImage blue = new MagickImage("xc:blue"))
  {
    double distance = navy.Compare(blue, Metric.RootMeanSquaredError);
    Console.WriteLine((Quantum.Max * distance).ToString());
    Console.WriteLine(distance.ToString());
  }
}
Jun 17, 2014 at 11:36 AM
Thanks, that's just what I needed !!