GRASS Programmer's Manual  6.4.2(2012)
getg.c
Go to the documentation of this file.
00001 /*      Name:   getg.c
00002  *
00003  * Created:        Thu May 29 00:37:44 1986
00004  * Last modified:  Sat May 31 20:34:30 1986
00005  *
00006  * Purpose:        Get the laplacian of a Gaussian (not normalized).
00007  *
00008  * Author:         Bill Hoff,2-114C,8645,3563478 (hoff) at uicsl
00009  */
00010 
00011 #include <stdio.h>
00012 #include <math.h>
00013 #include <grass/gmath.h>
00014 
00015 
00016 int getg(double w, double *g[2], int size)
00017 {
00018     long i, j, totsize, n, g_row;
00019     float rsq, sigma, two_ssq, val, sum = 0.0;
00020 
00021     totsize = size * size;
00022     n = size / 2;
00023     for (i = 0; i < totsize; i++) {
00024         *(g[0] + i) = 0.0;
00025         *(g[1] + i) = 0.0;
00026     }
00027 
00028     sigma = w / (2.0 * sqrt((double)2.0));
00029     two_ssq = 2.0 * sigma * sigma;
00030     for (i = 0; i < n; i++) {
00031         g_row = i * size;       /* start of row */
00032         for (j = 0; j < n; j++) {
00033             rsq = i * i + j * j;
00034             val = (rsq / two_ssq - 1) * exp(-rsq / two_ssq);
00035             *(g[0] + g_row + j) = val;
00036             sum += val;
00037             /* reflect into other quadrants */
00038             if (j > 0) {
00039                 *(g[0] + g_row + (size - j)) = val;
00040                 sum += val;
00041             }
00042             if (i > 0) {
00043                 *(g[0] + (size - i) * size + j) = val;
00044                 sum += val;
00045             }
00046             if (i > 0 && j > 0) {
00047                 *(g[0] + (size - i) * size + (size - j)) = val;
00048                 sum += val;
00049             }
00050         }
00051     }
00052 
00053     *(g[0] + 0) -= sum;         /* make sure sum of all values is zero */
00054 
00055     return 0;
00056 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines