• Create Account

### #Actualphyitbos

Posted 11 October 2012 - 12:36 AM

I was going to move in to making it work for color images eventually, but I figured to start with greyscale cause it should be faster. Thanks for the tip about color images though.

Kinda expected it to go faster myself, so I wouldn't be surprised if something's wrong. Here's my function for it (C#):
private double GetEuclideanDistance(Image img1, Image img2)
{
int dist = 0.0;
try
{
Bitmap a = new Bitmap(img1);
Bitmap b = new Bitmap(img2);
if (a.Width != b.Width || a.Height != b.Height)
{
System.Windows.Forms.MessageBox.Show("Target comparable image does not have the same dimensions. Cannot get Euclidean Distance.");
return 0;
}
int nRows = a.Height;
int nCols = a.Width;
for (int row = 0; row < nRows; row++)
{
for (int col = 0; col < nCols; col++)
{
int d = a.GetPixel(col, row).ToArgb() - b.GetPixel(col, row).ToArgb();
dist += (d * d);
}
}
}
catch (Exception ex)
{
IEvo.ReportException(ex, "GetEuclideanDistance");
}
return Math.Sqrt(dist);
}

My timings show that it takes around 400ms to complete every time. Only about 15 ms for it to copy the images in to Bitmaps.

### #1phyitbos

Posted 11 October 2012 - 12:35 AM

I was going to move in to making it work for color images eventually, but I figured to start with greyscale cause it should be faster. Thanks for the tip about color images though.

Kinda expected it to go faster myself, so I wouldn't be surprised if something's wrong. Here's my function for it (C#):
private double GetEuclideanDistance(Image img1, Image img2)
{
int dist = 0.0;
try
{
Bitmap a = new Bitmap(img1);
Bitmap b = new Bitmap(img2);
if (a.Width != b.Width || a.Height != b.Height)
{
System.Windows.Forms.MessageBox.Show("Target comparable image does not have the same dimensions. Cannot get Euclidean Distance.");
return 0;
}
int nRows = a.Height;
int nCols = a.Width;
for (int row = 0; row < nRows; row++)
{
for (int col = 0; col < nCols; col++)
{
int d = a.GetPixel(col, row).ToArgb() - b.GetPixel(col, row).ToArgb();
dist += (d * d);
}
}
}
catch (Exception ex)
{
IEvo.ReportException(ex, "GetEuclideanDistance");
}
return Math.Sqrt(dist);
}

My timings show that it takes around 400ms to complete every time.

PARTNERS