Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


phyitbos

Member Since 30 Sep 2012
Offline Last Active Oct 15 2012 11:36 PM

Posts I've Made

In Topic: Speedy Image Likeness Comparison

11 October 2012 - 11:22 PM

Thanks to everyone (especially Spiro for the continued support!) your answers have been very helpful! I've learned some very important things here Posted Image

In Topic: Speedy Image Likeness Comparison

11 October 2012 - 02:26 AM

Wow, yes apparently GetPixel is incredibly slow. I don't understand the idea behind image locking, but I found this post that explains how to get access to the bitmaps byte array.

http://stackoverflow.com/questions/1563038/fast-work-with-bitmaps-in-c-sharp

That cut the algorithms time down to 11 ms using the Marshal'ing method. To subtract the RGB values from each other just (aR+aG+aB)-(bR+bG+bB)?

In Topic: Speedy Image Likeness Comparison

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. Only about 15 ms for it to copy the images in to Bitmaps.

In Topic: What language is better to learn - C# vs. Java

09 October 2012 - 08:07 PM

My first real language that I taught myself (other than web script languages) was C#. It's still my favorite for general purpose applications. C# isn't the best for cross-platform, but if you are mostly going to write Windows applications, C# and the .NET Framework offer you more. Finally, once you know C#, Java comes secondhand, they are *very* similar.

PARTNERS