[GRASS-SVN] r68725 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jun 21 20:57:55 PDT 2016
Author: hao2309
Date: 2016-06-21 20:57:55 -0700 (Tue, 21 Jun 2016)
New Revision: 68725
Modified:
sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
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:
addfucntion to write out multi bands of shifted value
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-22 03:38:15 UTC (rev 68724)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-22 03:57:55 UTC (rev 68725)
@@ -70,7 +70,6 @@
long ncells, notnullcells;
char *out_name; /* name of output raster map */
- char *ms_bands_out; /* name of out put shifted band for ms */
char *seeds, *bounds_map; /* optional segment seeds and polygon constraints/boundaries */
CELL lower_bound, upper_bound;
const char *bounds_mapset;
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-22 03:38:15 UTC (rev 68724)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-22 03:57:55 UTC (rev 68725)
@@ -51,7 +51,7 @@
G_percent_reset();
class_val=0;
cluster_threshold = 0.05;
- cluster_threshold2= pow((cluster_threshold * globals->max_diff),2);
+ cluster_threshold2= pow(cluster_threshold ,2);
for (row = globals->row_min; row < globals->row_max; row++) {
G_percent(row - globals->row_min,
globals->row_max - globals->row_min, 4);
@@ -260,6 +260,11 @@
/* get the current pixel value */
Segment_get(globals->bands_in, (void *)Rin.mean, row, col);
+ /* reset Rout to zero to prepare next iteration */
+ n2 = globals->nbands - 1;
+ do{
+ Rout.mean[n2] =0;
+ } while(n2--);
/* start of the moving window */
for (current_window_row = window_row_north;current_window_row<window_row_south;current_window_row++){
@@ -302,11 +307,6 @@
if (diff2 > alpha2)
n_changes++;
- /* reset Rout to zero to prepare next iteration */
- n2 = globals->nbands - 1;
- do{
- Rout.mean[n2] =0;
- } while(n2--);
// G_message(_("row: %d, col: %d, diff2 is: %f"),row,col,diff2);
}/* end col iteration */
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-22 03:38:15 UTC (rev 68724)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-22 03:57:55 UTC (rev 68725)
@@ -11,7 +11,7 @@
{
struct Option *group, *seeds, *bounds, *output,
*method, *similarity, *threshold, *min_segment_size,
- *ms_range_bandwidth, *ms_spatial_bandwidth, *ms_suffix, *ms_bands_out, // added ms_suffix, ms_range_bandwidth,ms_bands_out, ms_spatial_bandwidth for mean shift
+ *ms_range_bandwidth, *ms_spatial_bandwidth, *ms_suffix, // added ms_suffix, ms_range_bandwidth, ms_spatial_bandwidth for mean shift
#ifdef _OR_SHAPE_
*shape_weight, *smooth_weight,
#endif
@@ -52,12 +52,12 @@
ms_spatial_bandwidth->description = _("Moving window radiuns (1-32 in number of pixel) for mean shift");
ms_spatial_bandwidth->guisection = _("MS_Settings");
- ms_bands_out = G_define_option();
- ms_bands_out->key = "ms_bands_out";
- ms_bands_out->type = TYPE_STRING;
- ms_bands_out->required = NO;
- ms_bands_out->answer = "ms_shiftval_band";
- ms_bands_out->description = _("If also output the intermediam shifted-value band");
+ ms_suffix = G_define_option();
+ ms_suffix->key = "ms_suffix";
+ ms_suffix->type = TYPE_STRING;
+ ms_suffix->required = NO;
+ ms_suffix->answer = "ms_shiftval_band";
+ ms_suffix->description = _("If also output the intermediam shifted-value band");
ms_spatial_bandwidth->guisection = _("MS_Settings");
ms_range_bandwidth = G_define_option();
@@ -69,14 +69,6 @@
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();
@@ -282,7 +274,7 @@
globals->ncols = Rast_window_cols();
/* for mean shift seg2 output */
- globals->ms_bands_out = ms_bands_out->answer;
+ globals->ms_suffix = ms_suffix->answer;
/* debug help */
if (outband->answer == NULL)
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-22 03:38:15 UTC (rev 68724)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-22 03:57:55 UTC (rev 68725)
@@ -15,11 +15,12 @@
int write_ms_seg2(struct globals *globals)
{
-
int *seg2_fd, row, col, n;
DCELL **outbuf2, *seg2;
struct ngbr_stats;
+ char suffix[50], band_num[10];
+
seg2_fd = G_malloc(globals->nbands * sizeof(int));
outbuf2 = (DCELL **) G_malloc(globals->nbands * sizeof(DCELL *));
seg2 = G_malloc(sizeof(DCELL) * globals->nbands);
@@ -31,7 +32,10 @@
G_debug(1, "preparing shifted value output raster");
/* open output raster map */
for (n=0;n<globals->nbands; n++){
- seg2_fd[n] = Rast_open_new(globals->ms_bands_out, DCELL_TYPE);
+ strcpy(suffix, globals->ms_suffix);
+ strcpy(band_num, itoa(n,band_num,10));
+ strcat(suffix,band_num);
+ seg2_fd[n] = Rast_open_new(suffix, DCELL_TYPE);
}
G_debug(1, "start data transfer from seg2 file to raster");
@@ -47,7 +51,7 @@
for (col = 0; col < globals->ncols; col++){
if (!(FLAG_GET(globals->null_flag, row, col))) {
- Segment_get(&globals->bands_seg2, (void *)seg2, row, col);
+ Segment_get(globals->bands_out, (void *)seg2, row, col);
for (n=0;n<globals->nbands; n++){
outbuf2[n][col] = seg2[n];
}
More information about the grass-commit
mailing list