GRASS logo

NAME

r.seg - Generates a smooth approximation of the input raster and a discontinuity map

KEYWORDS

image segmentation, edge detection, smooth

SYNOPSIS

r.seg
r.seg help
r.seg [-k] in_g=string out_u=string out_z=string [lambda=float] [alpha=float] [mxi=integer] [tol=float] [kepsilon=float] [beta=float] [--overwrite] [--verbose] [--quiet]

Flags:

-k
Activate MSK model (Mumford-Shah with curvature term)
--overwrite
Allow output files to overwrite existing files
--verbose
Verbose module output
--quiet
Quiet module output

Parameters:

in_g=string
Input raster map to segment
out_u=string
Output segmented raster map
out_z=string
Output raster map with detected discontinuities
lambda=float
Smoothness coefficient [>0]
Default: 1.0
alpha=float
Discontinuity coefficient [>0]
Default: 1.0
mxi=integer
Maximal number of numerical iterations
Default: 100
tol=float
Convergence tolerance [>0]
Default: 0.001
kepsilon=float
Discontinuity thickness [>0]
Default: 1.0
beta=float
Curvature coefficient [>=0]
Default: 0.0

DESCRIPTION

r.seg generates a piece-wise smooth approximation of the input raster map and a raster map of the discontinuities of the output approximation.
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.
The module makes use of the varseg 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).
Some examples of use of the module can be found here and in this presentation [FOSS4G 2009 - pdf].
For details on the numerical implementation see [3].

NOTES

Remove any MASK before the execution of the module. If a MASK is present, the module stops after just one iteration.

Replace (r.null) any null data with the map average value (get with r.univar).

The segmentation depends on the parameters alpha and lambda: The module computes the segmentation by means of an iterative procedure.
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].
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].
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.

The data type of the output raster maps is DOUBLE PRECISION.

The module works on one raster map at a time, imagery groups are not supported.

To avoid to inappropriately re-sampled the input raster map, the settings for the current region should be set so that: The discontinuity thickness should be changed for test purposes only.

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.

EXAMPLE

This example is based the North Carolina GRASS sample data set, [complete GRASS location].
# set the region to match the ortho_2001_t792_1m 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@PERMANENT out_u=u_OF out_z=z_OF lambda=10 alpha=200 mxi=250

# for a better visualization of the output raster map u_OF, 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 u_OF:
r.mapcalc "diff = abs(ortho_2001_t792_1m@PERMANENT - u_OF)"

# for a better visualization of the differences, compute the natural logarithm of the diff 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 u_OF, 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@PERMANENT out_u=u1_OF out_z=z1_OF lambda=10 alpha=65 mxi=250
r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u2_OF out_z=z2_OF lambda=10 alpha=600 mxi=250
r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u3_OF out_z=z3_OF lambda=0.1 alpha=200 mxi=250
r.seg in_g=ortho_2001_t792_1m@PERMANENT out_u=u4_OF out_z=z4_OF lambda=1 alpha=200 mxi=250

# visualize and compare the different results

REFERENCE

SEE ALSO

i.smap, i.zc, r.mfilter

AUTHOR

Alfonso Vitti
  Dept. Civil and Environmental Engineering
  University of Trento - Italy
  alfonso.vitti [at] ing.unitn.it

Last changed: $Date: 2010-08-10 12:00:00 +0200 (Tue, 10 Aug 2010)$


Main index - raster index - Full index

© 2003-2016 GRASS Development Team