[GRASS-SVN] r62793 - grass/trunk/imagery/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 18 00:44:58 PST 2014
Author: mmetz
Date: 2014-11-18 00:44:58 -0800 (Tue, 18 Nov 2014)
New Revision: 62793
Modified:
grass/trunk/imagery/i.segment/write_output.c
Log:
i.segment: fix goodness of fit
Modified: grass/trunk/imagery/i.segment/write_output.c
===================================================================
--- grass/trunk/imagery/i.segment/write_output.c 2014-11-18 04:00:51 UTC (rev 62792)
+++ grass/trunk/imagery/i.segment/write_output.c 2014-11-18 08:44:58 UTC (rev 62793)
@@ -73,6 +73,8 @@
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();
@@ -100,11 +102,23 @@
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);
+
+ /* 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_message(_("Writing out goodness of fit"));
@@ -141,7 +155,11 @@
/* get values for Rk = this cell */
for (n = 0; n < Ref.nfiles; n++) {
- globals->second_val[n] = inbuf[n][col];
+ 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;
@@ -161,7 +179,7 @@
}
}
else {
- sim = 1 - sim / globals->max_diff;
+ sim = 1 - sim;
meanbuf[col] = sim;
if (mingood > sim)
mingood = sim;
@@ -191,6 +209,9 @@
}
G_free(inbuf);
G_free(in_fd);
+ G_free(fp_range);
+ G_free(min);
+ G_free(max);
}
/* free memory */
More information about the grass-commit
mailing list