[GRASS-SVN] r68639 - sandbox/bo/i.segment.gsoc2016/i.segment

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 8 09:26:53 PDT 2016


Author: hao2309
Date: 2016-06-08 09:26:53 -0700 (Wed, 08 Jun 2016)
New Revision: 68639

Modified:
   sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
   sandbox/bo/i.segment.gsoc2016/i.segment/main.c
   sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
   sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
   sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
Log:
move stand-alone code to sub folder and get start on mean-shift.c

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h	2016-06-08 16:26:07 UTC (rev 68638)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h	2016-06-08 16:26:53 UTC (rev 68639)
@@ -57,7 +57,13 @@
 
     int end_t;			/* maximum number of iterations */
     int mb;
-
+	
+	/* ===parameters for ms_setting=== */	
+	double ms_bandwidth; /* "Moving window radiuns (1-32 in number of pixel) for mean shift" */
+	double ms_range_bandwidth; /* Nomarlized range bandwidth for mean shift */
+	char *ms_suffix; /* a suffix to be appended to the input bands when writing out shifted band values */
+	/* ===end parameters for ms_setting=== */
+	
     /* region info */
     int nrows, ncols;
     int row_min, row_max, col_min, col_max; /* region constraints */
@@ -73,7 +79,9 @@
     int nbands;			/* number of rasters in the image group */
     SEGMENT bands_seg, 	        /* input group with one or more bands */
             bounds_seg,
+			bands_seg2,  /* copy of bands_seg for mean shift */
 	    rid_seg;
+	SEGMENT *bands_in, *bands_out;  /* pointers to rotate input/output bands for mean shift */
     DCELL *bands_min, *bands_max;
     DCELL *bands_val;		/* array to hold all input values for one cell */
     DCELL *second_val;		/* array to hold all input values for another cell */

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/main.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/main.c	2016-06-08 16:26:07 UTC (rev 68638)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/main.c	2016-06-08 16:26:53 UTC (rev 68639)
@@ -47,6 +47,7 @@
 
     G_debug(1, "Main: starting create_isegs()");
     if (create_isegs(&globals) != TRUE)
+	/* if (mean_shift(&globals) != TRUE) */
 	G_fatal_error(_("Error in creating segments"));
 
     G_debug(1, "Main: starting write_output()");

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-08 16:26:07 UTC (rev 68638)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-08 16:26:53 UTC (rev 68639)
@@ -36,20 +36,24 @@
     int row, col, t;
     int n_changes;
     double alpha2;
-    struct ngbr_stats Rin, Rout;
+    struct ngbr_stats Rin, Rout, Rwin;
     double diff2;
 
-    G_fatal_error(_("Mean shift is not yet implemented"));
-    return FALSE;
+    /* G_fatal_error(_("Mean shift is not yet implemented"));
+    return FALSE; */
 
-
     Rin.mean = G_malloc(globals->datasize);
+	Rwin.mean = G_malloc(globals->datasize);
     Rout.mean = G_malloc(globals->datasize);
 
     /* TODO: need another segment structure holding output
-     * for mean shift, output of the previous iteration becomes input of the next iteration
      * initially, input and output are original band values */
-
+	/* set the pointers */
+	globals->bands_in = &globals->bands_seg; 
+	globals->bands_out = &globals->bands_seg2;
+	
+	/*window size in pixel number*/
+	int window_size = globals->ms_bandwidth*2+1;
     alpha2 = globals->alpha * globals->alpha;
     
     t = 0;
