[GRASS-SVN] r68703 - sandbox/bo/i.segment.gsoc2016/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 16 21:12:15 PDT 2016
Author: hao2309
Date: 2016-06-16 21:12:15 -0700 (Thu, 16 Jun 2016)
New Revision: 68703
Modified:
sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
Log:
add cluster, not finished
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-17 02:24:44 UTC (rev 68702)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c 2016-06-17 04:12:15 UTC (rev 68703)
@@ -33,15 +33,15 @@
int mean_shift(struct globals *globals)
{
- int row, col, current_window_row, current_window_col, t;
+ int row, col, t;
int n_changes, window_size;
- int window_row_north, window_row_south, window_col_west,window_col_east;
+ int window_row_north, window_row_south, window_col_west,window_col_east, current_window_row, current_window_col;
double alpha2, cluster_threshold;
struct ngbr_stats Rin, Rout, Rwin;
- struct ngbr_stats Rleft, Rabove, Rright;
+ struct ngbr_stats Rleft, Rabove;
double weight, sum_of_weights, diff2;
- double min_val, max_val, old_val, new_val;
- double *prev_cluster, *cur_cluster, *temp_cluster;
+ int seg_id, new_val;
+ double min_val, max_val;
/* G_fatal_error(_("Mean shift is not yet implemented"));
return FALSE; */
@@ -51,13 +51,13 @@
Rout.mean = G_malloc(globals->datasize);
Rleft.mean = G_malloc(globals->datasize);
Rabove.mean = G_malloc(globals->datasize);
- Rright.mean = G_malloc(globals->datasize);
/* 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_id = &globals->rid_seg;
/* bands_seg hold the input value actually, but in and out are change each time before the iteration starts */
/*window size in pixel number*/
@@ -156,8 +156,6 @@
/* get the current moving window pixel value */
Segment_get(globals->bands_in, (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) <= pow((globals->ms_range_bandwidth * globals->max_diff),2)){
@@ -178,7 +176,7 @@
Rout.mean[n1] /=sum_of_weights;
} while(n1--);
- G_message(_("row: %d, col: %d, Rout.mean 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);
@@ -211,47 +209,44 @@
*******************************************************/
G_message(_("Pass 1 of 2 for clustering"));
G_percent_reset();
+ new_val = 0;
for (row = globals->row_min; row < globals->row_max; row++) {
G_percent(row - globals->row_min,
globals->row_max - globals->row_min, 4);
for (col = globals->col_min; col < globals->col_max; col++) {
if (!(FLAG_GET(globals->candidate_flag, row, col)))
continue;
- /* try to connect current pixel to a existing cluster */
- old_val = new_val = 0;
/* 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-1 < globals->col_min){
- col = globals->col_min +1;
+ if (col > globals->col_min){
+ Segment_get(&globals->bands_seg2, (void *)Rleft.mean, row, col-1);
+ /* compare with left value and set if same cluster */
+ if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ seg_id = new_val;
}
- Segment_get(globals->bands_out, (void *)Rleft.mean, row, col-1);
-
- /* compare with left value and set if same cluster */
- if ((globals->calculate_similarity)(&Rin, &Rleft, globals) <= pow((cluster_threshold * globals->max_diff),2)){
- old_val = Rin.mean[0] = Rleft.mean[0];
- }
- /* check diag */
-
- /* compare with above value and set if same cluster */
- else{
+ else if(row > globals->row_min){
/* get above pixel value */
- if (row-1 < globals->row_min){
- row = globals->row_min+1;
+ Segment_get(&globals->bands_seg2, (void *)Rabove.mean, row-1, col);
+ if ((globals->calculate_similarity)(&Rin, &Rabove, globals) <= pow((cluster_threshold * globals->max_diff),2)){
+ seg_id = new_val;
}
- 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)){
- temp_cluster = prev_cluster + col;
- // cur_cluster =
+ else{
+ new_val+=1;
+ seg_id = new_val;
+ }
}
}
+ G_debug(1, "row: %d, col: %d, seg_id is: %d",row,col,seg_id);
+ /* compare with above value and set if same cluster */
+ // segment_put(&globals->rid_seg, &seg_id, row,col);
}
}
- /* */
-
-
-
+
+ /* */
+
/*******************************************************
* Part 3 identify connected components *
* Merge small super-pixel to bigger super-pixels *
Modified: sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-17 02:24:44 UTC (rev 68702)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/write_output.c 2016-06-17 04:12:15 UTC (rev 68703)
@@ -61,8 +61,8 @@
if (globals->method == ORM_MS){
int seg2_fd;
DCELL *outbuf2, seg2;
- outbuf2 = Rast_allocate_c_buf();
-
+ outbuf2 = Rast_allocate_d_buf();
+
G_debug(1, "preparing shifted value output raster");
/* open output raster map */
seg2_fd = Rast_open_new(globals->ms_bands_out, DCELL_TYPE);
@@ -75,13 +75,11 @@
G_percent(row, globals->nrows, 9);
- Rast_set_c_null_value(outbuf2, globals->ncols);
+ Rast_set_d_null_value(outbuf2, globals->ncols);
for (col = 0; col < globals->ncols; col++) {
if (!(FLAG_GET(globals->null_flag, row, col))) {
Segment_get(&globals->bands_seg2, (void *) &seg2, row, col);
-
- G_message(_("Row %d, Col %d, is: %f"),row,col,seg2);
outbuf2[col] = seg2;
More information about the grass-commit
mailing list