Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public static double median_power(Byte[] pixels, int x_pixel, int y_pixel, int pixelRadius, int width)
  2. {
  3. List<double> powers_list = new List<double>();
  4.  
  5. //itterate on radius-run on x
  6. for (int x = x_pixel - pixelRadius; x <= x_pixel + pixelRadius; x++)
  7. {
  8. //if this pixels location out of bounds-don't try to add it to calculations
  9. if (x > image_size_x || x < 0) continue;
  10.  
  11. //itterate on radius-run on y
  12. for (int y = y_pixel - pixelRadius; y <= y_pixel + pixelRadius; y++)
  13. {
  14. //if this pixels location out of bounds-don't try to add it to calculations
  15. if (y > image_size_y || y < 0) continue;
  16.  
  17. //index is the pixel's trio(RBG) location in the array
  18. int index = ((y * width) + x) * 4;
  19.  
  20. Byte b = pixels[index + 0];
  21. Byte g = pixels[index + 1];
  22. Byte r = pixels[index + 2];
  23.  
  24. double power;
  25. //for black pixel- give
  26. if (r == 0 && g == 0 && b == 0) power = 0;
  27. else power = ColorTranslator.RGB_array_power(r, g, b);
  28.  
  29. powers_list.Add(power);
  30. }
  31. }
  32. double median = powers_list.ElementAt((int)Math.Floor((double)powers_list.Count/2.0));
  33. return median;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement