# Segmentation

## Brief Description

Performs segmentation of an image, and output either a raster or a vector file. In vector mode, large input datasets are supported.

## Tags

Segmentation

## Long Description

This application allows performing various segmentation algorithms on a multispectral image.Available segmentation algorithms are two different versions of Mean-Shift segmentation algorithm (one being multi-threaded), simple pixel based connected components according to a user-defined criterion, and watershed from the gradient of the intensity (norm of spectral bands vector). The application has two different modes that affects the nature of its output. In raster mode, the output of the application is a classical image of unique labels identifying the segmented regions. The labeled output can be passed to the ColorMapping application to render regions with contrasted colors. Please note that this mode loads the whole input image into memory, and as such can not handle large images. To segment large data, one can use the vector mode. In this case, the output of the application is a vector file or database. The input image is split into tiles (whose size can be set using the tilesize parameter), and each tile is loaded, segmented with the chosen algorithm, vectorized, and written into the output file or database. This piece-wise behavior ensure that memory will never get overloaded, and that images of any size can be processed. There are few more options in the vector mode. The simplify option allows simplifying the geometry (i.e. remove nodes in polygons) according to a user-defined tolerance. The stitch option allows applying to try to stitch together polygons corresponding to segmented region that may have been split by the tiling scheme.

## Parameters

- [param] -in <string> The input image to segment. Mandatory: True. Default Value: ""
[choice] -filter Choice of segmentation algorithm (mean-shift by default) meanshift,edison,cc,watershed,mprofiles. Mandatory: True. Default Value: "meanshift"

- [group] -meanshift

- [param] -filter.meanshift.spatialr <int32> Spatial radius of the neighborhood.. Mandatory: True. Default Value: "5"
- [param] -filter.meanshift.ranger <float> Range radius defining the radius (expressed in radiometry unit) in the multispectral space.. Mandatory: True. Default Value: "15"
- [param] -filter.meanshift.thres <float> Algorithm iterative scheme will stop if mean-shift vector is below this threshold or if iteration number reached maximum number of iterations.. Mandatory: True. Default Value: "0.1"
- [param] -filter.meanshift.maxiter <int32> Algorithm iterative scheme will stop if convergence hasn't been reached after the maximum number of iterations.. Mandatory: True. Default Value: "100"
- [param] -filter.meanshift.minsize <int32> Minimum size of a region (in pixel unit) in segmentation. Smaller clusters will be merged to the neighboring cluster with the closest radiometry. If set to 0 no pruning is done.. Mandatory: True. Default Value: "100"

- [group] -edison

- [param] -filter.edison.spatialr <int32> Spatial radius defining neighborhood.. Mandatory: True. Default Value: "5"
- [param] -filter.edison.ranger <float> Range radius defining the radius (expressed in radiometry unit) in the multi-spectral space.. Mandatory: True. Default Value: "15"
- [param] -filter.edison.minsize <int32> Minimum size of a region in segmentation. Smaller clusters will be merged to the neighboring cluster with the closest radiometry.. Mandatory: True. Default Value: "100"
- [param] -filter.edison.scale <float> Scaling of the image before processing. This is useful for images with narrow decimal ranges (like [0,1] for instance). . Mandatory: True. Default Value: "1"

- [group] -cc

- [param] -filter.cc.expr <string> User defined connection condition, written as a mathematical expression. Available variables are p(i)b(i), intensity_p(i) and distance (example of expression : distance < 10 ). Mandatory: True. Default Value: ""

- [group] -watershed

- [param] -filter.watershed.threshold <float> Depth threshold Units in percentage of the maximum depth in the image.. Mandatory: True. Default Value: "0.01"
- [param] -filter.watershed.level <float> flood level for generating the merge tree from the initial segmentation (between 0 and 1). Mandatory: True. Default Value: "0.1"

- [group] -mprofiles

- [param] -filter.mprofiles.size <int32> Size of the profiles. Mandatory: True. Default Value: "5"
- [param] -filter.mprofiles.start <int32> Initial radius of the structuring element (in pixels). Mandatory: True. Default Value: "1"
- [param] -filter.mprofiles.step <int32> Radius step along the profile (in pixels). Mandatory: True. Default Value: "1"
- [param] -filter.mprofiles.sigma <float> Profiles values under the threshold will be ignored.. Mandatory: True. Default Value: "1"

[choice] -mode Choice of processing mode, either raster or large-scale. vector,raster. Mandatory: True. Default Value: "vector"

- [group] -vector

- [param] -mode.vector.out <string> The output vector file or database (name can be anything understood by OGR). Mandatory: True. Default Value: ""
- [param] -mode.vector.outmode <string> This allows setting the writing behaviour for the output vector file. Please note that the actual behaviour depends on the file format.. Mandatory: True. Default Value: "ulco"
- [param] -mode.vector.inmask <string> Only pixels whose mask value is strictly positive will be segmented.. Mandatory: False. Default Value: ""
- [param] -mode.vector.neighbor <boolean> Activate 8-Neighborhood connectivity (default is 4).. Mandatory: False. Default Value: "True"
- [param] -mode.vector.stitch <boolean> Scan polygons on each side of tiles and stitch polygons which connect by more than one pixel.. Mandatory: False. Default Value: "True"
- [param] -mode.vector.minsize <int32> Objects whose size is below the minimum object size (area in pixels) will be ignored during vectorization.. Mandatory: False. Default Value: "1"
- [param] -mode.vector.simplify <float> Simplify polygons according to a given tolerance (in pixel). This option allows reducing the size of the output file or database.. Mandatory: False. Default Value: "0.1"
- [param] -mode.vector.layername <string> Name of the layer in the vector file or database (default is Layer).. Mandatory: True. Default Value: "layer"
- [param] -mode.vector.fieldname <string> Name of the field holding the geometry index in the output vector file or database.. Mandatory: True. Default Value: "DN"
- [param] -mode.vector.tilesize <int32> User defined tiles size for tile-based segmentation. Optimal tile size is selected according to available RAM if null.. Mandatory: True. Default Value: "1024"
- [param] -mode.vector.startlabel <int32> Starting value of the geometry index field. Mandatory: True. Default Value: "1"
- [param] -mode.vector.ogroptions <string> A list of layer creation options in the form KEY=VALUE that will be passed directly to OGR without any validity checking. Options may depend on the file format, and can be found in OGR documentation.. Mandatory: False. Default Value: ""

- [group] -raster

- [param] -mode.raster.out <string> The output labeled image.. Mandatory: True. Default Value: ""

## Limitations

In raster mode, the application can not handle large input images. Stitching step of vector mode might become slow with very large input images. MeanShift filter results depends on threads number.

## Authors

OTB-Team

## See Also

MeanShiftSegmentation

## Example of use

- Example of use with vector mode and watershed segmentation

  - in: QB_Toulouse_Ortho_PAN.tif

  - mode: vector

  - mode.vector.out: SegmentationVector.sqlite

  - filter: watershed

- Example of use with raster mode and mean-shift segmentation

  - in: QB_Toulouse_Ortho_PAN.tif

  - mode: raster

  - mode.raster.out: SegmentationRaster.tif uint16

  - filter: meanshift