[GRASS-SVN] r68710 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Jun 18 13:13:35 PDT 2016
Author: hao2309
Date: 2016-06-18 13:13:34 -0700 (Sat, 18 Jun 2016)
New Revision: 68710
Modified:
sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
Log:
modifying cluster part
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-18 03:44:16 UTC (rev 68709)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-18 20:13:34 UTC (rev 68710)
@@ -36,7 +36,7 @@
int row, col, t;
int n_changes, window_size;
int window_row_north, window_row_south, window_col_west,window_col_east, current_window_row, current_window_col;
- double alpha2, cluster_threshold;
+ double alpha2, cluster_threshold,cluster_threshold2;
struct ngbr_stats Rin, Rout, Rwin;
struct ngbr_stats Rleft, Rabove;
double weight, sum_of_weights, diff2;
@@ -63,7 +63,6 @@
/*window size in pixel number*/
window_size = globals->ms_spatial_bandwidth*2+1;
- /* alpha2 = globals->alpha * globals->alpha;
/*******************************************************
* Part 1 shift values *
@@ -72,7 +71,6 @@
/*use local threshold for temporal testing,*/
alpha2 = 0.0001;
- cluster_threshold = 0.1;
t = 0;
n_changes = 1;
while (t < globals->end_t && n_changes > 0) {
@@ -137,17 +135,11 @@
/* calculate new band values */
sum_of_weights = 0;
- // G_message(_("globals->ms_spatial_bandwidth is: %f"),globals->ms_spatial_bandwidth);
- // G_message(_("globals->ms_range_bandwidth is: %f"),globals->ms_range_bandwidth);
- // 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 (current_window_row = window_row_north;current_window_row<window_row_south;current_window_row++){
for (current_window_col = window_col_west;current_window_col<window_col_east;current_window_col++){
@@ -211,6 +203,8 @@
G_message(_("Pass 1 of 2 for clustering"));
G_percent_reset();
class_val=0;
+ cluster_threshold = 0.1;
+ cluster_threshold2= pow((cluster_threshold * globals->max_diff),2);
for (row = globals->row_min; row < globals->row_max; row++) {
G_percent(row - globals->row_min,
globals->row_max - globals->row_min, 4);
@@ -219,57 +213,56 @@
continue;
/* get the current pixel value */
- Segment_get(globals->bands_out, (void *)Rin.mean, row, col);
+ Segment_get(&globals->bands_seg2, (void *)Rin.mean, row, col);
/* get left pixel value */
- if (col == globals->col_min & row == globals->row_min){
+ if (col == globals->col_min && row == globals->row_min){
seg_id=class_val;
- class_val+=1;
}
else if (row == globals->row_min){
/* compare with left value and set if same cluster */
- Segment_get(globals->bands_out, (void *)Rleft.mean, row, col-1);
- if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ Segment_get(&globals->bands_seg2, (void *)Rleft.mean, row, col-1);
+ if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= cluster_threshold2){
G_debug(1, "row: %d, col: %d, left_similarity is: %f",row,col,(globals->calculate_similarity)(&Rin, &Rleft, globals));
Segment_get(&globals->rid_seg, (void *)&left_new_val, row, col-1);
seg_id = left_new_val;
}
/* end compare left */
else{
- seg_id=class_val;
class_val+=1;
+ seg_id=class_val;
}
}
else if(col == globals->col_min){
/* compare with above value and set if same cluster */
- Segment_get(globals->bands_out, (void *)Rabove.mean, row-1, col);
- if ((globals->calculate_similarity)(&Rin, &Rabove, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ Segment_get(&globals->bands_seg2, (void *)Rabove.mean, row-1, col);
+ if ((globals->calculate_similarity)(&Rin, &Rabove, globals) <= cluster_threshold2){
G_debug(1, "row: %d, col: %d, above_similarity is: %f",row,col,(globals->calculate_similarity)(&Rin, &Rabove, globals));
Segment_get(&globals->rid_seg, (void *)&above_new_val, row-1, col);
seg_id = above_new_val;
}
/* end compare above */
else{
- seg_id=class_val;
class_val+=1;
+ seg_id=class_val;
}
}
else{
/* compare with left value then above value */
- Segment_get(globals->bands_out, (void *)Rleft.mean, row, col-1);
- Segment_get(globals->bands_out, (void *)Rabove.mean, row-1, col);
- if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ Segment_get(&globals->bands_seg2, (void *)Rleft.mean, row, col-1);
+ Segment_get(&globals->bands_seg2, (void *)Rabove.mean, row-1, col);
+ if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= cluster_threshold2 && (globals->calculate_similarity)(&Rin, &Rleft, globals) < (globals->calculate_similarity)(&Rin, &Rabove, globals)){
G_debug(1, "row: %d, col: %d, left_similarity is: %f",row,col,(globals->calculate_similarity)(&Rin, &Rleft, globals));
Segment_get(&globals->rid_seg, (void *)&left_new_val, row, col-1);
seg_id = left_new_val;
}
- else if((globals->calculate_similarity)(&Rin, &Rabove, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ else if((globals->calculate_similarity)(&Rin, &Rabove, globals) <= cluster_threshold2){
G_debug(1, "row: %d, col: %d, above_similarity is: %f",row,col,(globals->calculate_similarity)(&Rin, &Rabove, globals));
Segment_get(&globals->rid_seg, (void *)&above_new_val, row-1, col);
seg_id = above_new_val;
}
else{
- seg_id=class_val;
class_val+=1;
+ seg_id=class_val;
}
}
@@ -281,13 +274,13 @@
Segment_put(&globals->rid_seg, &seg_id, row, col);
}
}
-
- /* */
-
+
/*******************************************************
* Part 3 identify connected components *
* Merge small super-pixel to bigger super-pixels *
*******************************************************/
+
+
return TRUE;
}
More information about the grass-commit
mailing list