[GRASS-SVN] r52431 - grass-addons/grass7/imagery/i.segment

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 20 15:20:28 PDT 2012


Author: momsen
Date: 2012-07-20 15:20:28 -0700 (Fri, 20 Jul 2012)
New Revision: 52431

Modified:
   grass-addons/grass7/imagery/i.segment/create_isegs.c
   grass-addons/grass7/imagery/i.segment/iseg.h
   grass-addons/grass7/imagery/i.segment/main.c
   grass-addons/grass7/imagery/i.segment/open_files.c
   grass-addons/grass7/imagery/i.segment/parse_args.c
   grass-addons/grass7/imagery/i.segment/write_output.c
Log:
option for processing in boundary constraints is fixed, other small changes.

Modified: grass-addons/grass7/imagery/i.segment/create_isegs.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/create_isegs.c	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/create_isegs.c	2012-07-20 22:20:28 UTC (rev 52431)
@@ -45,82 +45,67 @@
     for (files->current_bound = lower_bound;
 	 files->current_bound <= upper_bound; files->current_bound++) {
 
-	/* check the processing window */
+	if (files->bounds_map == NULL)
+	    G_message(_("Running region growing algorithm, the percent completed is based the range of values in the boundary constraints map"));
+	G_percent(files->current_bound - lower_bound,
+		  upper_bound - lower_bound, 1);
+
+	/* *** check the processing window *** */
+
+	/* set boundaries at "opposite" end, change until reach lowest/highest */
+	files->minrow = files->nrows;
+	files->mincol = files->ncols;
+	files->maxrow = files->maxcol = 0;
+
 	if (files->bounds_map == NULL) {
-	    files->minrow = files->mincol = 0;
-	    files->maxrow = files->nrows;
-	    files->maxcol = files->ncols;
-	    /* todo polish: could actually check the NULL flag to see where the first/last row/col of real data are, and reduce the processing window.
-	     * This could help (a little?) if a MASK is used that removes a large part of the map. */
-	}
-	else {
-	    /* todo, Markus, should there be a faster way to find this?  Something already in GRASS that I can call? */
-	    /* find first row that matches the current bound value */
+	    /* check the NULL flag to see where the first/last row/col of real data are, and reduce the processing window.
+	     * This could help (a little?) if a MASK is used that removes a large border portion of the map. */
 	    for (row = 0; row < files->nrows; row++) {
 		for (col = 0; col < files->ncols; col++) {
-		    segment_get(&files->bounds_seg, &files->bounds_val, row,
-				col);
-		    if (files->bounds_val == files->current_bound) {
-			files->minrow = row;
-			/* break a nested loop... hmm, could change this to a function call, use a flag, or use peano iteration. */
-			goto done1;	/* or is this one of the few places where a goto loop is OK? */
-		    }
-		}
-	    }
-	  done1:
 
-	    for (col = 0; col < files->ncols; col++) {
-		for (row = 0; row < files->nrows; row++) {
-		    segment_get(&files->bounds_seg, &files->bounds_val, row,
-				col);
-		    if (files->bounds_val == files->current_bound) {
-			files->mincol = col;
-			goto done2;
+		    if (!(FLAG_GET(files->null_flag, row, col))) {
+
+			if (files->minrow > row)
+			    files->minrow = row;
+			if (files->maxrow < row)
+			    files->maxrow = row;
+			if (files->mincol > col)
+			    files->mincol = col;
+			if (files->maxcol < col)
+			    files->maxcol = col;
 		    }
 		}
 	    }
-	  done2:
+	}
+	else {
+	    for (row = 0; row < files->nrows; row++) {
+		for (col = 0; col < files->ncols; col++) {
 
-	    for (row = files->nrows - 1; row >= 0; row--) {
-		for (col = files->ncols - 1; col >= 0; col--) {
 		    segment_get(&files->bounds_seg, &files->bounds_val, row,
 				col);
-		    if (files->bounds_val == files->current_bound) {
-			files->maxrow = row;
-			goto done3;
-		    }
-		}
-	    }
-	  done3:
+		    if (files->bounds_val == files->current_bound &&
+			!(FLAG_GET(files->orig_null_flag, row, col))) {
+			FLAG_UNSET(files->null_flag, row, col);
 
-	    for (col = files->ncols - 1; col >= 0; col--) {
-		for (row = files->nrows - 1; row >= 0; row--) {
-		    segment_get(&files->bounds_seg, &files->bounds_val, row,
-				col);
-		    if (files->bounds_val == files->current_bound) {
-			files->maxcol = col;
-			goto done4;
+			if (files->minrow > row)
+			    files->minrow = row;
+			if (files->maxrow < row)
+			    files->maxrow = row;
+			if (files->mincol > col)
+			    files->mincol = col;
+			if (files->maxcol < col)
+			    files->maxcol = col;
+
 		    }
+		    else	/* pixel is outside the current boundary or was null in the input bands */
+			FLAG_SET(files->null_flag, row, col);
 		}
 	    }
-	  done4:
-	    G_message("minrow: %d, maxrow: %d, mincol: %d, maxcol: %d", files->minrow, files->maxrow, files->mincol, files->maxcol);	//TODO change to debug.
+	    G_debug(1, "minrow: %d, maxrow: %d, mincol: %d, maxcol: %d",
+		    files->minrow, files->maxrow, files->mincol,
+		    files->maxcol);
 
-	    /* set the in_bound_flag */
-	    for (row = 0; row < files->nrows; row++) {
-		for (col = 0; col < files->ncols; col++) {
-		    if (!(FLAG_GET(files->null_flag, row, col))) {
-			segment_get(&files->bounds_seg, &files->bounds_val,
-				    row, col);
-			if (files->bounds_val == files->current_bound) {
-			    FLAG_SET(files->in_bounds_flag, row, col);
-			}
-			else
-			    FLAG_UNSET(files->in_bounds_flag, row, col);
-		    }
-		}
-	    }
-	    /* clear candidate flag, so only need to reset the processing area on each iteration. */
+	    /* clear candidate flag, so only need to reset the processing area on each iteration. todo polish, can be removed after all loops only cover the processing area */
 	    flag_clear_all(files->candidate_flag);
 
 	}			/* end of else, set up for bounded segmentation */
@@ -140,7 +125,20 @@
 #endif
     }				/* end outer loop for processing polygons */
 
-    return successflag;
+    /* reset null flag to the original if we have boundary constraints */
+    if (files->bounds_map != NULL) {
+	for (row = 0; row < files->nrows; row++) {
+	    for (col = 0; col < files->ncols; col++) {
+		if (FLAG_GET(files->orig_null_flag, row, col))
+		    FLAG_SET(files->null_flag, row, col);
+		else
+		    FLAG_UNSET(files->null_flag, row, col);
+	    }
+	}
+    }
+
+
+    return successflag;		/* todo, successflag was assuming one pass... don't have anything to pick up a failure if there is a bounds constraint */
 }
 
 #ifdef DEBUG
@@ -438,49 +436,49 @@
 	start = clock();
 	for (i = 0; i < max; i++) {
 	    no_check_tree = rbtree_create(compare_ids, sizeof(struct pixels));
+
 	    /*build */
 	    for (j = 0; j < n; j++) {
+		tree_pix = (struct pixels *)link_new(files->token);
 		tree_pix->row = tree_pix->col = j;
 		rbtree_insert(no_check_tree, &tree_pix);
 	    }
 	    /*access */
-	    rbtree_init_trav(&trav, no_check_tree);
-	    /*not sure how to do this...
-	       while ((data = rbtree_traverse(&trav)) != NULL) {
-	       if (my_compare_fn(data, threshold_data) == 0) break;
-	       G_message("%d", data);
-	       }
-	     */
+	    for (j = 0; j < n; j++) {
+		if (rbtree_find(no_check_tree, &tree_pix))
+		    continue;	/* always looking for the same pixel...is this an easy or hard one to find? */
+	    }
 	    /*free memory */
 	    rbtree_destroy(no_check_tree);
 	}
 	end = clock();
 	cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
 	G_message
-	    ("Using rbtree of pixels (just build/destroy), %d elements, time: %g",
+	    ("Using rbtree of pixels ( build/find/destroy), %d elements, time: %g",
 	     n, cpu_time_used);
 
 	start = clock();
 	for (i = 0; i < max; i++) {
 	    known_iseg_tree = rbtree_create(compare_ids, sizeof(int));
+
 	    /*build */
 	    for (j = 0; j < n; j++) {
 		rbtree_insert(known_iseg_tree, &j);
 	    }
+
 	    /*access */
-	    rbtree_init_trav(&trav, known_iseg_tree);
-	    /*
-	       while ((data = rbtree_traverse(&trav)) != NULL) {
-	       if (my_compare_fn(data, threshold_data) == 0) break;
-	       G_message("%d", data);
-	       } */
+	    for (j = 0; j < n; j++) {
+		if (rbtree_find(known_iseg_tree, &j))
+		    continue;
+	    }
+
 	    /*free memory */
 	    rbtree_destroy(known_iseg_tree);
 	}
 	end = clock();
 	cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
 	G_message
-	    ("Using rbtree ints (just build/destroy), %d elements, time: %g",
+	    ("Using rbtree ints ( build/find/destroy), %d elements, time: %g",
 	     n, cpu_time_used);
 
 
@@ -517,17 +515,18 @@
 	start = clock();
 	for (i = 0; i < max; i++) {
 	    known_iseg_tree = rbtree_create(compare_ids, sizeof(int));
-	    rbtree_init_trav(&trav, known_iseg_tree);
 
 	    /*build */
 	    for (j = 0; j < n; j++) {
 		rbtree_insert(known_iseg_tree, &j);
 	    }
+
 	    /*access */
-	    /* while ((data = rbtree_traverse(&trav)) != NULL) {
-	       if (my_compare_fn(data, threshold_data) == 0) break;
-	       G_message("%d", data);
-	       } */
+	    for (j = 0; j < n; j++) {
+		if (rbtree_find(known_iseg_tree, &j))
+		    continue;
+	    }
+
 	    /*free memory */
 	    rbtree_destroy(known_iseg_tree);
 	}
@@ -603,31 +602,60 @@
 
     /* iff bounding constraints have been given, need to confirm neighbors are in the same area.
      * Faster to check if the bounds map is null, or if no bounds just set all the bounds flags to 1 and directly check the bounds flag? */
+    {
+	max = INT_MAX;
+	j = 0;
+	G_message("compare if statement to FLAG_GET, repeating %d times",
+		  max);
+	G_message("Flag = %d", FLAG_GET(files->candidate_flag, 1, 1));
+
+	start = clock();
+	for (i = 0; i < max; i++) {
+	    if ((FLAG_GET(files->candidate_flag, 1, 1)) != 0) {
+		j++;
+	    }
+	}
+	end = clock();
+	cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
+	G_message("FLAG_GET: %g, temp: %d", cpu_time_used, j);
+	j = 0;
+	start = clock();
+	for (i = 0; i < max; i++) {
+	    if (files->bounds_map != NULL) {
+		j++;
+	    }
+	}
+	end = clock();
+	cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
+	G_message("check for NULL: %g, temp: %d", cpu_time_used, j);	/* was faster by about 20% */
+    }
+
+    /* is accessing a variable different then a value? */
     max = INT_MAX;
-    j = 0;
-    G_message("compare if statement to FLAG_GET, repeating %d times", max);
-    G_message("Flag = %d", FLAG_GET(files->candidate_flag, 1, 1));
+    j = k = 0;
+    G_message("compare variable to number, repeating %d times", max);
 
     start = clock();
     for (i = 0; i < max; i++) {
-	if ((FLAG_GET(files->candidate_flag, 1, 1)) != 0) {
+	if (i > 0) {
 	    j++;
 	}
     }
     end = clock();
     cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
-    G_message("FLAG_GET: %g, temp: %d", cpu_time_used, j);
+    G_message("compare to zero: %g, temp: %d", cpu_time_used, j);
     j = 0;
     start = clock();
     for (i = 0; i < max; i++) {
-	if (files->bounds_map != NULL) {
+	if (i > k) {
 	    j++;
 	}
     }
     end = clock();
     cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
-    G_message("check for NULL: %g, temp: %d", cpu_time_used, j);	/* was faster by about 20% */
+    G_message("compare to k: %g, temp: %d", cpu_time_used, j);	/* was faster by about 20% */
 
+
     return TRUE;
 }
 
@@ -662,7 +690,9 @@
      * Rin = Ri's neigbors
      * */
 
-    G_message("Running region growing algorithm, the percent completed is based on %d max iterations, but the process will end earlier if no further merges can be made.", functions->end_t);	/*TODO polish: can _() be combined with %d ? */
+    if (files->bounds_map == NULL)
+	G_message(_("Running region growing algorithm, the percent completed is based on %d max iterations, but the process will end earlier if no further merges can be made."),
+		  functions->end_t);
 
     t = 1;
     files->candidate_count = 0;
@@ -674,13 +704,11 @@
     Rkn_head = NULL;
     Ri_bestn = NULL;
 
-    /* TODO, want to get a min/max row/col to narrow the processing window ??? certainly if polygon constraints. */
-
     /* do while loop until no merges are made, or until t reaches maximum number of iterations */
     do {
 
 	G_debug(3, "#######   Starting outer do loop! t = %d    #######", t);
-	G_verbose_message("Pass %d: ", t);
+	/* todo, delete this?  G_verbose_message("Pass %d: ", t); */
 	G_percent(t, functions->end_t, 1);
 
 	threshold = functions->threshold;	/* TODO, consider making this a function of t. */
@@ -759,8 +787,7 @@
 			    /* for each of Ri's neighbors */
 			    for (current = Rin_head; current != NULL;
 				 current = current->next) {
-				tempsim =
-				    (*functions->calculate_similarity)
+				tempsim = (*functions->calculate_similarity)
 				    (Ri_head, current, files, functions);
 				G_debug(4,
 					"simularity = %g for neighbor : row: %d, col %d.",
@@ -880,24 +907,24 @@
 			    /* So for the next iteration, lets start with Rk as the focus segment */
 			    /* Seems this should be a bit faster, since we already have segment membership pixels */
 			    /* TODO: this shortened each iteration time by about 10% but increased the number of iterations by 20% ?!?!?!? */
-			if(functions->path == TRUE){
-			    Ri_count = Rk_count;
-			    Rk_count = 0;
-			    my_dispose_list(files->token, &Ri_head);
-			    Ri_head = Rk_head;
-			    Rk_head = NULL;
-			    if (Rkn_head != NULL) {
-				my_dispose_list(files->token, &Rin_head);
-				Rin_head = Rkn_head;
-				Rkn_head = NULL;
+			    if (functions->path == TRUE) {
+				Ri_count = Rk_count;
+				Rk_count = 0;
+				my_dispose_list(files->token, &Ri_head);
+				Ri_head = Rk_head;
+				Rk_head = NULL;
+				if (Rkn_head != NULL) {
+				    my_dispose_list(files->token, &Rin_head);
+				    Rin_head = Rkn_head;
+				    Rkn_head = NULL;
+				}
+				else
+				    my_dispose_list(files->token, &Rin_head);
 			    }
 			    else
-				my_dispose_list(files->token, &Rin_head);
+				pathflag = FALSE;
+
 			}
-			else
-			pathflag = FALSE;
-			
-			}
 
 		    }		/*end pathflag do loop */
 		}		/*end if pixel is candidate pixel */
@@ -923,7 +950,7 @@
     /* ****************************************************************************************** */
 
 
-    if (functions->min_segment_size > 1) {
+    if (functions->min_segment_size > 1 && t > 2) {	/* NOTE: added t > 2, it doesn't make sense to force merges if no merges were made on the original pass.  Something should be adjusted first */
 	G_verbose_message
 	    (_("Final iteration, forcing merges for small segments, percent complete based on rows."));
 
@@ -1036,11 +1063,14 @@
 		}		/* end if pixel is candidate pixel */
 	    }			/* next column */
 	}			/* next row */
+	t++;			/* to count one more "iteration" */
     }				/* end if for force merge */
     else
-	G_verbose_message(_("Input for minimum pixels in a segment was 1, will not force a merge for small segments."));
+	/* todo delete?  G_verbose_message(_("Input for minimum pixels in a segment was 1, will not force a merge for small segments.")); */
 
-    G_message("temporary(?) message, number of passes: %d", t - 1);
+    if (t > 2)
+	G_verbose_message("temporary(?) message, number of passes: %d",
+			  t - 1);
 
     return TRUE;
 }
@@ -1136,23 +1166,15 @@
 	for (n = 0; n < functions->num_pn; n++) {
 
 	    /* skip pixel if out of computational area or null */
-	    if (pixel_neighbors[n][0] < 0 ||
-		pixel_neighbors[n][0] >= files->nrows ||
-		pixel_neighbors[n][1] < 0 ||
-		pixel_neighbors[n][1] >= files->ncols ||
+	    if (pixel_neighbors[n][0] < files->minrow ||
+		pixel_neighbors[n][0] >= files->maxrow ||
+		pixel_neighbors[n][1] < files->mincol ||
+		pixel_neighbors[n][1] >= files->maxcol ||
 		FLAG_GET(files->null_flag, pixel_neighbors[n][0],
 			 pixel_neighbors[n][1])
 		)
 		continue;
 
-	    /* skip pixel if not in same boundary area */
-	    //~ if(files->bounds_map != NULL){
-	    //~ segment_get(&files->bounds_seg, &files->bounds_val, pixel_neighbors[n][0], pixel_neighbors[n][1]);
-	    //~ if (files->bounds_val != files->current_bound) {
-	    //~ continue;
-	    //~ }
-	    //~ }
-
 	    tree_pix.row = pixel_neighbors[n][0];
 	    tree_pix.col = pixel_neighbors[n][1];
 	    G_debug(5,
@@ -1349,6 +1371,10 @@
 
     }
 
+    /* merged two segments, decrement count */
+    files->nsegs--;
+    /* todo seeds: need if statement here, if merging "unseeded" pixel, don't want to decrement. */
+
     return TRUE;
 }
 
@@ -1438,34 +1464,34 @@
 {
     int row, col;
 
-    if (files->bounds_map == NULL) {	/* process entire raster */
-	for (row = files->minrow; row < files->maxrow; row++) {
-	    for (col = files->mincol; col < files->maxcol; col++) {
-		/* TODO: if we are starting from seeds...and only allow merges between unassigned pixels
-		 *  and seeds/existing segments, then this needs an if (and will be very inefficient)
-		 * maybe consider the sorted array, btree, map... but the number of seeds could still be high for a large map */
-		/* MM: could be solved/not necessary if all pixels of an existing segment have the same ID */
-		if (!(FLAG_GET(files->null_flag, row, col))) {
-		    FLAG_SET(files->candidate_flag, row, col);
-		    files->candidate_count++;
-		}
-		else
-		    FLAG_UNSET(files->candidate_flag, row, col);
+    //~ if (files->bounds_map == NULL) {        /* process entire raster */
+    for (row = files->minrow; row < files->maxrow; row++) {
+	for (col = files->mincol; col < files->maxcol; col++) {
+	    /* TODO: if we are starting from seeds...and only allow merges between unassigned pixels
+	     *  and seeds/existing segments, then this needs an if (and will be very inefficient)
+	     * maybe consider the sorted array, btree, map... but the number of seeds could still be high for a large map */
+	    /* MM: could be solved/not necessary if all pixels of an existing segment have the same ID */
+	    if (!(FLAG_GET(files->null_flag, row, col))) {
+		FLAG_SET(files->candidate_flag, row, col);
+		files->candidate_count++;
 	    }
+	    else
+		FLAG_UNSET(files->candidate_flag, row, col);
 	}
     }
-    else {			/* process part of the raster, polygon constraints/boundaries */
-	for (row = files->minrow; row < files->maxrow; row++) {
-	    for (col = files->mincol; col < files->maxcol; col++) {
-		if (!(FLAG_GET(files->in_bounds_flag, row, col))) {
-		    FLAG_SET(files->candidate_flag, row, col);
-		    files->candidate_count++;
-		}
-		else
-		    FLAG_UNSET(files->candidate_flag, row, col);
-	    }
-	}
-    }
+    //~ }
+    //~ else {                  /* process part of the raster, polygon constraints/boundaries */
+    //~ for (row = files->minrow; row < files->maxrow; row++) {
+    //~ for (col = files->mincol; col < files->maxcol; col++) {
+    //~ if (!(FLAG_GET(files->in_bounds_flag, row, col))) {
+    //~ FLAG_SET(files->candidate_flag, row, col);
+    //~ files->candidate_count++;
+    //~ }
+    //~ else
+    //~ FLAG_UNSET(files->candidate_flag, row, col);
+    //~ }
+    //~ }
+    //~ }
 
     return TRUE;
 }

Modified: grass-addons/grass7/imagery/i.segment/iseg.h
===================================================================
--- grass-addons/grass7/imagery/i.segment/iseg.h	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/iseg.h	2012-07-20 22:20:28 UTC (rev 52431)
@@ -54,10 +54,11 @@
     int minrow, maxrow, mincol, maxcol;
 
     /* results */
-    int **iseg;			/*segment ID assignment. */
+    int **iseg;			/* segment ID assignment */
+    int nsegs;			/* number of segments */
 
     /* processing flags */
-    FLAG *candidate_flag, *null_flag, *in_bounds_flag;
+    FLAG *candidate_flag, *null_flag, *orig_null_flag;
 
     /* memory management, linked lists */
     struct link_head *token;	/* for linkm.h linked list memory management. */
@@ -80,8 +81,8 @@
 
     /* max number of iterations/passes */
     int end_t;
-    
-    /* todo remove when decide on pathflag*/
+
+    /* todo remove when decide on pathflag */
     int path;
 };
 

Modified: grass-addons/grass7/imagery/i.segment/main.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/main.c	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/main.c	2012-07-20 22:20:28 UTC (rev 52431)
@@ -55,7 +55,7 @@
     G_debug(1, "Main: starting close_files()");
     close_files(&files);
 
-    G_done_msg("Number of segments created: TODO");
+    G_done_msg("Number of segments created: %d", files.nsegs);
 
     exit(EXIT_SUCCESS);
 }

Modified: grass-addons/grass7/imagery/i.segment/open_files.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/open_files.c	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/open_files.c	2012-07-20 22:20:28 UTC (rev 52431)
@@ -36,13 +36,13 @@
     files->null_flag = flag_create(files->nrows, files->ncols);
     files->candidate_flag = flag_create(files->nrows, files->ncols);
     if (files->bounds_map != NULL)
-	files->in_bounds_flag = flag_create(files->nrows, files->ncols);
+	files->orig_null_flag = flag_create(files->nrows, files->ncols);
 
     /* references for segmentation library: i.cost r.watershed/seg and http://grass.osgeo.org/programming7/segmentlib.html */
 
     /* ****** open the input rasters ******* */
 
-    /* TODO: I confirmed, the API does not check this.  Markus, should this be checked in parse_args / validation ?  Or best to do here where I want to use the REF data? */
+    /* Note: I confirmed, the API does not check this. */
     G_debug(1, "Checking image group...");
     if (!I_get_group_ref(files->image_group, &Ref))
 	G_fatal_error(_("Unable to read REF file for group <%s>"),
@@ -161,6 +161,21 @@
 	}
     }
 
+    /* keep original copy of null flag if we have boundary constraints */
+    if (files->bounds_map != NULL) {
+	for (row = 0; row < files->nrows; row++) {
+	    for (col = 0; col < files->ncols; col++) {
+		if (FLAG_GET(files->null_flag, row, col))
+		    FLAG_SET(files->orig_null_flag, row, col);
+		else		/* todo polish, flags are initialized to zero... could just skip this else? */
+		    FLAG_UNSET(files->orig_null_flag, row, col);
+	    }
+	}
+    }
+
+    /* number of initial segments, will decrement when merge */
+    files->nsegs = s - 1;
+
     /* bounds/constraints */
     /* TODO: You should also handle NULL cells in the bounds
      * raster map, I would suggest to replace NULL with min(bounds) - 1 or
@@ -191,6 +206,8 @@
     /* other info */
     files->candidate_count = 0;	/* counter for remaining candidate pixels */
 
+    /* translate seeds to unique segments TODO MM mentioned it here... */
+
     /* linked list memory management linkm */
     link_set_chunk_size(100);	/* TODO polish: fine tune this number */
 

Modified: grass-addons/grass7/imagery/i.segment/parse_args.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/parse_args.c	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/parse_args.c	2012-07-20 22:20:28 UTC (rev 52431)
@@ -41,13 +41,14 @@
     method->description = _("Segmentation method.");
 
     min_segment_size = G_define_option();
-    min_segment_size->key = "min";	/*TODO Markus, is there a preference for long or short key names? min is pretty generic...but short... */
+    min_segment_size->key = "minsize";
     min_segment_size->type = TYPE_INTEGER;
     min_segment_size->required = YES;
     min_segment_size->answer = "1";	/* default: no merges, a minimum of 1 pixel is allowed in a segment. */
     min_segment_size->options = "1-100000";
+    min_segment_size->label = _("Minimum number of cells in a segment.");
     min_segment_size->description =
-	_("Minimum number of pixels (cells) in a segment.  The final merge step will ignore the threshold for any segments with fewer pixels.");
+	_("The final iteration will ignore the threshold for any segments with fewer pixels.");
 
     /* optional parameters */
 
@@ -182,8 +183,8 @@
 
     /* debug help */
 
-	functions->path = path->answer;	/* default/0 for no pathflag, but selected/1 to use Rk as next Ri if not mutually best neighbors. */
-    
+    functions->path = path->answer;	/* default/0 for no pathflag, but selected/1 to use Rk as next Ri if not mutually best neighbors. */
+
     if (outband->answer == NULL)
 	files->out_band = NULL;
     else {

Modified: grass-addons/grass7/imagery/i.segment/write_output.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/write_output.c	2012-07-20 17:53:52 UTC (rev 52430)
+++ grass-addons/grass7/imagery/i.segment/write_output.c	2012-07-20 22:20:28 UTC (rev 52431)
@@ -54,6 +54,7 @@
      * current:         |   Data Description:                                                        |
      *                          |    generated by i.segment                                                  |
      * It would be nice to save the segmentation settings (just the CL?  Or something more human readable?)
+     * * MM: see e.g. i.pca for an example of setting custom info
      */
 
     /* close and save file */
@@ -64,7 +65,7 @@
     /* set colors */
     Rast_init_colors(&colors);
     Rast_make_random_colors(&colors, 1, files->nrows * files->ncols);	/* TODO polish - number segments from 1 - max ? and then can use that max here. */
-    Rast_write_colors(files->out_name, G_mapset(), &colors);	/* TODO, OK to just use G_mapset() here, seems I don't use it anywhere else, and that is where the output has to be written.  (Markus, should the library allow changing colors to other mapsets? I was suprised it was needed as a parameter.) */
+    Rast_write_colors(files->out_name, G_mapset(), &colors);
 
     /* free memory */
     G_free(outbuf);



More information about the grass-commit mailing list