Changeset 58886
- Timestamp:
- Feb 5, 2014, 8:36:23 AM (11 years ago)
- Location:
- grass-addons/grass7/raster
- Files:
-
- 1 deleted
- 4 edited
- 2 copied
-
Makefile (modified) (1 diff)
-
r.segment (copied) (copied from grass-addons/grass6/raster/r.seg )
-
r.segment/Makefile (modified) (1 diff)
-
r.segment/README (modified) (1 diff)
-
r.segment/description.html (deleted)
-
r.segment/main.c (modified) (20 diffs)
-
r.segment/r.segment.html (copied) (copied from grass-addons/grass6/raster/r.seg/description.html ) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
grass-addons/grass7/raster/Makefile
r58619 r58886 19 19 r.modis \ 20 20 r.regression.series \ 21 r.segment \ 21 22 r.stream.basins \ 22 23 r.stream.channel \ -
grass-addons/grass7/raster/r.segment/Makefile
r43846 r58886 1 1 MODULE_TOPDIR = ../.. 2 2 3 PGM = r.seg 3 PGM = r.segment 4 4 5 LIBES = $(SEGLIB) $(GISLIB) 6 DEPENDENCIES = $(SEGDEP) $(GISDEP) 5 LIBES = $(GISLIB) $(RASTERLIB) $(SEGMENTLIB) 6 DEPENDENCIES = $(GISDEP) $(RASTERDEP) $(SEGMENTDEP) 7 7 8 8 9 include $(MODULE_TOPDIR)/include/Make/Module.make 9 include $(MODULE_TOPDIR)/include/Make/Doxygen.make10 10 11 11 default: cmd 12 12 13 #doxygen:14 DOXNAME = r.seg -
grass-addons/grass7/raster/r.segment/README
r43846 r58886 1 GRASS 6.4+: install with 2 g.extension r.seg 1 GRASS GIS module for image segmentation and edge detection 2 Alfonso Vitti <alfonso.vitti [at] ing.unitn.it> 3 see http://www.ing.unitn.it/~vittia/sw 3 4 4 --------------------- 5 Old method: 6 r.seg GRASS GIS module for image segmentation and edge detection 7 Alfonso Vitti <alfonso.vitti [at] ing.unitn.it> 8 see www.ing.unitn.it/~vittia/sw 5 GRASS 7: install with 6 g.extension r.segment 9 7 10 copy the "r.seg" directory in the "raster" directory of the GRASS source code directory11 12 from within the "r.seg" directory, as normal user run:13 make14 15 from the GRASS main source code directory, as root run:16 make install17 or, as normal user:18 sudo make install -
grass-addons/grass7/raster/r.segment/main.c
r43846 r58886 1 1 /**************************************************************************** 2 2 * 3 * MODULE: r.seg 3 * MODULE: r.segment (former name: r.seg) 4 4 * 5 5 * AUTHOR: Alfonso Vitti <alfonso.vitti ing.unitn.it> 6 6 * 7 * PURPOSE: generates a piece-wise smooth approximation of the input7 * PURPOSE: generates a piece-wise smooth approximation of the input 8 8 * raster map and a raster map of the discontinuities (edges) of 9 9 * the output approximation. The discontinuities of the output … … 12 12 * REFERENCE: http://www.ing.unitn.it/~vittia/phd/vitti_phd.pdf 13 13 * 14 * COPYRIGHT: (C) 2007-201 014 * COPYRIGHT: (C) 2007-2014 by Alfonso Vitti, and the GRASS Development Team 15 15 * 16 16 * This program is free software under the GNU General Public … … 24 24 #include <string.h> 25 25 #include <grass/gis.h> 26 #include <grass/raster.h> 26 27 #include <grass/config.h> 27 28 #include <grass/glocale.h> … … 42 43 int max_iter; /* max number of numerical iterations */ 43 44 int iter; /* iteration index */ 44 c har *mapset; /* current mapset */45 const char *mapset; /* current mapset */ 45 46 void *g_row; /* input row buffers */ 46 47 void *out_u_row, *out_z_row; /* output row buffer */ … … 66 67 67 68 68 /* initialize GRASS environment */ 69 G_gisinit(argv[0]); /*reads GRASS env */ 70 69 G_gisinit(argv[0]); 71 70 72 71 /* initialize module */ 73 72 module = G_define_module(); 74 module->keywords = _("image segmentation, edge detection, smooth"); 73 G_add_keyword(_("imagery")); 74 G_add_keyword(_("segmentation")); 75 G_add_keyword(_("edge detection")); 76 G_add_keyword(_("smoothing")); 75 77 module->description = 76 _("Generates a smooth approximation of the input raster and a discontinuity map ");77 78 parm.in_g = G_define_ option();78 _("Generates a smooth approximation of the input raster and a discontinuity map."); 79 80 parm.in_g = G_define_standard_option(G_OPT_R_INPUTS); 79 81 parm.in_g->key = "in_g"; 80 parm.in_g->type = TYPE_STRING;81 parm.in_g->required = YES;82 82 parm.in_g->description = _("Input raster map to segment"); 83 parm.in_g->gisprompt = "old,cell,raster"; 84 85 parm.out_u = G_define_option(); 83 84 parm.out_u = G_define_standard_option(G_OPT_R_OUTPUT); 86 85 parm.out_u->key = "out_u"; 87 parm.out_u->type = TYPE_STRING;88 parm.out_u->required = YES;89 86 parm.out_u->description = _("Output segmented raster map"); 90 parm.out_u->gisprompt = "new,cell,raster"; 91 92 parm.out_z = G_define_option(); 87 88 parm.out_z = G_define_standard_option(G_OPT_R_OUTPUT); 93 89 parm.out_z->key = "out_z"; 94 parm.out_z->type = TYPE_STRING;95 parm.out_z->required = YES;96 90 parm.out_z->description = 97 91 _("Output raster map with detected discontinuities"); 98 parm.out_z->gisprompt = "new,cell,raster";99 92 100 93 opts.lambda = G_define_option(); … … 104 97 opts.lambda->answer = "1.0"; 105 98 opts.lambda->description = _("Smoothness coefficient [>0]"); 99 opts.lambda->guisection = _("Settings"); 106 100 107 101 opts.alpha = G_define_option(); … … 111 105 opts.alpha->answer = "1.0"; 112 106 opts.alpha->description = _("Discontinuity coefficient [>0]"); 107 opts.alpha->guisection = _("Settings"); 113 108 114 109 opts.max_iter = G_define_option(); … … 119 114 opts.max_iter->description = 120 115 _("Maximal number of numerical iterations"); 116 opts.max_iter->guisection = _("Settings"); 121 117 122 118 opts.tol = G_define_option(); … … 126 122 opts.tol->answer = "0.001"; 127 123 opts.tol->description = _("Convergence tolerance [>0]"); 124 opts.tol->guisection = _("Settings"); 128 125 129 126 opts.kepsilon = G_define_option(); … … 134 131 opts.kepsilon->description = 135 132 _("Discontinuity thickness [>0]"); 133 opts.kepsilon->guisection = _("Settings"); 136 134 137 135 opts.beta = G_define_option(); … … 148 146 * have to be set independently from the values used in MS 149 147 */ 148 opts.beta->guisection = _("Settings"); 150 149 151 150 flag_k = G_define_flag(); 152 151 flag_k->key = 'k'; 153 152 flag_k->description = _("Activate MSK model (Mumford-Shah with curvature term)"); 154 153 flag_k->guisection = _("Settings"); 155 154 156 155 /* parameters and flags parser */ … … 171 170 172 171 if (((usek = (flag_k->answer) == 0) && (beta != 0.0))) 173 G_warning(_ 174 ("Beta is not zero and you have not activated the MSK formulation: \n \ 172 G_warning(_("Beta is not zero and you have not activated the MSK formulation: \n \ 175 173 beta will be ignored and MS (default) will be used.")); 176 174 177 175 if (((usek = (flag_k->answer) == 1) && (beta == 0.0))) 178 G_warning(_ 179 ("You have activated the MSK formulation, but beta is zero:\n \ 176 G_warning(_("You have activated the MSK formulation, but beta is zero:\n \ 180 177 beta should be greater than zero in MSK.")); 181 178 182 179 /* check existence and names of raster maps */ 183 mapset = G_find_cell2(in_g, ""); 184 if (!mapset) 185 G_fatal_error(_("raster file [%s] not found"), in_g); 180 mapset = G_find_raster2(in_g, ""); 181 if (mapset == NULL) 182 G_fatal_error(_("Raster map <%s> not found"), in_g); 183 184 /* still needed in GRASS 7? 186 185 if (G_legal_filename(out_u) < 0) 187 186 G_fatal_error(_("[%s] is an illegal file name"), out_u); … … 192 191 if (strcmp(out_u, out_z) == 0) 193 192 G_fatal_error(_("Output raster maps have the same name [%s]"), out_u); 193 */ 194 194 195 195 … … 203 203 204 204 /* get the window dimention */ 205 nr = G_window_rows();206 nc = G_window_cols();205 nr = Rast_window_rows(); 206 nc = Rast_window_cols(); 207 207 nrc = nr * nc; 208 208 … … 217 217 218 218 /* open the input raster map for reading */ 219 if ((g_fd = G_open_cell_old(in_g, mapset)) < 0) 220 G_fatal_error(_("cannot open raster file [%s]"), in_g); 221 if (G_get_cellhd(in_g, mapset, &cellhd) < 0) 222 G_fatal_error(_("cannot read [%s] header"), in_g); 223 219 g_fd = Rast_open_old(in_g, mapset); 220 221 Rast_get_cellhd(in_g, mapset, &cellhd); 224 222 225 223 /* allocate the buffer for storing the values of the input raster map */ 226 g_row = G_allocate_raster_buf(dcell_data_type);224 g_row = Rast_allocate_buf(dcell_data_type); 227 225 228 226 … … 231 229 jnc = j * nc; 232 230 233 if (G_get_raster_row(g_fd, g_row, j, dcell_data_type) < 0) 234 G_fatal_error(_("Cannot read from [%s] raster,"), in_g); 231 Rast_get_row(g_fd, g_row, j, dcell_data_type); 235 232 236 233 for (i = 0; i < nc; i++) { … … 243 240 244 241 /* close the input raster map and free memory */ 245 G_close_cell(g_fd);242 Rast_close(g_fd); 246 243 G_free(g_row); 247 244 … … 273 270 274 271 /* print the total number of iteration performed */ 275 G_message("\nr.seg iterations: %i\n", iter); 276 G_message("\n"); 272 G_message("Total number of iterations: %i", iter); 277 273 278 274 /* open the output raster maps for writing */ 279 if ((out_u_fd = G_open_raster_new(out_u, dcell_data_type)) < 0) 280 G_fatal_error(_("cannot open raster file [%s]"), out_u); 281 if ((out_z_fd = G_open_raster_new(out_z, dcell_data_type)) < 0) 282 G_fatal_error(_("cannot open raster file [%s]"), out_z); 275 out_u_fd = Rast_open_new(out_u, dcell_data_type); 276 out_z_fd = Rast_open_new(out_z, dcell_data_type); 283 277 284 278 285 279 /* allocate the buffer for storing the values of the output raster maps */ 286 out_u_row = G_allocate_raster_buf(dcell_data_type);287 out_z_row = G_allocate_raster_buf(dcell_data_type);280 out_u_row = Rast_allocate_buf(dcell_data_type); 281 out_z_row = Rast_allocate_buf(dcell_data_type); 288 282 289 283 … … 295 289 ((DCELL *) out_z_row)[i] = *(z + jnc + i); 296 290 } 297 if (G_put_raster_row(out_u_fd, out_u_row, dcell_data_type) < 0) 298 G_fatal_error(_("cannot write [%s] raster"), out_u); 299 if (G_put_raster_row(out_z_fd, out_z_row, dcell_data_type) < 0) 300 G_fatal_error(_("cannot write [%s] raster"), out_z); 291 Rast_put_row(out_u_fd, out_u_row, dcell_data_type); 292 Rast_put_row(out_z_fd, out_z_row, dcell_data_type); 301 293 } 302 294 303 295 304 296 /* close the input raster map and free memory */ 305 G_close_cell(out_u_fd);297 Rast_close(out_u_fd); 306 298 G_free(out_u_row); 307 G_close_cell(out_z_fd);299 Rast_close(out_z_fd); 308 300 G_free(out_z_row); 309 301 G_free(g); … … 311 303 G_free(z); 312 304 313 314 /* write history file */ 315 G_short_history(out_u, "raster", &history); 316 G_command_history(&history); 317 sprintf(history.edhist[3], "iterations = %i", iter); 318 history.edlinecnt = 4; 319 G_write_history(out_u, &history); 320 G_write_history(out_z, &history); 321 305 /* write map history (meta data) */ 306 Rast_short_history(out_u, "raster", &history); 307 Rast_set_history(&history, HIST_DATSRC_1, in_g); 308 Rast_append_format_history(&history, "iterations = %i", iter); 309 Rast_command_history(&history); 310 Rast_write_history(out_u, &history); 311 Rast_write_history(out_z, &history); 322 312 323 313 /* exit */ -
grass-addons/grass7/raster/r.segment/r.segment.html
r58885 r58886 1 1 <h2>DESCRIPTION</h2> 2 2 3 <em><b>r.seg </b></em> generates a piece-wise smooth approximation of the3 <em><b>r.segment</b></em> generates a piece-wise smooth approximation of the 4 4 input raster map and a raster map of the discontinuities of the output 5 5 approximation. <br> … … 26 26 Remove any MASK before the execution of the module. If 27 27 a MASK is present, the module stops after just one iteration. 28 < br><br>28 <p> 29 29 30 30 Replace (<em>r.null</em>) any null data with the map average value (get with <em>r.univar</em>). 31 < br><br>31 <p> 32 32 33 33 The segmentation depends on the parameters alpha and lambda: … … 62 62 values of the parameter lambda. The larger the total number of pixels 63 63 of the input raster map the larger the number of iterations will be. 64 < br><br>64 <p> 65 65 66 The data type of the output raster maps is DOUBLE PRECISION. <br><br>66 The data type of the output raster maps is DOUBLE PRECISION.<p> 67 67 68 68 The module works on one raster map at a time, imagery groups are not 69 supported. <br><br>69 supported.<p> 70 70 71 71 To avoid to inappropriately re-sampled the input raster map, the settings … … 79 79 80 80 The discontinuity thickness should be changed for test purposes only. 81 < br><br>81 <p> 82 82 83 83 The actual need to use the MSK model should be very rare, see [3]. … … 95 95 <div><pre class="code"> 96 96 # set the region to match the <em>ortho_2001_t792_1m</em> raster map: 97 g.region rast=ortho_2001_t792_1m 97 g.region rast=ortho_2001_t792_1m -p 98 98 99 99 # select a smaller region: 100 g.region n=221725 s=220225 w=638350 e=639550 100 g.region n=221725 s=220225 w=638350 e=639550 -p 101 101 102 # run r.seg :103 r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u_OF out_z=z_OF lambda=10 alpha=200 mxi=250102 # run r.segment: 103 r.segment in_g=ortho_2001_t792_1m@PERMANENT out_u=u_OF out_z=z_OF lambda=10 alpha=200 mxi=250 104 104 105 105 # for a better visualization of the output raster map <em>u_OF</em>, set its color table to: … … 118 118 r.colors z_OF color=bgyr 119 119 120 # run r.seg with different parameter values:121 r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u1_OF out_z=z1_OF lambda=10 alpha=65 mxi=250122 r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u2_OF out_z=z2_OF lambda=10 alpha=600 mxi=250123 r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u3_OF out_z=z3_OF lambda=0.1 alpha=200 mxi=250124 r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u4_OF out_z=z4_OF lambda=1 alpha=200 mxi=250120 # run r.segment with different parameter values: 121 r.segment in_g=ortho_2001_t792_1m@PERMANENT out_u=u1_OF out_z=z1_OF lambda=10 alpha=65 mxi=250 122 r.segment in_g=ortho_2001_t792_1m@PERMANENT out_u=u2_OF out_z=z2_OF lambda=10 alpha=600 mxi=250 123 r.segment in_g=ortho_2001_t792_1m@PERMANENT out_u=u3_OF out_z=z3_OF lambda=0.1 alpha=200 mxi=250 124 r.segment in_g=ortho_2001_t792_1m@PERMANENT out_u=u4_OF out_z=z4_OF lambda=1 alpha=200 mxi=250 125 125 126 126 # visualize and compare the different results
Note:
See TracChangeset
for help on using the changeset viewer.
