GRASS GIS 8 Programmer's Manual 8.2.1RC1(2022)-exported
getg.c
Go to the documentation of this file.
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
11#include <stdio.h>
12#include <math.h>
13#include <grass/gmath.h>
14
15
16int getg(double w, double *g[2], int size)
17{
18 long i, j, totsize, n, g_row;
19 float rsq, sigma, two_ssq, val, sum = 0.0;
20
21 totsize = size * size;
22 n = size / 2;
23 for (i = 0; i < totsize; i++) {
24 *(g[0] + i) = 0.0;
25 *(g[1] + i) = 0.0;
26 }
27
28 sigma = w / (2.0 * sqrt((double)2.0));
29 two_ssq = 2.0 * sigma * sigma;
30 for (i = 0; i < n; i++) {
31 g_row = i * size; /* start of row */
32 for (j = 0; j < n; j++) {
33 rsq = i * i + j * j;
34 val = (rsq / two_ssq - 1) * exp(-rsq / two_ssq);
35 *(g[0] + g_row + j) = val;
36 sum += val;
37 /* reflect into other quadrants */
38 if (j > 0) {
39 *(g[0] + g_row + (size - j)) = val;
40 sum += val;
41 }
42 if (i > 0) {
43 *(g[0] + (size - i) * size + j) = val;
44 sum += val;
45 }
46 if (i > 0 && j > 0) {
47 *(g[0] + (size - i) * size + (size - j)) = val;
48 sum += val;
49 }
50 }
51 }
52
53 *(g[0] + 0) -= sum; /* make sure sum of all values is zero */
54
55 return 0;
56}
int getg(double w, double *g[2], int size)
Definition: getg.c:16
float g
Definition: named_colr.c:8