[GRASS-SVN] r61205 - in grass-addons/grass7/imagery: . i.destripe

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 8 20:07:37 PDT 2014


Author: ychemin
Date: 2014-07-08 20:07:37 -0700 (Tue, 08 Jul 2014)
New Revision: 61205

Added:
   grass-addons/grass7/imagery/i.destripe/
   grass-addons/grass7/imagery/i.destripe/Makefile
   grass-addons/grass7/imagery/i.destripe/fourier.c
   grass-addons/grass7/imagery/i.destripe/i.destripe.html
   grass-addons/grass7/imagery/i.destripe/main.c
Modified:
   grass-addons/grass7/imagery/Makefile
Log:
Add i.destripe

Modified: grass-addons/grass7/imagery/Makefile
===================================================================
--- grass-addons/grass7/imagery/Makefile	2014-07-09 03:01:47 UTC (rev 61204)
+++ grass-addons/grass7/imagery/Makefile	2014-07-09 03:07:37 UTC (rev 61205)
@@ -3,6 +3,7 @@
 # i.fusion.brovey deprecated
 
 SUBDIRS = \
+	i.destripe \
 	i.eb.hsebal95 \
 	i.eb.z0m \
 	i.edge \
@@ -16,6 +17,7 @@
 	i.points.auto \
 	i.rotate \
 	i.segment.gsoc \
+	i.spec.unmix \
 	i.vi.mpi \
 	i.wavelet
 

Added: grass-addons/grass7/imagery/i.destripe/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.destripe/Makefile	                        (rev 0)
+++ grass-addons/grass7/imagery/i.destripe/Makefile	2014-07-09 03:07:37 UTC (rev 61205)
@@ -0,0 +1,11 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.destripe
+
+LIBES = $(RASTERLIB) $(GISLIB) $(MATHLIB)
+DEPENDENCIES = $(RASTERDEP) $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+
+default: cmd

Added: grass-addons/grass7/imagery/i.destripe/fourier.c
===================================================================
--- grass-addons/grass7/imagery/i.destripe/fourier.c	                        (rev 0)
+++ grass-addons/grass7/imagery/i.destripe/fourier.c	2014-07-09 03:07:37 UTC (rev 61205)
@@ -0,0 +1,37 @@
+#include<stdio.h>
+#include<math.h>
+#include <grass/gis.h>
+
+#define PI 3.1415926
+#define HARMONIC_MAX 50000
+
+
+void fourier(DCELL *t_sim,DCELL *inrast,int length,int harmonic_number){
+	int u, t, col;
+	double t_obs[HARMONIC_MAX] = {0.0};
+	for (col = 0; col < length; col++)
+		t_obs[col] = (double) inrast[col];
+	double fcos[HARMONIC_MAX] = {0.0};
+	double fsin[HARMONIC_MAX] = {0.0};
+	double fm[HARMONIC_MAX] = {0.0};
+	double fp[HARMONIC_MAX] = {0.0};
+
+	//Generate F[u], Fm[u] and Fp[u] for u=1 to q
+	//u is spectral dimension
+	//t is temporal dimension
+	for (u=0;u<harmonic_number;u++){
+		for (t=0;t<length;t++){
+			fcos[u] = fcos[u]+t_obs[t]*cos(2*PI*u*t/length);
+			fsin[u] = fsin[u]+t_obs[t]*sin(2*PI*u*t/length);
+		}
+		fcos[u]	= fcos[u]/length;
+		fsin[u]	= fsin[u]/length;
+		fm[u]	= pow(pow(fcos[u],2)+pow(fsin[u],2),0.5);
+		fp[u]	= atan2(fcos[u],fsin[u]);
+	}
+	for (t=0;t<length;t++){
+		for (u=0;u<harmonic_number;u++){
+			t_sim[t] = t_sim[t]+fm[u]*(cos((2*PI*u*t/length)-fp[u])+sin((2*PI*u*t/length)+fp[u]));
+		}
+	}
+}

