[GRASS-SVN] r68673 - sandbox/bo/i.segment.gsoc2016/i.segment

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 12 13:17:14 PDT 2016


Author: hao2309
Date: 2016-06-12 13:17:14 -0700 (Sun, 12 Jun 2016)
New Revision: 68673

Modified:
   sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
   sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c
Log:
debugging ongoing, can't add bands_seg2 to openfile.c, grass stop running

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:39:56 UTC (rev 68672)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-12 20:17:14 UTC (rev 68673)
@@ -33,17 +33,20 @@
 
 int mean_shift(struct globals *globals)
 {
-    int row, col, t;
+    int row, col, current_window_row, current_window_col, t;
     int n_changes, window_size;
+	int window_row_north, window_row_south, window_col_west,window_col_east;
     double alpha2;
     struct ngbr_stats Rin, Rout, Rwin;
-    double diff2;
-
-    /* G_fatal_error(_("Mean shift is not yet implemented"));
-    return FALSE; */
+    double weight, sum_of_weights, diff2;
+	double min_val, max_val;
+    
 	double ms_spatial_bandwidth = 3;
 	double ms_range_bandwidth = 0.1;
 	
+	/* G_fatal_error(_("Mean shift is not yet implemented"));
+    return FALSE; */
+	
     Rin.mean = G_malloc(globals->datasize);
 	Rwin.mean = G_malloc(globals->datasize);
     Rout.mean = G_malloc(globals->datasize);
@@ -52,7 +55,7 @@
      * initially, input and output are original band values */
 	/* set the pointers */
 	globals->bands_in = &globals->bands_seg; 
-	globals->bands_out = &globals->bands_seg;
+	globals->bands_out = &globals->bands_seg2;
 	
 	/*window size in pixel number*/
 	window_size = ms_spatial_bandwidth*2+1;
@@ -83,6 +86,7 @@
 		    
 		    FLAG_SET(globals->candidate_flag, row, col);
 		    globals->candidate_count++;
+			
 		}
 	    }
 	}
@@ -98,13 +102,13 @@
 		if (!(FLAG_GET(globals->candidate_flag, row, col)))
 		    continue;
 		/* left bound of the window */
-		int window_row_north = row - globals->ms_spatial_bandwidth;
+		window_row_north = row - globals->ms_spatial_bandwidth;
 		/* right bound of the window */
-		int window_row_south = window_row_north + window_size;
+		window_row_south = window_row_north + window_size;
 		/* upper bound of the window */
-		int window_col_west = col - globals->ms_spatial_bandwidth;
+		window_col_west = col - globals->ms_spatial_bandwidth;
 		/* lower bound of the window */
-		int window_col_east = window_col_west + window_size;
+		window_col_east = window_col_west + window_size;
 			
 		/* clip window in the edge */
 		if (window_row_north < globals->row_min){
@@ -121,10 +125,9 @@
 			}
 			
 		/* calculate new band values */
-		double sum_of_weights = 0;
+		sum_of_weights = 0;
 		
 		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);
@@ -133,23 +136,24 @@
 		/* 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;
+		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++){
+				weight = 1;
 				/* adapt initial spatial and range bandwidths */
 				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);
+					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((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;
+						int n = globals->nbands - 1;
 						do{
 							weight *=1;/* later can apply gaussian kernal */
 							Rout.mean[n] += Rwin.mean[n]*weight;
@@ -166,7 +170,7 @@
 		
 		G_message(_("row: %d, col: %d, Rout.mean is: %f"),row,col,Rout.mean[0]);
 		/* write the output to bands_out*/
-		Segment_put(&globals->bands_seg, (void *)Rout.mean, row, col);
+		Segment_put(globals->bands_out, (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 

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:39:56 UTC (rev 68672)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/open_files.c	2016-06-12 20:17:14 UTC (rev 68673)
@@ -174,7 +174,7 @@
 	                    (void *)globals->bands_val, row, col) != 1)
 		G_fatal_error(_("Unable to write to temporary file"));
 
-		// /* add globals->bands_seg2 when using 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"));



More information about the grass-commit mailing list