[GRASS-SVN] r58886 - in grass-addons/grass7/raster: . r.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Feb 5 08:36:23 PST 2014
Author: neteler
Date: 2014-02-05 08:36:23 -0800 (Wed, 05 Feb 2014)
New Revision: 58886
Added:
grass-addons/grass7/raster/r.segment/
grass-addons/grass7/raster/r.segment/r.segment.html
Removed:
grass-addons/grass7/raster/r.segment/description.html
Modified:
grass-addons/grass7/raster/Makefile
grass-addons/grass7/raster/r.segment/Makefile
grass-addons/grass7/raster/r.segment/README
grass-addons/grass7/raster/r.segment/main.c
Log:
r.segment: ported r.seg GRASS 6 Addon to GRASS 7
Modified: grass-addons/grass7/raster/Makefile
===================================================================
--- grass-addons/grass7/raster/Makefile 2014-02-05 09:51:02 UTC (rev 58885)
+++ grass-addons/grass7/raster/Makefile 2014-02-05 16:36:23 UTC (rev 58886)
@@ -18,6 +18,7 @@
r.mcda.roughset \
r.modis \
r.regression.series \
+ r.segment \
r.stream.basins \
r.stream.channel \
r.stream.distance \
Modified: grass-addons/grass7/raster/r.segment/Makefile
===================================================================
--- grass-addons/grass6/raster/r.seg/Makefile 2014-02-05 09:51:02 UTC (rev 58885)
+++ grass-addons/grass7/raster/r.segment/Makefile 2014-02-05 16:36:23 UTC (rev 58886)
@@ -1,14 +1,12 @@
MODULE_TOPDIR = ../..
-PGM = r.seg
+PGM = r.segment
-LIBES = $(SEGLIB) $(GISLIB)
-DEPENDENCIES = $(SEGDEP) $(GISDEP)
+LIBES = $(GISLIB) $(RASTERLIB) $(SEGMENTLIB)
+DEPENDENCIES = $(GISDEP) $(RASTERDEP) $(SEGMENTDEP)
+
include $(MODULE_TOPDIR)/include/Make/Module.make
-include $(MODULE_TOPDIR)/include/Make/Doxygen.make
default: cmd
-#doxygen:
-DOXNAME = r.seg
Modified: grass-addons/grass7/raster/r.segment/README
===================================================================
--- grass-addons/grass6/raster/r.seg/README 2014-02-05 09:51:02 UTC (rev 58885)
+++ grass-addons/grass7/raster/r.segment/README 2014-02-05 16:36:23 UTC (rev 58886)
@@ -1,18 +1,7 @@
-GRASS 6.4+: install with
- g.extension r.seg
-
----------------------
-Old method:
-r.seg GRASS GIS module for image segmentation and edge detection
+GRASS GIS module for image segmentation and edge detection
Alfonso Vitti <alfonso.vitti [at] ing.unitn.it>
- see www.ing.unitn.it/~vittia/sw
+ see http://www.ing.unitn.it/~vittia/sw
-copy the "r.seg" directory in the "raster" directory of the GRASS source code directory
+GRASS 7: install with
+ g.extension r.segment
-from within the "r.seg" directory, as normal user run:
-make
-
-from the GRASS main source code directory, as root run:
-make install
-or, as normal user:
-sudo make install
Deleted: grass-addons/grass7/raster/r.segment/description.html
===================================================================
--- grass-addons/grass6/raster/r.seg/description.html 2014-02-05 09:51:02 UTC (rev 58885)
+++ grass-addons/grass7/raster/r.segment/description.html 2014-02-05 16:36:23 UTC (rev 58886)
@@ -1,161 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em><b>r.seg</b></em> generates a piece-wise smooth approximation of the
-input raster map and a raster map of the discontinuities of the output
-approximation. <br>
-
-The discontinuities of the output approximation are preserved from being
-smoothed. The values of the discontinuity map are close to one where the
-output approximation is "homogeneous", where the output approximation
-has discontinuities (edges) the values are close to zero. <br>
-
-The module makes use of the <em>varseg</em> library which implements
-the Mumford-Shah [1] variational model for image segmentation. The
-Mumford-Shah variational model with curvature term [2] is also implemented
-in the library. The curvature term prevents the discontinuities from being
-shortened too much when the parameter alpha is set to very high values,
-(this happens very rarely). <br>
-
-Some examples of use of the module can be found <a
-href="http://www.ing.unitn.it/~vittia/sw/sw_index.html">here</a> and in <a
-href="http://download.OSGeo.org/OSGeo/foss4g/2009/SPREP/2Thu/Parkside%20GO4/1500/Thu
-G04 1545 Zatelli.pdf">this presentation [FOSS4G 2009 - pdf]</a>. <br>
-For details on the numerical implementation see [3].
-
-<h2>NOTES</h2>
-Remove any MASK before the execution of the module. If
-a MASK is present, the module stops after just one iteration.
-<br><br>
-
-Replace (<em>r.null</em>) any null data with the map average value (get with <em>r.univar</em>).
-<br><br>
-
-The segmentation depends on the parameters alpha and lambda:
-<ul>
-<li> alpha controls how many discontinuities are allowed to exist.
-<li> lambda controls the smoothness of the solution.
-<li> It is not possible to select the values of the parameters in an
- automatic way. Test some different values to understand their
- influence on the results. Try the following procedure:
-<ul>
- <li> run the module with both alpha and lambda set to 1.0
- <li> run the module with alpha set to 1.0 and different values for lambda
- <br> e.g., 0.01, 0.1, 1, 10, 100
- <li> run the module with lambda set to 1.0 and different values for alpha
- <br> e.g., let's say 0.01, 0.1, 1, 10, 100
- <li> see how the segmentations change and select the values that
- produce the result that best fits your requirements.
-</ul>
-</ul>
-
-The module computes the segmentation by means of an iterative
-procedure.<br>
-The module stops either when the number of iterations
-reaches the maximum number of iterations [mxi] or when the maximum
-difference between the solutions of two successive iterations is less than
-the convergence tolerance [tol].<br>
-To stop the iteration procedure,
-it is easier to act on the maximum number of iterations parameter [mxi]
-than on the convergence tolerance parameter [tol].<br>
-The number of
-iterations needed to reach the convergence tolerance increases for high
-values of the parameter lambda. The larger the total number of pixels
-of the input raster map the larger the number of iterations will be.
-<br><br>
-
-The data type of the output raster maps is DOUBLE PRECISION. <br><br>
-
-The module works on one raster map at a time, imagery groups are not
-supported. <br><br>
-
-To avoid to inappropriately re-sampled the input raster map, the settings
-for the current region should be set so that:
-<ul>
-<li> the resolution of the region matches the resolution of the
- input raster map;
-<li>the boundaries of the region are lined up along the edges of the nearest
-cells in the input raster map.
-</ul>
-
-The discontinuity thickness should be changed for test purposes only.
-<br><br>
-
-The actual need to use the MSK model should be very rare, see [3].
-Due to a different implementation of the MSK model with respect to MS
-one, the values of the parameters lambda and alpha in MSK have to be
-set independently from the values used in MS.
-
-<h2>EXAMPLE</h2>
-
-This example is based the <a
-href="http://grass.OSGeo.org/download/data.php">North Carolina GRASS sample
-data set</a>, [complete GRASS location].
-
-
-<div><pre class="code">
-# set the region to match the <em>ortho_2001_t792_1m</em> raster map:
-g.region rast=ortho_2001_t792_1m
-
-# select a smaller region:
-g.region n=221725 s=220225 w=638350 e=639550
-
-# run r.seg:
-r.seg in_g=ortho_2001_t792_1m at PERMANENT out_u=u_OF out_z=z_OF lambda=10 alpha=200 mxi=250
-
-# for a better visualization of the output raster map <em>u_OF</em>, set its color table to:
-r.colors u_OF rast=ortho_2001_t792_1m
-
-# compute the difference between the input raster map and the output raster map <em>u_OF</em>:
-r.mapcalc "diff = abs(ortho_2001_t792_1m at PERMANENT - u_OF)"
-
-# for a better visualization of the differences, compute the natural logarithm of the <em>diff</em> map:
-r.mapcalc "log_diff = log(1 + diff)"
-
-# and set its color table to the "differences" style:
-r.colors log_diff color=differences
-
-# for a better visualization of the output raster map <em>u_OF</em>, set its color table to:
-r.colors z_OF color=bgyr
-
-# run r.seg with different parameter values:
-r.seg in_g=ortho_2001_t792_1m at PERMANENT out_u=u1_OF out_z=z1_OF lambda=10 alpha=65 mxi=250
-r.seg in_g=ortho_2001_t792_1m at PERMANENT out_u=u2_OF out_z=z2_OF lambda=10 alpha=600 mxi=250
-r.seg in_g=ortho_2001_t792_1m at PERMANENT out_u=u3_OF out_z=z3_OF lambda=0.1 alpha=200 mxi=250
-r.seg in_g=ortho_2001_t792_1m at PERMANENT out_u=u4_OF out_z=z4_OF lambda=1 alpha=200 mxi=250
-
-# visualize and compare the different results
-</pre></div>
-
-<h2>REFERENCE</h2>
-
-<ul> <li> <b>[1]</b> D. Mumford and J. Shah. <em>Optimal Approximation by
-Piecewise Smooth Functions and Associated Variational Problems</em>. <br>
-Communications on Pure Applied Mathematics, 42:577-685, 1989.
-
-<li> <b>[2]</b> R. March and M. Dozio. <em>A variational method for the
-recovery of smooth boundaries</em>. <br> Image and Vision Computing,
-15:705-712, 1997.
-
-<li> <b>[3]</b> A. Vitti. <em>Free discontinuity
-problems in image and signal segmentatiion</em>. <br>
-Ph.D. Thesis - University of Trento (Italy), 2008. <br> <a
-href="http://www.ing.unitn.it/~vittia/misc/vitti_phd.pdf">http://www.ing.unitn.it/~vittia/misc/vitti_phd.pdf</a>
-</ul>
-
-
-<h2>SEE ALSO</h2>
-
-<em><a href="i.smap.html">i.smap</a></em>,
-<em><a href="i.zc.html">i.zc</a></em>,
-<em><a href="r.mfilter.html">r.mfilter</a></em>
-
-
-<h2>AUTHOR</h2>
-
-Alfonso Vitti <br>
- Dept. Civil and
-Environmental Engineering <br>
- University of Trento - Italy<br>
- alfonso.vitti [at] ing.unitn.it
-
-<p><i>Last changed: $Date: 2010-08-10 12:00:00 +0200 (Tue, 10 Aug 2010)$</i>
Modified: grass-addons/grass7/raster/r.segment/main.c
===================================================================
--- grass-addons/grass6/raster/r.seg/main.c 2014-02-05 09:51:02 UTC (rev 58885)
+++ grass-addons/grass7/raster/r.segment/main.c 2014-02-05 16:36:23 UTC (rev 58886)
@@ -1,17 +1,17 @@
/****************************************************************************
*
- * MODULE: r.seg
+ * MODULE: r.segment (former name: r.seg)
*
* AUTHOR: Alfonso Vitti <alfonso.vitti ing.unitn.it>
*
- * PURPOSE: generates a piece-wise smooth approximation of the input
+ * PURPOSE: generates a piece-wise smooth approximation of the input
* raster map and a raster map of the discontinuities (edges) of
* the output approximation. The discontinuities of the output
* approximation are preserved from being smoothed.
*
* REFERENCE: http://www.ing.unitn.it/~vittia/phd/vitti_phd.pdf
*
- * COPYRIGHT: (C) 2007-2010
+ * COPYRIGHT: (C) 2007-2014 by Alfonso Vitti, and the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
+#include <grass/raster.h>
#include <grass/config.h>
#include <grass/glocale.h>
#include "varseg.h"
@@ -41,7 +42,7 @@
double *mxdf; /* maximum difference betweed two iteration steps */
int max_iter; /* max number of numerical iterations */
int iter; /* iteration index */
- char *mapset; /* current mapset */
+ const char *mapset; /* current mapset */
void *g_row; /* input row buffers */
void *out_u_row, *out_z_row; /* output row buffer */
int nr, nc, nrc; /* number of rows and colums */
@@ -65,37 +66,29 @@
struct Flag *flag_k; /* flag, k = use MSK instead of MS */
- /* initialize GRASS environment */
- G_gisinit(argv[0]); /*reads GRASS env */
+ G_gisinit(argv[0]);
-
/* initialize module */
module = G_define_module();
- module->keywords = _("image segmentation, edge detection, smooth");
+ G_add_keyword(_("imagery"));
+ G_add_keyword(_("segmentation"));
+ G_add_keyword(_("edge detection"));
+ G_add_keyword(_("smoothing"));
module->description =
- _("Generates a smooth approximation of the input raster and a discontinuity map");
+ _("Generates a smooth approximation of the input raster and a discontinuity map.");
- parm.in_g = G_define_option();
+ parm.in_g = G_define_standard_option(G_OPT_R_INPUTS);
parm.in_g->key = "in_g";
- parm.in_g->type = TYPE_STRING;
- parm.in_g->required = YES;
parm.in_g->description = _("Input raster map to segment");
- parm.in_g->gisprompt = "old,cell,raster";
- parm.out_u = G_define_option();
+ parm.out_u = G_define_standard_option(G_OPT_R_OUTPUT);
parm.out_u->key = "out_u";
- parm.out_u->type = TYPE_STRING;
- parm.out_u->required = YES;
parm.out_u->description = _("Output segmented raster map");
- parm.out_u->gisprompt = "new,cell,raster";
- parm.out_z = G_define_option();
+ parm.out_z = G_define_standard_option(G_OPT_R_OUTPUT);
parm.out_z->key = "out_z";
- parm.out_z->type = TYPE_STRING;
- parm.out_z->required = YES;
parm.out_z->description =
_("Output raster map with detected discontinuities");
- parm.out_z->gisprompt = "new,cell,raster";
opts.lambda = G_define_option();
opts.lambda->key = "lambda";
@@ -103,6 +96,7 @@
opts.lambda->required = NO;
opts.lambda->answer = "1.0";
opts.lambda->description = _("Smoothness coefficient [>0]");
+ opts.lambda->guisection = _("Settings");
opts.alpha = G_define_option();
opts.alpha->key = "alpha";
@@ -110,6 +104,7 @@
opts.alpha->required = NO;
opts.alpha->answer = "1.0";
opts.alpha->description = _("Discontinuity coefficient [>0]");
+ opts.alpha->guisection = _("Settings");
opts.max_iter = G_define_option();
opts.max_iter->key = "mxi";
@@ -118,6 +113,7 @@
opts.max_iter->answer = "100";
opts.max_iter->description =
_("Maximal number of numerical iterations");
+ opts.max_iter->guisection = _("Settings");
opts.tol = G_define_option();
opts.tol->key = "tol";
@@ -125,6 +121,7 @@
opts.tol->required = NO;
opts.tol->answer = "0.001";
opts.tol->description = _("Convergence tolerance [>0]");
+ opts.tol->guisection = _("Settings");
opts.kepsilon = G_define_option();
opts.kepsilon->key = "kepsilon";
@@ -133,6 +130,7 @@
opts.kepsilon->answer = "1.0";
opts.kepsilon->description =
_("Discontinuity thickness [>0]");
+ opts.kepsilon->guisection = _("Settings");
opts.beta = G_define_option();
opts.beta->key = "beta";
@@ -147,12 +145,13 @@
* the values of the parameters lambda and alpha in MSK
* have to be set independently from the values used in MS
*/
+ opts.beta->guisection = _("Settings");
flag_k = G_define_flag();
flag_k->key = 'k';
flag_k->description = _("Activate MSK model (Mumford-Shah with curvature term)");
+ flag_k->guisection = _("Settings");
-
/* parameters and flags parser */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
@@ -170,19 +169,19 @@
max_iter = atoi(opts.max_iter->answer);
if (((usek = (flag_k->answer) == 0) && (beta != 0.0)))
- G_warning(_
- ("Beta is not zero and you have not activated the MSK formulation: \n \
+ G_warning(_("Beta is not zero and you have not activated the MSK formulation: \n \
beta will be ignored and MS (default) will be used."));
if (((usek = (flag_k->answer) == 1) && (beta == 0.0)))
- G_warning(_
- ("You have activated the MSK formulation, but beta is zero:\n \
+ G_warning(_("You have activated the MSK formulation, but beta is zero:\n \
beta should be greater than zero in MSK."));
/* check existence and names of raster maps */
- mapset = G_find_cell2(in_g, "");
- if (!mapset)
- G_fatal_error(_("raster file [%s] not found"), in_g);
+ mapset = G_find_raster2(in_g, "");
+ if (mapset == NULL)
+ G_fatal_error(_("Raster map <%s> not found"), in_g);
+
+/* still needed in GRASS 7?
if (G_legal_filename(out_u) < 0)
G_fatal_error(_("[%s] is an illegal file name"), out_u);
G_check_input_output_name(in_g, out_u, GR_FATAL_EXIT);
@@ -191,6 +190,7 @@
G_check_input_output_name(in_g, out_z, GR_FATAL_EXIT);
if (strcmp(out_u, out_z) == 0)
G_fatal_error(_("Output raster maps have the same name [%s]"), out_u);
+*/
/* -------------------------------------------------------------------- */
@@ -202,8 +202,8 @@
/* get the window dimention */
- nr = G_window_rows();
- nc = G_window_cols();
+ nr = Rast_window_rows();
+ nc = Rast_window_cols();
nrc = nr * nc;
@@ -216,22 +216,19 @@
/* open the input raster map for reading */
- if ((g_fd = G_open_cell_old(in_g, mapset)) < 0)
- G_fatal_error(_("cannot open raster file [%s]"), in_g);
- if (G_get_cellhd(in_g, mapset, &cellhd) < 0)
- G_fatal_error(_("cannot read [%s] header"), in_g);
+ g_fd = Rast_open_old(in_g, mapset);
+ Rast_get_cellhd(in_g, mapset, &cellhd);
/* allocate the buffer for storing the values of the input raster map */
- g_row = G_allocate_raster_buf(dcell_data_type);
+ g_row = Rast_allocate_buf(dcell_data_type);
/* read the input raster map + fill up the variable pointers with pixel values */
for (j = 0; j < nr; j++) {
jnc = j * nc;
- if (G_get_raster_row(g_fd, g_row, j, dcell_data_type) < 0)
- G_fatal_error(_("Cannot read from [%s] raster,"), in_g);
+ Rast_get_row(g_fd, g_row, j, dcell_data_type);
for (i = 0; i < nc; i++) {
*(g + jnc + i) = ((DCELL *) g_row)[i];
@@ -242,7 +239,7 @@
/* close the input raster map and free memory */
- G_close_cell(g_fd);
+ Rast_close(g_fd);
G_free(g_row);
@@ -272,19 +269,16 @@
/* print the total number of iteration performed */
- G_message("\nr.seg iterations: %i\n", iter);
- G_message("\n");
+ G_message("Total number of iterations: %i", iter);
/* open the output raster maps for writing */
- if ((out_u_fd = G_open_raster_new(out_u, dcell_data_type)) < 0)
- G_fatal_error(_("cannot open raster file [%s]"), out_u);
- if ((out_z_fd = G_open_raster_new(out_z, dcell_data_type)) < 0)
- G_fatal_error(_("cannot open raster file [%s]"), out_z);
+ out_u_fd = Rast_open_new(out_u, dcell_data_type);
+ out_z_fd = Rast_open_new(out_z, dcell_data_type);
/* allocate the buffer for storing the values of the output raster maps */
- out_u_row = G_allocate_raster_buf(dcell_data_type);
- out_z_row = G_allocate_raster_buf(dcell_data_type);
+ out_u_row = Rast_allocate_buf(dcell_data_type);
+ out_z_row = Rast_allocate_buf(dcell_data_type);
/* fill up the output buffers with result values + write the output raster maps */
@@ -294,32 +288,28 @@
((DCELL *) out_u_row)[i] = *(u + jnc + i);
((DCELL *) out_z_row)[i] = *(z + jnc + i);
}
- if (G_put_raster_row(out_u_fd, out_u_row, dcell_data_type) < 0)
- G_fatal_error(_("cannot write [%s] raster"), out_u);
- if (G_put_raster_row(out_z_fd, out_z_row, dcell_data_type) < 0)
- G_fatal_error(_("cannot write [%s] raster"), out_z);
+ Rast_put_row(out_u_fd, out_u_row, dcell_data_type);
+ Rast_put_row(out_z_fd, out_z_row, dcell_data_type);
}
/* close the input raster map and free memory */
- G_close_cell(out_u_fd);
+ Rast_close(out_u_fd);
G_free(out_u_row);
- G_close_cell(out_z_fd);
+ Rast_close(out_z_fd);
G_free(out_z_row);
G_free(g);
G_free(u);
G_free(z);
+ /* write map history (meta data) */
+ Rast_short_history(out_u, "raster", &history);
+ Rast_set_history(&history, HIST_DATSRC_1, in_g);
+ Rast_append_format_history(&history, "iterations = %i", iter);
+ Rast_command_history(&history);
+ Rast_write_history(out_u, &history);
+ Rast_write_history(out_z, &history);
- /* write history file */
- G_short_history(out_u, "raster", &history);
- G_command_history(&history);
- sprintf(history.edhist[3], "iterations = %i", iter);
- history.edlinecnt = 4;
- G_write_history(out_u, &history);
- G_write_history(out_z, &history);
-
-
/* exit */
exit(EXIT_SUCCESS);
}
Copied: grass-addons/grass7/raster/r.segment/r.segment.html (from rev 58885, grass-addons/grass6/raster/r.seg/description.html)
===================================================================
--- grass-addons/grass7/raster/r.segment/r.segment.html (rev 0)
+++ grass-addons/grass7/raster/r.segment/r.segment.html 2014-02-05 16:36:23 UTC (rev 58886)
@@ -0,0 +1,161 @@
+<h2>DESCRIPTION</h2>
+
+<em><b>r.segment</b></em> generates a piece-wise smooth approximation of the
+input raster map and a raster map of the discontinuities of the output
+approximation. <br>
+
+The discontinuities of the output approximation are preserved from being
+smoothed. The values of the discontinuity map are close to one where the
+output approximation is "homogeneous", where the output approximation
+has discontinuities (edges) the values are close to zero. <br>
+
+The module makes use of the <em>varseg</em> library which implements
+the Mumford-Shah [1] variational model for image segmentation. The
+Mumford-Shah variational model with curvature term [2] is also implemented
+in the library. The curvature term prevents the discontinuities from being
+shortened too much when the parameter alpha is set to very high values,
+(this happens very rarely). <br>
+
+Some examples of use of the module can be found <a
+href="http://www.ing.unitn.it/~vittia/sw/sw_index.html">here</a> and in <a
+href="http://download.OSGeo.org/OSGeo/foss4g/2009/SPREP/2Thu/Parkside%20GO4/1500/Thu
+G04 1545 Zatelli.pdf">this presentation [FOSS4G 2009 - pdf]</a>. <br>
+For details on the numerical implementation see [3].
+
+<h2>NOTES</h2>
+Remove any MASK before the execution of the module. If
+a MASK is present, the module stops after just one iteration.
+<p>
+
+Replace (<em>r.null</em>) any null data with the map average value (get with <em>r.univar</em>).
+<p>
+
+The segmentation depends on the parameters alpha and lambda:
+<ul>
+<li> alpha controls how many discontinuities are allowed to exist.
+<li> lambda controls the smoothness of the solution.
+<li> It is not possible to select the values of the parameters in an
+ automatic way. Test some different values to understand their
+ influence on the results. Try the following procedure:
+<ul>
+ <li> run the module with both alpha and lambda set to 1.0
+ <li> run the module with alpha set to 1.0 and different values for lambda
+ <br> e.g., 0.01, 0.1, 1, 10, 100
+ <li> run the module with lambda set to 1.0 and different values for alpha
+ <br> e.g., let's say 0.01, 0.1, 1, 10, 100
+ <li> see how the segmentations change and select the values that
+ produce the result that best fits your requirements.
+</ul>
+</ul>
+
+The module computes the segmentation by means of an iterative
+procedure.<br>
+The module stops either when the number of iterations
+reaches the maximum number of iterations [mxi] or when the maximum
+difference between the solutions of two successive iterations is less than
+the convergence tolerance [tol].<br>
+To stop the iteration procedure,
+it is easier to act on the maximum number of iterations parameter [mxi]
+than on the convergence tolerance parameter [tol].<br>
+The number of
+iterations needed to reach the convergence tolerance increases for high
+values of the parameter lambda. The larger the total number of pixels
+of the input raster map the larger the number of iterations will be.
+<p>
+
+The data type of the output raster maps is DOUBLE PRECISION.<p>
+
+The module works on one raster map at a time, imagery groups are not
+supported.<p>
+
+To avoid to inappropriately re-sampled the input raster map, the settings
+for the current region should be set so that:
+<ul>
+<li> the resolution of the region matches the resolution of the
+ input raster map;
+<li>the boundaries of the region are lined up along the edges of the nearest
+cells in the input raster map.
+</ul>
+
+The discontinuity thickness should be changed for test purposes only.
+<p>
+
+The actual need to use the MSK model should be very rare, see [3].
+Due to a different implementation of the MSK model with respect to MS
+one, the values of the parameters lambda and alpha in MSK have to be
+set independently from the values used in MS.
+
+<h2>EXAMPLE</h2>
+
+This example is based the <a
+href="http://grass.OSGeo.org/download/data.php">North Carolina GRASS sample
+data set</a>, [complete GRASS location].
+
+
+<div><pre class="code">
+# set the region to match the <em>ortho_2001_t792_1m</em> raster map:
+g.region rast=ortho_2001_t792_1m -p
+
+# select a smaller region:
+g.region n=221725 s=220225 w=638350 e=639550 -p
+
+# run r.segment:
+r.segment in_g=ortho_2001_t792_1m at PERMANENT out_u=u_OF out_z=z_OF lambda=10 alpha=200 mxi=250
+
+# for a better visualization of the output raster map <em>u_OF</em>, set its color table to:
+r.colors u_OF rast=ortho_2001_t792_1m
+
+# compute the difference between the input raster map and the output raster map <em>u_OF</em>:
+r.mapcalc "diff = abs(ortho_2001_t792_1m at PERMANENT - u_OF)"
+
+# for a better visualization of the differences, compute the natural logarithm of the <em>diff</em> map:
+r.mapcalc "log_diff = log(1 + diff)"
+
+# and set its color table to the "differences" style:
+r.colors log_diff color=differences
+
+# for a better visualization of the output raster map <em>u_OF</em>, set its color table to:
+r.colors z_OF color=bgyr
+
+# run r.segment with different parameter values:
+r.segment in_g=ortho_2001_t792_1m at PERMANENT out_u=u1_OF out_z=z1_OF lambda=10 alpha=65 mxi=250
+r.segment in_g=ortho_2001_t792_1m at PERMANENT out_u=u2_OF out_z=z2_OF lambda=10 alpha=600 mxi=250
+r.segment in_g=ortho_2001_t792_1m at PERMANENT out_u=u3_OF out_z=z3_OF lambda=0.1 alpha=200 mxi=250
+r.segment in_g=ortho_2001_t792_1m at PERMANENT out_u=u4_OF out_z=z4_OF lambda=1 alpha=200 mxi=250
+
+# visualize and compare the different results
+</pre></div>
+
+<h2>REFERENCE</h2>
+
+<ul> <li> <b>[1]</b> D. Mumford and J. Shah. <em>Optimal Approximation by
+Piecewise Smooth Functions and Associated Variational Problems</em>. <br>
+Communications on Pure Applied Mathematics, 42:577-685, 1989.
+
+<li> <b>[2]</b> R. March and M. Dozio. <em>A variational method for the
+recovery of smooth boundaries</em>. <br> Image and Vision Computing,
+15:705-712, 1997.
+
+<li> <b>[3]</b> A. Vitti. <em>Free discontinuity
+problems in image and signal segmentatiion</em>. <br>
+Ph.D. Thesis - University of Trento (Italy), 2008. <br> <a
+href="http://www.ing.unitn.it/~vittia/misc/vitti_phd.pdf">http://www.ing.unitn.it/~vittia/misc/vitti_phd.pdf</a>
+</ul>
+
+
+<h2>SEE ALSO</h2>
+
+<em><a href="i.smap.html">i.smap</a></em>,
+<em><a href="i.zc.html">i.zc</a></em>,
+<em><a href="r.mfilter.html">r.mfilter</a></em>
+
+
+<h2>AUTHOR</h2>
+
+Alfonso Vitti <br>
+ Dept. Civil and
+Environmental Engineering <br>
+ University of Trento - Italy<br>
+ alfonso.vitti [at] ing.unitn.it
+
+<p><i>Last changed: $Date: 2010-08-10 12:00:00 +0200 (Tue, 10 Aug 2010)$</i>
More information about the grass-commit
mailing list