Added: grass-addons/grass7/imagery/i.destripe/i.destripe.html
===================================================================
--- grass-addons/grass7/imagery/i.destripe/i.destripe.html	                        (rev 0)
+++ grass-addons/grass7/imagery/i.destripe/i.destripe.html	2014-07-09 03:07:37 UTC (rev 61205)
@@ -0,0 +1,27 @@
+<h2>DESCRIPTION</h2>
+
+<em>i.destripe</em> Destripes in a row-based Fourier smoothing way. 
+Requires a near vertical striping. 
+
+Input:
+<ul>
+ <li>Number of harmonics to use for reconstruction (less is smoother output).
+</ul>
+
+<h2>NOTES</h2>
+
+<h2>TODO</h2>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="i.rotate">i.rotate</a><br>
+</em>
+
+<h2>REFERENCES</h2>
+
+<h2>AUTHORS</h2>
+
+Yann Chemin, International Water Management Institute, Sri Lanka.
+
+<p><i>Last changed: $Date: 2014-07-09 20:34:41 +0530 (Wed, 09 Jul 2014) $</i>

Added: grass-addons/grass7/imagery/i.destripe/main.c
===================================================================
--- grass-addons/grass7/imagery/i.destripe/main.c	                        (rev 0)
+++ grass-addons/grass7/imagery/i.destripe/main.c	2014-07-09 03:07:37 UTC (rev 61205)
@@ -0,0 +1,107 @@
+
+/****************************************************************************
+ *
+ * MODULE:       i.destripe
+ * AUTHOR(S):    Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE:      Destripe a regularly striped image using Fourier
+ *               Row based, works with stripes about up-down direction
+ *
+ * COPYRIGHT:    (C) 2014 by the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *   	    	 License (>=v2). Read the file COPYING that comes with GRASS
+ *   	    	 for details.
+ *
+ *****************************************************************************/
+   
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
+
+void fourier(double *t_sim,double *t_obs,int length,int harmonic_number); 
+
+int main(int argc, char *argv[]) 
+{
+    int nrows, ncols;
+    int row, col;
+    struct GModule *module;
+    struct Option *input1, *input2;
+    struct Option *output;
+    struct History history;	/*metadata */
+    struct Colors colors;
+    char *result;	/*output raster name */
+    int infd, outfd, ha;
+    char *in;
+    void *inrast;
+    DCELL * outrast;
+    CELL val1, val2;
+    
+    /************************************/ 
+    G_gisinit(argv[0]);
+    module = G_define_module();
+    G_add_keyword(_("imagery"));
+    G_add_keyword(_("destripe"));
+    G_add_keyword("Fourier");
+    module->description =
+	_("Destripes regularly, about vertical, striped image using Fourier.");
+    
+    /* Define the different options */ 
+    input1 = G_define_standard_option(G_OPT_R_INPUT);
+
+    input2 = G_define_option();
+    input2->key = "harmonic";
+    input2->type = TYPE_INTEGER;
+    input2->required = YES;
+    input2->description =
+	_("Number of harmonics to use (less is smoother output)");
+    input2->answer = "8";
+
+    output = G_define_standard_option(G_OPT_R_OUTPUT);
+    /********************/ 
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    in = input1->answer;
+    ha = atoi(input2->answer);
+    result = output->answer;
+    
+    /***************************************************/ 
+    infd = Rast_open_old(in, "");
+    inrast = Rast_allocate_d_buf();
+
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
+    outrast = Rast_allocate_d_buf();
+    
+    /* Create New raster files */ 
+    outfd = Rast_open_new(result, DCELL_TYPE);
+     
+    /* Process each row */
+    for (row = 0; row < nrows; row++)
+    {
+        G_percent(row, nrows, 2);
+        Rast_get_d_row(infd, inrast, row);
+        fourier(outrast,inrast,ncols,ha);
+        Rast_put_d_row(outfd, outrast);
+    }
+    
+    /* Color table for biomass */ 
+    Rast_init_colors(&colors);
+    val1 = 0;
+    val2 = 1;
+    Rast_add_c_color_rule(&val1, 0, 0, 0, &val2, 255, 255, 255, &colors);
+    G_free(inrast);
+    G_free(outrast);
+    Rast_close(infd);
+    Rast_close(outfd);
+    Rast_short_history(result, "raster", &history);
+    Rast_command_history(&history);
+    Rast_write_history(result, &history);
+
+    exit(EXIT_SUCCESS);
+}
+
+



More information about the grass-commit mailing list