[GRASS-SVN] r68672 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 12 12:39:57 PDT 2016
Author: hao2309
Date: 2016-06-12 12:39:56 -0700 (Sun, 12 Jun 2016)
New Revision: 68672
Modified:
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
Log:
debugging in progress, some glabal paramters won't be read, e.g. globals->msspatial_bandwidth
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-12 19:09:49 UTC (rev 68671)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-12 19:39:56 UTC (rev 68672)
@@ -34,14 +34,16 @@
int mean_shift(struct globals *globals)
{
int row, col, t;
- int n_changes;
+ int n_changes, window_size;
double alpha2;
struct ngbr_stats Rin, Rout, Rwin;
double diff2;
/* G_fatal_error(_("Mean shift is not yet implemented"));
return FALSE; */
-
+ double ms_spatial_bandwidth = 3;
+ double ms_range_bandwidth = 0.1;
+
Rin.mean = G_malloc(globals->datasize);
Rwin.mean = G_malloc(globals->datasize);
Rout.mean = G_malloc(globals->datasize);
@@ -50,12 +52,14 @@
* initially, input and output are original band values */
/* set the pointers */
globals->bands_in = &globals->bands_seg;
- globals->bands_out = &globals->bands_seg2;
+ globals->bands_out = &globals->bands_seg;
/*window size in pixel number*/
- int window_size = globals->ms_spatial_bandwidth*2+1;
- alpha2 = globals->alpha * globals->alpha;
-
+ window_size = ms_spatial_bandwidth*2+1;
+ /* alpha2 = globals->alpha * globals->alpha;
+ use local threshold for temporal testing,*/
+ alpha2 = 0.0001;
+
t = 0;
n_changes = 1;
while (t < globals->end_t && n_changes > 0) {
@@ -82,7 +86,6 @@
}
}
}
-
G_debug(4, "Starting to process %ld candidate cells",
globals->candidate_count);
@@ -119,44 +122,53 @@
/* calculate new band values */
double sum_of_weights = 0;
- double *px_new_val = G_malloc(sizeof(double) * globals->nbands);
-
+
+ G_message(_("window_size is: %d"),window_size);
+ G_message(_("globals->bands_max is: %d"),globals->bands_max);
+ G_message(_("window_row_north is: %d"),window_row_north);
+ G_message(_("window_row_south is: %d"),window_row_south);
+ G_message(_("window_col_west is: %d"),window_col_west);
+ G_message(_("window_col_east is: %d"),window_col_east);
+
+ /* get the current pixel value */
+ Segment_get(globals->bands_in, (void *)Rin.mean, row, col);
+ G_message(_("row: %d, col: %d, Rin.mean is: %f"),row,col,Rin.mean[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++){
double weight = 1;
/* adapt initial spatial and range bandwidths */
- double distance2 = pow((current_window_row - row),2)+pow((current_window_col - col),2);
- if (distance2 <= pow(globals->ms_spatial_bandwidth,2)){
- /* get the current pixel value */
- Segment_get(globals->bands_in, (void *)Rin.mean,row, col);
-
+ if (pow((current_window_row - row),2)+pow((current_window_col - col),2) <= pow(ms_spatial_bandwidth,2)){
+
/* get the current moving window pixel value */
Segment_get(&globals->bands_seg, (void *)Rwin.mean,current_window_row, current_window_col);
+ // G_message(_("row: %d, col: %d, Rin.mean is: %f"),row,col,Rin.mean[0]);
+ // G_message(_("row: %d, col: %d, Rwin is: %f"),row,col,Rwin.mean[0]);
+
/* check range bandwidth */
- if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= (globals->ms_range_bandwidth * globals->ms_range_bandwidth)){
+ if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= pow((ms_range_bandwidth * globals->max_diff),2)){
int n = globals->nbands - 1;
+ /* I think sum_of_weights should be place out of loop because only the same index band pixels will take part in the calculation(Rout.mean[n] += Rwin.mean[n]*weight) */
+ sum_of_weights += weight;
do{
weight *=1;/* later can apply gaussian kernal */
- sum_of_weights += weight;
- px_new_val[n] += Rwin.mean[n]*weight;
+ Rout.mean[n] += Rwin.mean[n]*weight;
} while(n--);
}
}
}/* end of moving window col */
}/* end of moving window row */
+ int n1 = globals->nbands - 1;
+ do{
+ Rout.mean[n1] /=sum_of_weights;
+ } while(n1--);
+ G_message(_("row: %d, col: %d, Rout.mean is: %f"),row,col,Rout.mean[0]);
/* write the output to bands_out*/
- int n = globals->nbands - 1;
- do{
- Rout.mean[n] = px_new_val[n];
- Rout.mean[n] /= sum_of_weights;
- }while(n--);
- Segment_put(globals->bands_out, (void *)Rout.mean, row, col);
+ Segment_put(&globals->bands_seg, (void *)Rout.mean, row, col);
/* Segment_put(&globals->bands_seg2, (void *)Rout.mean, row, col); */
-
/* if the squared difference between old and new band values
* is larger than alpha2, then increase n_changes */
@@ -164,6 +176,13 @@
if (diff2 > alpha2)
n_changes++;
+ /* reset Rout to zero to prepare next iteration */
+ int 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 */
}/* end row iteration */
}/* end while iteration */
@@ -177,15 +196,15 @@
return TRUE;
}
-/* test out put the result */
-void print_matrix(struct globals *globals){
- int i,j;
- struct ngbr_stats R_prt;
- R_prt.mean = G_malloc(globals->datasize);
- for (i = globals->row_min; i < globals->row_max; i++){
- for (j = globals->col_min; j < globals->col_max; j++) {
- Segment_get(&globals->bands_seg, (void *)R_prt.mean,i, j);
- G_message(_("\t%.2f"),R_prt.mean[0]);
- }
- }
-}
\ No newline at end of file
+// /* test out put the result */
+// void print_matrix(struct globals *globals){
+ // int i,j;
+ // struct ngbr_stats R_prt;
+ // R_prt.mean = G_malloc(globals->datasize);
+ // for (i = globals->row_min; i < globals->row_max; i++){
+ // for (j = globals->col_min; j < globals->col_max; j++) {
+ // Segment_get(&globals->bands_seg, (void *)R_prt.mean,i, j);
+ // G_message(_("\t%.2f"),R_prt.mean[0]);
+ // }
+ // }
+// }
\ No newline at end of file
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-12 19:09:49 UTC (rev 68671)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c 2016-06-12 19:39:56 UTC (rev 68672)
@@ -174,11 +174,11 @@
(void *)globals->bands_val, row, col) != 1)
G_fatal_error(_("Unable to write to temporary file"));
- /* add globals->bands_seg2 when using mean shift */
- if (globals->method == ORM_MS){
- if(Segment_put(&globals->bands_seg2, &globals->bands_seg, row, col) !=1);
- G_fatal_error(_("Unable to initiate the shift-value band for mean-shift"));
- }
+ // /* add globals->bands_seg2 when using mean shift */
+ // if (globals->method == ORM_MS){
+ // if(Segment_put(&globals->bands_seg2, (void *)globals->bands_val, row, col) !=1);
+ // G_fatal_error(_("Unable to initiate the shift-value band for mean-shift"));
+ // }
if (!is_null) {
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-12 19:09:49 UTC (rev 68671)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/parse_args.c 2016-06-12 19:39:56 UTC (rev 68672)
@@ -47,7 +47,7 @@
ms_spatial_bandwidth->key = "ms_spatial_bandwidth";
ms_spatial_bandwidth->type = TYPE_DOUBLE;
ms_spatial_bandwidth->required = NO;
- ms_spatial_bandwidth->answer = "2";
+ ms_spatial_bandwidth->answer = "3";
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");
More information about the grass-commit
mailing list