[GRASS-SVN] r68761 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 24 08:56:04 PDT 2016
Author: hao2309
Date: 2016-06-24 08:56:04 -0700 (Fri, 24 Jun 2016)
New Revision: 68761
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/open_files.c
sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
Log:
added shift value bands matched colortable as the input bands
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-24 14:53:21 UTC (rev 68760)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h 2016-06-24 15:56:04 UTC (rev 68761)
@@ -61,7 +61,6 @@
/* ===parameters for ms_setting=== */
double ms_spatial_bandwidth; /* "Moving window radiuns (1-32 in number of pixel) for mean shift" */
double ms_range_bandwidth; /* Nomarlized range bandwidth for mean shift */
- double ms_iter_threshold;/* Threshold when stop iteration */
char *ms_suffix; /* a suffix to be appended to the input bands when writing out shifted band values */
/* ===end parameters for ms_setting=== */
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-24 14:53:21 UTC (rev 68760)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-24 15:56:04 UTC (rev 68761)
@@ -307,8 +307,8 @@
/* TODO: need another segment structure holding output
* initially, input and output are original band values */
/* set the pointers */
- globals->bands_in = &globals->bands_seg2;
- globals->bands_out = &globals->bands_seg;
+ globals->bands_in = &globals->bands_seg;
+ globals->bands_out = &globals->bands_seg2;
// globals->bands_id = &globals->rid_seg;
/* bands_seg hold the input value actually, but in and out are change each time before the iteration starts */
@@ -388,7 +388,6 @@
/* 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{
@@ -409,9 +408,9 @@
if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= pow((globals->ms_range_bandwidth),2)){
/* sum_of_weights should be place out of loop */
sum_of_weights += weight;
+ weight *=1;/* later can apply gaussian kernal */
int n = globals->nbands - 1;
- weight *=1;
- do{;/* later can apply gaussian kernal */
+ do{
Rout.mean[n] += Rwin.mean[n]*weight;
} while(n--);
}
@@ -423,7 +422,8 @@
do{
Rout.mean[n1] /=sum_of_weights;
} while(n1--);
-
+ // G_message(_("row: %d, col: %d, Rin is: %f"),row,col,Rin.mean[0]);
+ // G_message(_("row: %d, col: %d, Rout is: %f"),row,col,Rout.mean[0]);
G_debug(1, "row: %d, col: %d, Rout.mean is: %f",row,col,Rout.mean[0]);
/* write the output to bands_out*/
Segment_put(globals->bands_out, (void *)Rout.mean, row, col);
@@ -433,7 +433,7 @@
Segment_get(&globals->bands_seg2, (void *)Rout.mean,row, col);
// G_message(_("row: %d, col: %d, Rout.mean of seg2 is: %f"),row,col,Rout.mean[0]);
diff2 = (globals->calculate_similarity)(&Rin, &Rout, globals);
- if (diff2 > globals->ms_iter_threshold)
+ if (diff2 > globals->alpha)
n_changes++;
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-24 14:53:21 UTC (rev 68760)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-24 15:56:04 UTC (rev 68761)
@@ -152,6 +152,9 @@
globals->bands_val = (double *)G_malloc(inlen);
globals->second_val = (double *)G_malloc(inlen);
+ globals->bands_max = (double *)G_malloc(inlen);
+ globals->bands_min = (double *)G_malloc(inlen);
+
/* initial segment ID */
s = 1;
@@ -177,6 +180,8 @@
/* scaled version */
globals->bands_val[n] = (inbuf[n][col] - min[n]) / (max[n] - min[n]);
}
+ globals->bands_min[n] = min[n];
+ globals->bands_max[n] = max[n];
}
if (Segment_put(&globals->bands_seg,
(void *)globals->bands_val, row, col) != 1)
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-24 14:53:21 UTC (rev 68760)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-24 15:56:04 UTC (rev 68761)
@@ -11,7 +11,7 @@
{
struct Option *group, *seeds, *bounds, *output,
*method, *similarity, *threshold, *min_segment_size,
- *ms_range_bandwidth, *ms_spatial_bandwidth, *ms_iter_threshold, *ms_suffix, // added ms_suffix, ms_range_bandwidth, ms_spatial_bandwidth for mean shift
+ *ms_range_bandwidth, *ms_spatial_bandwidth, *alpha, *ms_suffix, // added ms_suffix, ms_range_bandwidth, ms_spatial_bandwidth for mean shift
#ifdef _OR_SHAPE_
*shape_weight, *smooth_weight,
#endif
@@ -52,20 +52,11 @@
ms_spatial_bandwidth->description = _("Moving window radiuns (1-32 in number of pixel) for mean shift");
ms_spatial_bandwidth->guisection = _("MS_Settings");
- /* ======threshold when stop iteration=====*/
- ms_iter_threshold = G_define_option();
- ms_iter_threshold->key = "ms_iter_threshold";
- ms_iter_threshold->type = TYPE_DOUBLE;
- ms_iter_threshold->required = NO;
- ms_iter_threshold->answer = "0.0001";
- ms_iter_threshold->description = _("Threshold when stop iteration");
- ms_iter_threshold->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 = "ms_shiftval_band";
+ ms_suffix->answer = "_ms";
ms_suffix->description = _("If also output the intermediam shifted-value band");
ms_spatial_bandwidth->guisection = _("MS_Settings");
@@ -188,7 +179,6 @@
/* Note: this threshold is scaled after we know more at the beginning of create_isegs() */
globals->alpha = atof(threshold->answer);
globals->ms_spatial_bandwidth = atof(ms_spatial_bandwidth->answer);
- globals->ms_iter_threshold = atof(ms_iter_threshold->answer);
globals->ms_range_bandwidth = atof(ms_range_bandwidth->answer);
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-24 14:53:21 UTC (rev 68760)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-24 15:56:04 UTC (rev 68761)
@@ -34,10 +34,8 @@
seg2_fd = G_malloc(globals->nbands * sizeof(int));
outbuf2 = (DCELL **) G_malloc(globals->nbands * sizeof(DCELL *));
- seg2 = G_malloc(sizeof(DCELL) * globals->nbands);
- min_val = G_malloc(sizeof(DCELL) * globals->nbands);
- max_val = G_malloc(sizeof(DCELL) * globals->nbands);
-
+ seg2 = G_malloc(sizeof(DCELL) * globals->nbands);
+
for (n=0;n<globals->nbands; n++){
outbuf2[n] = Rast_allocate_d_buf();
}
@@ -58,8 +56,6 @@
for (n=0;n<globals->nbands; n++){
Rast_set_d_null_value(outbuf2[n], globals->ncols);
- min_val[n] = 1;
- max_val[n] = 0;
}
for (col = 0; col < globals->ncols; col++){
@@ -67,13 +63,12 @@
Segment_get(globals->bands_out, (void *)seg2, row, col);
for (n=0;n<globals->nbands; n++){
- outbuf2[n][col] = seg2[n];
- if (seg2[n] < min_val[n]){
- min_val[n] = seg2[n];
+ if (globals->weighted == FALSE){
+ /* scaled version */
+ seg2[n] = seg2[n]*(globals->bands_max[n]-globals->bands_min[n]) + globals->bands_min[n];
}
- else{
- max_val[n] = seg2[n];
- }
+ outbuf2[n][col] = seg2[n];
+
}
}
}
@@ -96,7 +91,7 @@
G_asprintf(&shifted_out_name, "%s_%s", Ref.file[n].name, globals->ms_suffix);
/* set colors */
Rast_init_colors(&colors);
- Rast_make_grey_scale_fp_colors(&colors, min_val[n], max_val[n]);
+ Rast_read_colors(Ref.file[n].name,G_mapset(), &colors);
Rast_write_colors(shifted_out_name, G_mapset(), &colors);
More information about the grass-commit
mailing list