Guest User

Untitled

a guest
Dec 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. void GaussImage(const Image8 &src_image, Image8 &dst_image)
  2. {
  3. double sigma = 1.25;
  4. int radius = 2;
  5.  
  6. double** kernel = NULL;
  7. double kernelSum = 0;
  8.  
  9. kernel = new double*[2 * radius + 1];
  10. for(int i = 0; i < 2 * radius + 1; ++i)
  11. {
  12. kernel[i] = new double[2 * radius + 1];
  13. }
  14.  
  15. for(int x = -radius; x <= radius; x += 1)
  16. {
  17. for(int y = -radius; y <= radius; y += 1)
  18. {
  19. kernel[x + radius][y + radius] =
  20. exp(-((x * x + y * y) / 2 / sigma / sigma))
  21. / 2 / M_PI / sigma / sigma;
  22.  
  23. kernelSum += kernel[x + radius][y + radius];
  24. }
  25. }
  26.  
  27. for(int x = -radius; x <= radius; x += 1)
  28. {
  29. for(int y = -radius; y <= radius; y += 1)
  30. {
  31. kernel[x + radius][y + radius] /= kernelSum;
  32. }
  33. }
  34.  
  35. dst_image.height = src_image.height;
  36. dst_image.width = src_image.width;
  37. dst_image.widthstep = src_image.widthstep;
  38. dst_image.data = new uint8_t[src_image.height * src_image.width];
  39.  
  40. double sum = 0;
  41.  
  42. for(int line = radius; line < src_image.height - radius; ++line)
  43. {
  44. for(int column = radius; column < src_image.width - radius;
  45. ++column)
  46. {
  47. sum = 0;
  48.  
  49. for(int i = -radius; i <= radius; i += 1)
  50. {
  51. for(int j = -radius; j <= radius; j += 1)
  52. {
  53. sum += kernel[i + radius][j + radius] * src_image.data[
  54. (line + i) * src_image.width + (column + j)];
  55. }
  56. }
  57.  
  58. dst_image.data[(line) * dst_image.width + column] = sum;
  59. }
  60. }
  61. }
Add Comment
Please, Sign In to add comment