getg.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Name: getg.c
  2. *
  3. * Created: Thu May 29 00:37:44 1986
  4. * Last modified: Sat May 31 20:34:30 1986
  5. *
  6. * Purpose: Get the laplacian of a Gaussian (not normalized).
  7. *
  8. * Author: Bill Hoff,2-114C,8645,3563478 (hoff) at uicsl
  9. */
  10. #include <stdio.h>
  11. #include <math.h>
  12. #include <grass/gmath.h>
  13. int getg(double w, double *g[2], int size)
  14. {
  15. long i, j, totsize, n, g_row;
  16. float rsq, sigma, two_ssq, val, sum = 0.0;
  17. totsize = size * size;
  18. n = size / 2;
  19. for (i = 0; i < totsize; i++) {
  20. *(g[0] + i) = 0.0;
  21. *(g[1] + i) = 0.0;
  22. }
  23. sigma = w / (2.0 * sqrt((double)2.0));
  24. two_ssq = 2.0 * sigma * sigma;
  25. for (i = 0; i < n; i++) {
  26. g_row = i * size; /* start of row */
  27. for (j = 0; j < n; j++) {
  28. rsq = i * i + j * j;
  29. val = (rsq / two_ssq - 1) * exp(-rsq / two_ssq);
  30. *(g[0] + g_row + j) = val;
  31. sum += val;
  32. /* reflect into other quadrants */
  33. if (j > 0) {
  34. *(g[0] + g_row + (size - j)) = val;
  35. sum += val;
  36. }
  37. if (i > 0) {
  38. *(g[0] + (size - i) * size + j) = val;
  39. sum += val;
  40. }
  41. if (i > 0 && j > 0) {
  42. *(g[0] + (size - i) * size + (size - j)) = val;
  43. sum += val;
  44. }
  45. }
  46. }
  47. *(g[0] + 0) -= sum; /* make sure sum of all values is zero */
  48. return 0;
  49. }