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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 17 20:44:17 PDT 2016


Author: hao2309
Date: 2016-06-17 20:44:16 -0700 (Fri, 17 Jun 2016)
New Revision: 68709

Modified:
   sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
Log:
write the clustering result to rid and output the result

Modified: sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c
===================================================================
--- sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-17 19:52:07 UTC (rev 68708)
+++ sandbox/bo/i.segment.gsoc2016/i.segment/mean_shift.c	2016-06-18 03:44:16 UTC (rev 68709)
@@ -40,7 +40,8 @@
     struct ngbr_stats Rin, Rout, Rwin;
 	struct ngbr_stats Rleft, Rabove;
     double weight, sum_of_weights, diff2;
-	int seg_id, new_val;
+	int seg_id, class_val;
+	CELL left_new_val, above_new_val;
 	double min_val, max_val; 
 
 	/* G_fatal_error(_("Mean shift is not yet implemented"));
@@ -209,7 +210,7 @@
     *******************************************************/
 	G_message(_("Pass 1 of 2 for clustering"));
 	G_percent_reset();
-	new_val = 0;
+	class_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);
@@ -218,30 +219,66 @@
 		    continue;
 		
 		/* get the current pixel value */
-		Segment_get(&globals->bands_seg2, (void *)Rin.mean, row, col);
-
+		Segment_get(globals->bands_out, (void *)Rin.mean, row, col);
 		/* get left pixel value */
-		if (col > globals->col_min){
-			Segment_get(&globals->bands_seg2, (void *)Rleft.mean, row, col-1);
+		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)){
-			seg_id = new_val;
+				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(row > globals->row_min){
-			/* get above pixel value */
-				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;
-				}
-				else{
-					new_val+=1;
-					seg_id = new_val;
-				}
+			/* end compare left */
+			else{
+				seg_id=class_val;
+				class_val+=1;
 			}
 		}
+		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)){
+				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;
+			}
+		}
+		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)){
+				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)){
+				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;
+			}
+		}
+		
+		G_debug(1, "row: %d, col: %d, Rin is: %f",row,col,Rin.mean[0]);
+		
 		G_debug(1, "row: %d, col: %d, seg_id is: %d",row,col,seg_id);
+		// G_debug(1, "row: %d, col: %d, cluster_threshold * globals->max_diff is: %f",row,col,pow((cluster_threshold * globals->max_diff),2));
 		/* compare with above value and set if same cluster */
-		// segment_put(&globals->rid_seg, &seg_id, row,col);
+		Segment_put(&globals->rid_seg, &seg_id, row, col);
 		}
 	}
 	



More information about the grass-commit mailing list