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