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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 8 12:39:28 PDT 2016


Author: hao2309
Date: 2016-06-08 12:39:28 -0700 (Wed, 08 Jun 2016)
New Revision: 68640

Modified:
   sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
   sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
Log:
updated gaussian kernal

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h	2016-06-08 16:26:53 UTC (rev 68639)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/iseg.h	2016-06-08 19:39:28 UTC (rev 68640)
@@ -78,8 +78,8 @@
     /* file processing */
     int nbands;			/* number of rasters in the image group */
     SEGMENT bands_seg, 	        /* input group with one or more bands */
-            bounds_seg,
-			bands_seg2,  /* copy of bands_seg for mean shift */
+            bands_seg2,  /* copy of bands_seg for mean shift */
+			bounds_seg,
 	    rid_seg;
 	SEGMENT *bands_in, *bands_out;  /* pointers to rotate input/output bands for mean shift */
     DCELL *bands_min, *bands_max;

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-08 16:26:53 UTC (rev 68639)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-08 19:39:28 UTC (rev 68640)
@@ -126,7 +126,8 @@
 			for (int current_window_col = window_col_west;current_window_col<window_col_east;current_window_col++){
 				float weight =1;
 				/* adapt initial spatial and range bandwidths */
-				if (pow((current_window_row - row),2)+pow((current_window_col - col),2) <= pow(globals->ms_bandwidth,2)){
+				double distance2 = pow((current_window_row - row),2)+pow((current_window_col - col),2);
+				if (distance2 <= pow(globals->ms_bandwidth,2)){
 					/* get the current pixel value */
 					Segment_get(&globals->bands_seg, (void *)Rin.mean,row, col);
 							
@@ -134,7 +135,7 @@
 					Segment_get(&globals->bands_seg, (void *)Rwin.mean,current_window_row, current_window_col);
 					/* check range bandwidth */
 					if ((globals->calculate_similarity)(&Rin, &Rwin, globals) <= (globals->ms_range_bandwidth * globals->ms_range_bandwidth)){
-						weight *=1;
+						weight *=gauss_kernel(pow((Rin.mean[0]-Rwin.mean[0]),2),distance2);
 						sum_of_weights += weight;
 						new_val += Rwin.mean[0]*weight;
 					}
@@ -142,17 +143,19 @@
 			}/* end of moving window col */
 		}/* end of moving window row */
 		
+		
 		/* write the output to bands_out*/
 		Rout.mean[0] = new_val;
-		Segment_put(&globals->bands_out, (void *)Rout.mean, row, col);
-
 		
+		Segment_put(&globals->bands_seg, (void *)Rout.mean, row, col);
+		/* G_message(_("test")); */
 		/* if the squared difference between old and new band values 
 		 * is larger than alpha2, then increase n_changes */
 		
 		diff2 = (globals->calculate_similarity)(&Rin, &Rout, globals);
 		if (diff2 > alpha2)
 		    n_changes++;
+		
 	    }/* end col iteration */
 	}/* end row iteration */
     }/* end while iteration */



More information about the grass-commit mailing list