@@ -57,6 +61,12 @@
     while (t < globals->end_t && n_changes > 0) {
 
 	G_message(_("Processing pass %d..."), ++t);
+	
+	/* for mean shift, output of the previous iteration becomes input of the next iteration */
+	SEGMENT *bands_tmp;
+	bands_tmp = globals->bands_in;
+	globals->bands_in = globals->bands_out;
+	globals->bands_out = bands_tmp;
 
 	n_changes = 0;
 	globals->candidate_count = 0;
@@ -78,30 +88,74 @@
 
 	/*process candidate cells */
 	G_percent_reset();
-	for (row = globals->row_min; row < globals->row_max; row++) {
+	/* temperaral using 40x40 sub set for fast testing */
+	for (row = globals->row_min; row < 40; row++) {
 	    G_percent(row - globals->row_min,
 	              globals->row_max - globals->row_min, 4);
-	    for (col = globals->col_min; col < globals->col_max; col++) {
+	    for (col = globals->col_min; col < 40; col++) {
 		if (!(FLAG_GET(globals->candidate_flag, row, col)))
 		    continue;
-
-		/* get current band values */
-		Segment_get(&globals->bands_seg, (void *)Rin.mean,
-			    row, col);
-
-		/* adapt initial spatial and range bandwiths */
-
+		/* left bound of the window */
+		int window_row_north = row - globals->ms_bandwidth;
+		/* right bound of the window */
+		int window_row_south = window_row_north + window_size;
+		/* upper bound of the window */
+		int window_col_west = col - globals->ms_bandwidth;
+		/* lower bound of the window */
+		int window_col_east = window_col_west + window_size;
+			
+		/* clip window in the edge */
+		if (window_row_north < globals->row_min){
+			window_row_north = globals->row_min;
+			}
+		if (window_row_south>globals->row_max){
+			window_row_south = globals->row_max;
+			}
+		if (window_col_west<globals->col_min){
+			window_col_west = globals->col_min;
+			}
+		if (window_col_east > globals->col_max){
+			window_col_east = globals->col_max;
+			}
 		/* calculate new band values */
+		float sum_of_weights = 0;
+		double new_val = 0;
 		
+		/* start of the moving window */
+		for (int current_window_row = window_row_north;current_window_row<window_row_south;current_window_row++){
+			for (int current_window_col = window_col_west;current_window_col<window_col_east;current_window_col++){
+				float weight =1;
+				/* adapt initial spatial and range bandwidths */
+				if (pow((current_window_row - row),2)+pow((current_window_col - col),2) <= pow(globals->ms_bandwidth,2)){
+					/* get the current pixel value */
+					Segment_get(&globals->bands_seg, (void *)Rin.mean,row, col);
+							
+					/* get the current moving window pixel value */
+					Segment_get(&globals->bands_seg, (void *)Rwin.mean,current_window_row, current_window_col);
+					/* check range bandwidth */
+					if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= (globals->ms_range_bandwidth * globals->ms_range_bandwidth)){
+						weight *=1;
+						sum_of_weights += weight;
+						new_val += Rwin.mean[0]*weight;
+					}
+				}
+			}/* end of moving window col */
+		}/* end of moving window row */
+		
+		/* write the output to bands_out*/
+		Rout.mean[0] = new_val;
+		Segment_put(&globals->bands_out, (void *)Rout.mean, row, col);
+
+		
 		/* if the squared difference between old and new band values 
 		 * is larger than alpha2, then increase n_changes */
 		
 		diff2 = (globals->calculate_similarity)(&Rin, &Rout, globals);
 		if (diff2 > alpha2)
 		    n_changes++;
-	    }
-	}
-    }
+	    }/* end col iteration */
+	}/* end row iteration */
+    }/* end while iteration */
     if (n_changes > 1)
 	G_message(_("Mean shift stopped at %d due to reaching max iteration limit, more changes may be possible"), t);
     else

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c	2016-06-08 16:26:07 UTC (rev 68638)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c	2016-06-08 16:26:53 UTC (rev 68639)
@@ -9,8 +9,9 @@
 
 int parse_args(int argc, char *argv[], struct globals *globals)
 {
-    struct Option *group, *seeds, *bounds, *output,
+    struct Option *group, *seeds, *bounds, *output, 
                   *method, *similarity, *threshold, *min_segment_size,
+				  *ms_range_bandwidth, *ms_spatial_bandwidth, *ms_suffix, *ms_shiftval_band, // added ms_suffix, ms_range_bandwidth,ms_shiftval_band, ms_spatial_bandwidth for mean shift
 #ifdef _OR_SHAPE_
 		  *shape_weight, *smooth_weight,
 #endif
@@ -35,12 +36,49 @@
     method = G_define_option();
     method->key = "method";
     method->type = TYPE_STRING;
-    method->required = NO;
-    method->answer = "region_growing";
+    method->required = YES;
+    method->answer = "mean_shift";
     method->options = "region_growing,mean_shift,watershed";
     method->description = _("Segmentation method");
-    method->guisection = _("Settings");
+//    method->guisection = _("RG_Settings");
 
+	/* =========================parameters for ms_setting====================== */
+	ms_spatial_bandwidth = G_define_option();
+    ms_spatial_bandwidth->key = "ms_bandwidth";
+    ms_spatial_bandwidth->type = TYPE_DOUBLE;
+    ms_spatial_bandwidth->required = NO;
+    ms_spatial_bandwidth->answer = "2";
+    ms_spatial_bandwidth->options = "1-32";
+    ms_spatial_bandwidth->description = _("Moving window radiuns (1-32 in number of pixel) for mean shift");
+    ms_spatial_bandwidth->guisection = _("MS_Settings");
+	
+	ms_shiftval_band = G_define_option();
+    ms_shiftval_band->key = "ms_bands_out";
+    ms_shiftval_band->type = TYPE_STRING;
+    ms_shiftval_band->required = NO;
+    ms_shiftval_band->answer = "ms_shiftval_band";
+    ms_shiftval_band->description = _("If also output the intermediam shifted-value band");
+    ms_spatial_bandwidth->guisection = _("MS_Settings");
+	
+	ms_range_bandwidth = G_define_option();
+    ms_range_bandwidth->key = "ms_range_bandwidth";
+    ms_range_bandwidth->type = TYPE_DOUBLE;
+    ms_range_bandwidth->required = NO;
+    ms_range_bandwidth->answer = "0.1";
+    ms_range_bandwidth->options = "0-1";
+    ms_range_bandwidth->description = _("Nomarlized range bandwidth for mean shift");
+    ms_range_bandwidth->guisection = _("MS_Settings");
+	 
+	ms_suffix = G_define_option();
+    ms_suffix->key = "ms_suffix";
+    ms_suffix->type = TYPE_STRING;
+    ms_suffix->required = NO;
+    ms_suffix->answer = "mean_shift";
+    ms_suffix->description = _("a suffix to be appended to the input bands when writing out shifted band values");
+    ms_suffix->guisection = _("MS_Settings");
+	
+	/* ==================end parameters for ms_setting===================== */
+	
     similarity = G_define_option();
     similarity->key = "similarity";
     similarity->type = TYPE_STRING;
@@ -48,7 +86,7 @@
     similarity->answer = "euclidean";
     similarity->options = "euclidean,manhattan";
     similarity->description = _("Similarity calculation method");
-    similarity->guisection = _("Settings");
+    similarity->guisection = _("RG_Settings");
 
     min_segment_size = G_define_option();
     min_segment_size->key = "minsize";
@@ -59,7 +97,7 @@
     min_segment_size->label = _("Minimum number of cells in a segment");
     min_segment_size->description =
 	_("The final step will merge small segments with their best neighbor");
-    min_segment_size->guisection = _("Settings");
+    min_segment_size->guisection = _("RG_Settings");
 
 #ifdef _OR_SHAPE_
     radio_weight = G_define_option();
@@ -70,7 +108,7 @@
     radio_weight->options = "0-1";
     radio_weight->label =
 	_("Importance of radiometric (input raster) values relative to shape");
-    radio_weight->guisection = _("Settings");
+    radio_weight->guisection = _("RG_Settings");
 
     smooth_weight = G_define_option();
     smooth_weight->key = "smooth_weight";
@@ -80,7 +118,7 @@
     smooth_weight->options = "0-1";
     smooth_weight->label =
 	_("Importance of smoothness relative to compactness");
-    smooth_weight->guisection = _("Settings");
+    smooth_weight->guisection = _("RG_Settings");
 #endif
 
     mem = G_define_option();
@@ -99,7 +137,7 @@
     endt->required = NO;
     endt->answer = "20";
     endt->description = _("Maximum number of iterations");
-    endt->guisection = _("Settings");
+    endt->guisection = _("RG_Settings");
 
     /* Using raster for seeds
      * Low priority TODO: allow vector points/centroids seed input. */
@@ -126,13 +164,13 @@
     diagonal->key = 'd';
     diagonal->description =
 	_("Use 8 neighbors (3x3 neighborhood) instead of the default 4 neighbors for each pixel");
-    diagonal->guisection = _("Settings");
+    diagonal->guisection = _("RG_Settings");
 
     weighted = G_define_flag();
     weighted->key = 'w';
     weighted->description =
 	_("Weighted input, do not perform the default scaling of input raster maps");
-    weighted->guisection = _("Settings");
+    weighted->guisection = _("RG_Settings");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c	2016-06-08 16:26:07 UTC (rev 68638)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c	2016-06-08 16:26:53 UTC (rev 68639)
@@ -40,8 +40,9 @@
 	    if (!(FLAG_GET(globals->null_flag, row, col))) {
 		Segment_get(&globals->rid_seg, (void *) &rid, row, col);
 		
-		
-		if (rid > 0) {
+		// G_message(_("Row %d, Col %d, is: %f"),row,col,rid);
+			
+		if (rid >= 0) {
 		    outbuf[col] = rid;
 		    if (maxid < rid)
 			maxid = rid;
@@ -65,158 +66,158 @@
     Rast_command_history(&hist);
     Rast_write_history(globals->out_name, &hist);
 
-    // /* write goodness of fit */
-    // if (globals->out_band) {
-	// int mean_fd;
-	// FCELL *meanbuf;
-	// double thresh, maxdev, sim, mingood;
-	// struct ngbr_stats Ri, Rk;
-	// struct Ref Ref;		/* group reference list */
-	// DCELL **inbuf;		/* buffers to store lines from each of the imagery group rasters */
-	// int n, *in_fd;
-	// struct FPRange *fp_range;	/* min/max values of each input raster */
-	// DCELL *min, *max;
+    /* write goodness of fit */
+    if (globals->out_band) {
+	int mean_fd;
+	FCELL *meanbuf;
+	double thresh, maxdev, sim, mingood;
+	struct ngbr_stats Ri, Rk;
+	struct Ref Ref;		/* group reference list */
+	DCELL **inbuf;		/* buffers to store lines from each of the imagery group rasters */
+	int n, *in_fd;
+	struct FPRange *fp_range;	/* min/max values of each input raster */
+	DCELL *min, *max;
 
-	// mean_fd = Rast_open_new(globals->out_band, FCELL_TYPE);
-	// meanbuf = Rast_allocate_f_buf();
+	mean_fd = Rast_open_new(globals->out_band, FCELL_TYPE);
+	meanbuf = Rast_allocate_f_buf();
 
-	// /* goodness of fit for each cell: 1 = good fit, 0 = bad fit */
-	// /* similarity of each cell to region mean
-	 // * max possible difference: globals->threshold
-	 // * if similarity < globals->alpha * globals->alpha * globals->threshold
-	 // * 1
-	 // * else 
-	 // * (similarity - globals->alpha * globals->alpha * globals->threshold) /
-	 // * (globals->threshold * (1 - globals->alpha * globals->alpha) */
+	/* goodness of fit for each cell: 1 = good fit, 0 = bad fit */
+	/* similarity of each cell to region mean
+	 * max possible difference: globals->threshold
+	 * if similarity < globals->alpha * globals->alpha * globals->threshold
+	 * 1
+	 * else 
+	 * (similarity - globals->alpha * globals->alpha * globals->threshold) /
+	 * (globals->threshold * (1 - globals->alpha * globals->alpha) */
 
-	// thresh = globals->alpha * globals->alpha * globals->max_diff;
-	// maxdev = globals->max_diff * (1 - globals->alpha * globals->alpha);
-	// mingood = 1;
+	thresh = globals->alpha * globals->alpha * globals->max_diff;
+	maxdev = globals->max_diff * (1 - globals->alpha * globals->alpha);
+	mingood = 1;
 
-	// /* open input bands */
-	// if (!I_get_group_ref(globals->image_group, &Ref))
-	    // G_fatal_error(_("Group <%s> not found in the current mapset"),
-			  // globals->image_group);
-	// if (Ref.nfiles <= 0)
-	    // G_fatal_error(_("Group <%s> contains no raster maps"),
-			  // globals->image_group);
+	/* open input bands */
+	if (!I_get_group_ref(globals->image_group, &Ref))
+	    G_fatal_error(_("Group <%s> not found in the current mapset"),
+			  globals->image_group);
+	if (Ref.nfiles <= 0)
+	    G_fatal_error(_("Group <%s> contains no raster maps"),
+			  globals->image_group);
 
-	// in_fd = G_malloc(Ref.nfiles * sizeof(int));
-	// inbuf = (DCELL **) G_malloc(Ref.nfiles * sizeof(DCELL *));
-	// fp_range = G_malloc(Ref.nfiles * sizeof(struct FPRange));
-	// min = G_malloc(Ref.nfiles * sizeof(DCELL));
-	// max = G_malloc(Ref.nfiles * sizeof(DCELL));
+	in_fd = G_malloc(Ref.nfiles * sizeof(int));
+	inbuf = (DCELL **) G_malloc(Ref.nfiles * sizeof(DCELL *));
+	fp_range = G_malloc(Ref.nfiles * sizeof(struct FPRange));
+	min = G_malloc(Ref.nfiles * sizeof(DCELL));
+	max = G_malloc(Ref.nfiles * sizeof(DCELL));
 
-	// G_debug(1, "Opening input rasters...");
-	// for (n = 0; n < Ref.nfiles; n++) {
-	    // inbuf[n] = Rast_allocate_d_buf();
-	    // in_fd[n] = Rast_open_old(Ref.file[n].name, Ref.file[n].mapset);
+	G_debug(1, "Opening input rasters...");
+	for (n = 0; n < Ref.nfiles; n++) {
+	    inbuf[n] = Rast_allocate_d_buf();
+	    in_fd[n] = Rast_open_old(Ref.file[n].name, Ref.file[n].mapset);
 
-	    // /* returns -1 on error, 2 on empty range, quitting either way. */
-	    // if (Rast_read_fp_range(Ref.file[n].name, Ref.file[n].mapset, &fp_range[n]) != 1)
-		// G_fatal_error(_("No min/max found in raster map <%s>"),
-			      // Ref.file[n].name);
-	    // Rast_get_fp_range_min_max(&(fp_range[n]), &min[n], &max[n]);
+	    /* returns -1 on error, 2 on empty range, quitting either way. */
+	    if (Rast_read_fp_range(Ref.file[n].name, Ref.file[n].mapset, &fp_range[n]) != 1)
+		G_fatal_error(_("No min/max found in raster map <%s>"),
+			      Ref.file[n].name);
+	    Rast_get_fp_range_min_max(&(fp_range[n]), &min[n], &max[n]);
 
-	    // G_debug(1, "Range for layer %d: min = %f, max = %f",
-			// n, min[n], max[n]);
-	// }
+	    G_debug(1, "Range for layer %d: min = %f, max = %f",
+			n, min[n], max[n]);
+	}
 
-	// G_message(_("Writing out goodness of fit"));
-	// for (row = 0; row < globals->nrows; row++) {
+	G_message(_("Writing out goodness of fit"));
+	for (row = 0; row < globals->nrows; row++) {
 
-	    // G_percent(row, globals->nrows, 9);
+	    G_percent(row, globals->nrows, 9);
 
-	    // Rast_set_f_null_value(meanbuf, globals->ncols);
+	    Rast_set_f_null_value(meanbuf, globals->ncols);
 
-	    // for (n = 0; n < Ref.nfiles; n++) {
-		// Rast_get_d_row(in_fd[n], inbuf[n], row);
-	    // }
+	    for (n = 0; n < Ref.nfiles; n++) {
+		Rast_get_d_row(in_fd[n], inbuf[n], row);
+	    }
 
-	    // for (col = 0; col < globals->ncols; col++) {
+	    for (col = 0; col < globals->ncols; col++) {
 
-		// if (!(FLAG_GET(globals->null_flag, row, col))) {
+		if (!(FLAG_GET(globals->null_flag, row, col))) {
 		    
-		    // Segment_get(&globals->rid_seg, (void *) &rid, row, col);
-
-		    // if (rid > 0) {
+		    Segment_get(&globals->rid_seg, (void *) &rid, row, col);
 			
-			// Ri.row = Rk.row = row;
-			// Ri.col = Rk.col = col;
+		    if (rid > 0) {
+			
+			Ri.row = Rk.row = row;
+			Ri.col = Rk.col = col;
 
-			// /* get values for Ri = this region */
-			// globals->rs.id = rid;
-			// fetch_reg_stats(row, col, &globals->rs, globals);
-			// Ri.mean = globals->rs.mean;
-			// Ri.count = globals->rs.count; 
+			/* get values for Ri = this region */
+			globals->rs.id = rid;
+			fetch_reg_stats(row, col, &globals->rs, globals);
+			Ri.mean = globals->rs.mean;
+			Ri.count = globals->rs.count; 
 
-			// sim = 0.;
-			// /* region consists of more than one cell */
-			// if (Ri.count > 1) {
+			sim = 0.;
+			/* region consists of more than one cell */
+			if (Ri.count > 1) {
 
-			    // /* get values for Rk = this cell */
-			    // for (n = 0; n < Ref.nfiles; n++) {
-				// if (globals->weighted == FALSE)
-				    // /* scaled version */
-				    // globals->second_val[n] = (inbuf[n][col] - min[n]) / (max[n] - min[n]);
-				// else
-				    // globals->second_val[n] = inbuf[n][col];
-			    // }
+			    /* get values for Rk = this cell */
+			    for (n = 0; n < Ref.nfiles; n++) {
+				if (globals->weighted == FALSE)
+				    /* scaled version */
+				    globals->second_val[n] = (inbuf[n][col] - min[n]) / (max[n] - min[n]);
+				else
+				    globals->second_val[n] = inbuf[n][col];
+			    }
 
-			    // Rk.mean = globals->second_val;
+			    Rk.mean = globals->second_val;
 
-			    // /* calculate similarity */
-			    // sim = (*globals->calculate_similarity) (&Ri, &Rk, globals);
-			// }
+			    /* calculate similarity */
+			    sim = (*globals->calculate_similarity) (&Ri, &Rk, globals);
+			}
 			
-			// if (0) {
-			    // if (sim < thresh)
-				// meanbuf[col] = 1;
-			    // else {
-				// sim = 1. - (sim - thresh) / maxdev;
-				// meanbuf[col] = sim;
-				// if (mingood > sim)
-				    // mingood = sim;
-			    // }
-			// }
-			// else {
-			    // sim = 1 - sim;
-			    // meanbuf[col] = sim;
-			    // if (mingood > sim)
-				// mingood = sim;
-			// }
-		    // }
-		// }
-	    // }
-	    // Rast_put_row(mean_fd, meanbuf, FCELL_TYPE);
-	// }
+			if (0) {
+			    if (sim < thresh)
+				meanbuf[col] = 1;
+			    else {
+				sim = 1. - (sim - thresh) / maxdev;
+				meanbuf[col] = sim;
+				if (mingood > sim)
+				    mingood = sim;
+			    }
+			}
+			else {
+			    sim = 1 - sim;
+			    meanbuf[col] = sim;
+			    if (mingood > sim)
+				mingood = sim;
+			}
+		    }
+		}
+	    }
+	    Rast_put_row(mean_fd, meanbuf, FCELL_TYPE);
+	}
 
-	// Rast_close(mean_fd);
+	Rast_close(mean_fd);
 
-	// Rast_init_colors(&colors);
-	// Rast_make_grey_scale_fp_colors(&colors, mingood, 1);
-	// Rast_write_colors(globals->out_band, G_mapset(), &colors);
+	Rast_init_colors(&colors);
+	Rast_make_grey_scale_fp_colors(&colors, mingood, 1);
+	Rast_write_colors(globals->out_band, G_mapset(), &colors);
 
-	// Rast_short_history(globals->out_band, "raster", &hist);
-	// Rast_command_history(&hist);
-	// Rast_write_history(globals->out_band, &hist);
+	Rast_short_history(globals->out_band, "raster", &hist);
+	Rast_command_history(&hist);
+	Rast_write_history(globals->out_band, &hist);
 
-	// G_free(meanbuf);
+	G_free(meanbuf);
 
-	// G_debug(1, "Closing input rasters...");
-	// for (n = 0; n < Ref.nfiles; n++) {
-	    // Rast_close(in_fd[n]);
-	    // G_free(inbuf[n]);
-	// }
-	// G_free(inbuf);
-	// G_free(in_fd);
-	// G_free(fp_range);
-	// G_free(min);
-	// G_free(max);
-    // }
+	G_debug(1, "Closing input rasters...");
+	for (n = 0; n < Ref.nfiles; n++) {
+	    Rast_close(in_fd[n]);
+	    G_free(inbuf[n]);
+	}
+	G_free(inbuf);
+	G_free(in_fd);
+	G_free(fp_range);
+	G_free(min);
+	G_free(max);
+    }
 
-    // /* free memory */
-    // Rast_free_colors(&colors);
+    /* free memory */
+    Rast_free_colors(&colors);
 
     return TRUE;
 }



More information about the grass-commit mailing list