/// <summary> /// Returns the stamina of a GeneticPhoto relative to a target Bitmap /// </summary> /// <param name="photo"></param> /// <param name="bitmap"></param> /// <returns></returns> public static double GetStaminaRelativeTo(this GeneticPhoto photo, Bitmap bitmap) { double value = 0; for (int y = 0; y < photo.Height; y++) { for (int x = 0; x < photo.Width; x++) { System.Drawing.Color c = bitmap.GetPixel(x, y); Pixel p = new Pixel(c.R, c.G, c.B); value += Math.Abs(p.R - photo.Pixels[x, y].R); value += Math.Abs(p.G - photo.Pixels[x, y].G); value += Math.Abs(p.B - photo.Pixels[x, y].B); } } return((photo.Width * photo.Height) / value); }
public static void Sort(this GeneticPhoto[] photo, Bitmap bitmap) { double[] values = new double[photo.Length]; for (int i = 0; i < photo.Length; i++) { double max = photo[i].GetStaminaRelativeTo(bitmap); for (int j = i + 1; j < photo.Length; j++) { if (max < photo[j].GetStaminaRelativeTo(bitmap)) { max = photo[j].GetStaminaRelativeTo(bitmap); GeneticPhoto t = photo[j]; photo[j] = photo[i]; photo[i] = t; } } } }