public GetPixel ( IntPoint point ) : Color | ||
point | IntPoint | Point's coordiates to get color of. |
return | Color |
public static int AvgColor(System.Drawing.Image img, int forceZeroBelow) { long total = 0; AForge.Imaging.UnmanagedImage umimg = AForge.Imaging.UnmanagedImage.FromManagedImage(new Bitmap(img)); for (int y = 0; y < umimg.Height; y++) { for (int x = 0; x < umimg.Width; x++) { Color c = umimg.GetPixel(x, y); total += forceZeroBelow > ((c.R + c.G + c.B) / 3) ? 0 : 255; } } return((int)((long)total / ((long)umimg.Width * (long)umimg.Height))); }
public static int[] Histogram(System.Drawing.Image img) { int[] ans = new int[256]; AForge.Imaging.UnmanagedImage umimg = AForge.Imaging.UnmanagedImage.FromManagedImage(new Bitmap(img)); for (int y = 0; y < umimg.Height; y++) { for (int x = 0; x < umimg.Width; x++) { Color c = umimg.GetPixel(x, y); ans[(c.R + c.G + c.B) / 3]++; } } int max = ans.Max(); for (int i = 0; i < 256; i++) { ans[i] = (int)Math.Round((double)ans[i] / (double)max * 255D, 0); } return(ans); }
/// <summary> /// Check if two images are the same /// </summary> /// <param name="img1">First image</param> /// <param name="img2">Second image</param> /// <returns></returns> private bool isSame(UnmanagedImage img1, Bitmap img2) { int count = 0, tcount = img2.Width * img2.Height; for (int y = 0; y < img1.Height; y++) for (int x = 0; x < img1.Width; x++) { Color c1 = img1.GetPixel(x, y), c2 = img2.GetPixel(x, y); if ((c1.R + c1.G + c1.B) / 3 > (c2.R + c2.G + c2.B) / 3 - 10 && (c1.R + c1.G + c1.B) / 3 < (c2.R + c2.G + c2.B) / 3 + 10) count++; } return (count * 100) / tcount >= 54; }