[GRASS-SVN] r36892 - grass/trunk/raster/r.neighbors
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Apr 25 01:00:47 EDT 2009
Author: glynn
Date: 2009-04-25 01:00:47 -0400 (Sat, 25 Apr 2009)
New Revision: 36892
Modified:
grass/trunk/raster/r.neighbors/local_proto.h
grass/trunk/raster/r.neighbors/main.c
grass/trunk/raster/r.neighbors/readweights.c
Log:
Add Gaussian filter
Modified: grass/trunk/raster/r.neighbors/local_proto.h
===================================================================
--- grass/trunk/raster/r.neighbors/local_proto.h 2009-04-23 11:41:45 UTC (rev 36891)
+++ grass/trunk/raster/r.neighbors/local_proto.h 2009-04-25 05:00:47 UTC (rev 36892)
@@ -22,3 +22,4 @@
/* read_weights.c */
extern void read_weights(const char *);
+extern void gaussian_weights(double);
Modified: grass/trunk/raster/r.neighbors/main.c
===================================================================
--- grass/trunk/raster/r.neighbors/main.c 2009-04-23 11:41:45 UTC (rev 36891)
+++ grass/trunk/raster/r.neighbors/main.c 2009-04-25 05:00:47 UTC (rev 36892)
@@ -89,6 +89,7 @@
struct Option *method, *size;
struct Option *title;
struct Option *weight;
+ struct Option *gauss;
} parm;
struct
{
@@ -152,6 +153,12 @@
parm.weight->gisprompt = "old_file,file,input";
parm.weight->description = _("File containing weights");
+ parm.gauss = G_define_option();
+ parm.gauss->key = "gauss";
+ parm.gauss->type = TYPE_DOUBLE;
+ parm.gauss->required = NO;
+ parm.gauss->description = _("Sigma (in cells) for Gaussian filter");
+
flag.align = G_define_flag();
flag.align->key = 'a';
flag.align->description = _("Do not align output with the input");
@@ -174,6 +181,9 @@
if (parm.weight->answer && flag.circle->answer)
G_fatal_error(_("weight= and -c are mutually exclusive"));
+ if (parm.weight->answer && parm.gauss->answer)
+ G_fatal_error(_("weight= and gauss= are mutually exclusive"));
+
ncb.oldcell = parm.input->answer;
ncb.newcell = parm.output->answer;
@@ -227,6 +237,11 @@
if (!newvalue_w)
weights_mask();
}
+ else if (parm.gauss->answer) {
+ if (!newvalue_w)
+ G_fatal_error(_("method %s not compatible with Gaussian filter"));
+ gaussian_weights(atof(parm.gauss->answer));
+ }
else
newvalue_w = NULL;
Modified: grass/trunk/raster/r.neighbors/readweights.c
===================================================================
--- grass/trunk/raster/r.neighbors/readweights.c 2009-04-23 11:41:45 UTC (rev 36891)
+++ grass/trunk/raster/r.neighbors/readweights.c 2009-04-25 05:00:47 UTC (rev 36892)
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <math.h>
#include <grass/gis.h>
#include <grass/glocale.h>
#include "ncb.h"
@@ -23,3 +24,21 @@
fclose(fp);
}
+
+void gaussian_weights(double sigma)
+{
+ double sigma2 = sigma * sigma;
+ int i, j;
+
+ ncb.weights = G_malloc(ncb.nsize * sizeof(DCELL *));
+ for (i = 0; i < ncb.nsize; i++)
+ ncb.weights[i] = G_malloc(ncb.nsize * sizeof(DCELL));
+
+ for (i = 0; i < ncb.nsize; i++) {
+ double y = i - ncb.dist;
+ for (j = 0; j < ncb.nsize; j++) {
+ double x = j - ncb.dist;
+ ncb.weights[i][j] = exp(-(x*x+y*y)/(2*sigma2))/(2*M_PI*sigma2);
+ }
+ }
+}
More information about the grass-commit
mailing list