[GRASS-SVN] r52452 - grass-addons/grass7/imagery/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 25 14:47:00 PDT 2012
Author: momsen
Date: 2012-07-25 14:46:59 -0700 (Wed, 25 Jul 2012)
New Revision: 52452
Modified:
grass-addons/grass7/imagery/i.segment/create_isegs.c
grass-addons/grass7/imagery/i.segment/iseg.h
grass-addons/grass7/imagery/i.segment/open_files.c
grass-addons/grass7/imagery/i.segment/parse_args.c
Log:
added initial attempt to grow from seeds, untested...
Modified: grass-addons/grass7/imagery/i.segment/create_isegs.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/create_isegs.c 2012-07-25 16:49:57 UTC (rev 52451)
+++ grass-addons/grass7/imagery/i.segment/create_isegs.c 2012-07-25 21:46:59 UTC (rev 52452)
@@ -389,7 +389,7 @@
G_message("estimate of tokens created %d", count + 15);
/*dispose tokens */
while (Rin_head != NULL) {
- current = Rin_head; /* rememer "old" head */
+ current = Rin_head; /* remember "old" head */
Rin_head = Rin_head->next; /* move head to next pixel */
link_dispose(files->token, (VOID_T *) current); /* remove "old" head */
}
@@ -921,9 +921,11 @@
"Lowest Ri_similarity = %g, for neighbor pixel row: %d col: %d",
Ri_similarity, Ri_bestn->row,
Ri_bestn->col);
-
+
+//if bounds map, can't check if it is a candidate. TODO better way to include this check after decide on using the candidate flag here.
+if(files->seeds_map == NULL){
//todo this "limited" flag will probably be removed? Then this entire if section could be removed if we always allow multiple merges per pass?
- if (functions->limited && !
+ if ((functions->limited == TRUE) && !
(FLAG_GET
(files->candidate_flag, Ri_bestn->row,
Ri_bestn->col))) {
@@ -933,7 +935,7 @@
pathflag = FALSE;
}
}
-
+}
if (Ri_bestn != NULL && Ri_similarity < threshold) { /* small TODO: should this be < or <= for threshold? */
/* Rk starts from Ri's best neighbor */
Rk_count = 1;
@@ -1583,6 +1585,8 @@
{
int row, col;
+ if(files->seeds_map == NULL) { /* entire map is considered as candidates */
+
//~ if (files->bounds_map == NULL) { /* process entire raster */
for (row = files->minrow; row < files->maxrow; row++) {
for (col = files->mincol; col < files->maxcol; col++) {
@@ -1611,7 +1615,22 @@
//~ }
//~ }
//~ }
-
+ }
+ else { /* seeds were provided */
+
+ for (row = files->minrow; row < files->maxrow; row++) {
+ for (col = files->mincol; col < files->maxcol; col++) {
+ if ((FLAG_GET(files->seeds_flag, row, col))) {
+ FLAG_SET(files->candidate_flag, row, col);
+ files->candidate_count++; //TODO, how deal with this...
+ }
+ else
+ FLAG_UNSET(files->candidate_flag, row, col); //todo maybe can skip this...
+ }
+ }
+ }
+
+
return TRUE;
}
Modified: grass-addons/grass7/imagery/i.segment/iseg.h
===================================================================
--- grass-addons/grass7/imagery/i.segment/iseg.h 2012-07-25 16:49:57 UTC (rev 52451)
+++ grass-addons/grass7/imagery/i.segment/iseg.h 2012-07-25 21:46:59 UTC (rev 52452)
@@ -40,8 +40,7 @@
/* files */
char *out_name; /* name of output raster map */
- const char *seeds, *bounds_map;
- const char *bounds_mapset; /* optional segment seeds and polygon constraints/boundaries */
+ const char *seeds_map, *seeds_mapset, *bounds_map, *bounds_mapset; /* optional segment seeds and polygon constraints/boundaries */
char *out_band; /* for debug */
/* file processing */
@@ -58,7 +57,7 @@
int nsegs; /* number of segments */
/* processing flags */
- FLAG *candidate_flag, *null_flag, *orig_null_flag;
+ FLAG *candidate_flag, *null_flag, *orig_null_flag, *seeds_flag;
/* memory management, linked lists */
struct link_head *token; /* for linkm.h linked list memory management. */
Modified: grass-addons/grass7/imagery/i.segment/open_files.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/open_files.c 2012-07-25 16:49:57 UTC (rev 52451)
+++ grass-addons/grass7/imagery/i.segment/open_files.c 2012-07-25 21:46:59 UTC (rev 52452)
@@ -10,10 +10,12 @@
int open_files(struct files *files)
{
struct Ref Ref; /* group reference list */
- int *in_fd, bounds_fd, null_check, out_fd, mean_fd;
+ int *in_fd, seeds_fd, bounds_fd, null_check, out_fd, mean_fd;
int i, n, s, row, col, srows, scols, inlen, nseg;
DCELL **inbuf; /* buffer array, to store lines from each of the imagery group rasters */
CELL *boundsbuf;
+ void *seedsbuf; /* todo. correct data type when allowing any data type? */
+ RASTER_MAP_TYPE data_type;
struct FPRange *fp_range; /* for getting min/max values on each input raster */
DCELL *min, *max;
@@ -37,6 +39,8 @@
files->candidate_flag = flag_create(files->nrows, files->ncols);
if (files->bounds_map != NULL)
files->orig_null_flag = flag_create(files->nrows, files->ncols);
+ if (files->seeds_map != NULL)
+ files->seeds_flag = flag_create(files->nrows, files->ncols);
/* references for segmentation library: i.cost r.watershed/seg and http://grass.osgeo.org/programming7/segmentlib.html */
@@ -164,6 +168,30 @@
/* number of initial segments, will decrement when merge */
files->nsegs = s - 1;
+ /* starting seeds */
+ /* save as flag, will reset candidate flags to match seed flags on each iteration */
+ if (files->seeds_map != NULL) {
+ seeds_fd = Rast_open_old(files->seeds_map, "");
+ data_type = Rast_get_map_type(seeds_fd);
+ seedsbuf = Rast_allocate_buf(data_type);
+
+ for (row = 0; row < files->nrows; row++) {
+ Rast_get_row(seeds_fd, seedsbuf, row, data_type);
+ for (col = 0; col < files->ncols; col++) {
+
+ if (Rast_is_null_value(&seedsbuf[col], data_type) == TRUE) { /* TODO, compiler warnings:
+ * open_files.c:182:37: warning: dereferencing ‘void *’ pointer [enabled by default]
+ * open_files.c:182:27: warning: taking address of expression of type ‘void’ [enabled by default]
+ */
+
+ FLAG_SET(files->seeds_flag, row, col);
+ }
+ }
+ }
+ Rast_close(seeds_fd);
+ G_free(seedsbuf);
+ }
+
/* bounds/constraints */
if (files->bounds_map != NULL) {
if (segment_open
Modified: grass-addons/grass7/imagery/i.segment/parse_args.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/parse_args.c 2012-07-25 16:49:57 UTC (rev 52451)
+++ grass-addons/grass7/imagery/i.segment/parse_args.c 2012-07-25 21:46:59 UTC (rev 52452)
@@ -172,7 +172,20 @@
functions->calculate_similarity = &calculate_euclidean_similarity; /* TODO add user input for this */
- files->seeds = seeds->answer;
+ if (seeds->answer == NULL) { /* no starting seeds, will use all pixels as seeds */
+ files->seeds_map = NULL;
+ }
+ else { /* polygon constraints given */
+ files->seeds_map = seeds->answer;
+ if ((files->seeds_mapset =
+ G_find_raster2(files->seeds_map, "")) == NULL) {
+ G_fatal_error(_("Starting seeds map not found."));
+ }
+ //~ if (Rast_map_type(files->seeds_map, files->seeds_mapset) !=
+ //~ CELL_TYPE) {
+ //~ G_fatal_error(_("Starting seeds map must be CELL type (integers)"));
+ //~ } //todo: don't need this check, want it for polygon constraints, but for seeds we are just looking for null vs. not null
+ }
if (bounds->answer == NULL) { /*no polygon constraints */
files->bounds_map = NULL;
More information about the grass-commit
mailing list