jexiar

GeomAverage

Nov 13th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.60 KB | None | 0 0
  1. //условно говоря, ситуация следующая
  2.  
  3. double GetAverage (Bitmap image)
  4. {
  5.     double brightness = 0;
  6.     double product = 1;
  7.     int red = 0, green = 0, blue = 0;
  8.     int quantity = 0;
  9.  
  10.     for (int x = 0; x < image.Width; x++)
  11.     {
  12.         for (int y = 0; y < image.Height; y++)
  13.         {
  14.             red = image.GetPixel (x, y).R;
  15.             green = image.GetPixel (x, y).G;
  16.             blue = image.GetPixel (x, y).B;
  17.            
  18.             if (red || green || blue)
  19.             {
  20.                 brightness = red*0.299 + green*0.587 + blue*0.114;
  21.                 product *= brightness;
  22.                 quantity++;
  23.             }
  24.         }
  25.     }
  26.  
  27.     return Math.Power (product, 1/quantity);
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment