[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
Superpixel Creation |
Modules | |
Parallel Processing | |
Classes | |
class | SeedOptions |
Options object for generateWatershedSeeds(). More... | |
class | SeedRgDirectValueFunctor< Value > |
Statistics functor to be used for seeded region growing. More... | |
struct | SlicOptions |
Options object for slicSuperpixels(). More... | |
class | WatershedOptions |
Options object for watershed algorithms. More... | |
Enumerations | |
enum | SRGType |
Functions | |
template<... > | |
unsigned int | generateSlicSeeds (...) |
Generate seeds for SLIC superpixel computation in arbitrary dimensions. More... | |
template<... > | |
unsigned int | generateWatershedSeeds (...) |
Generate seeds for watershed computation and seeded region growing. More... | |
template<... > | |
void | seededRegionGrowing (...) |
Region Segmentation by means of Seeded Region Growing. More... | |
template<... > | |
void | seededRegionGrowing3D (...) |
Three-dimensional Region Segmentation by means of Seeded Region Growing. More... | |
template<... > | |
unsigned int | slicSuperpixels (...) |
Compute SLIC superpixels in arbitrary dimensions. More... | |
template<... > | |
unsigned int | unionFindWatershedsBlockwise (...) |
Blockwise union-find watersheds transform for MultiArrays and ChunkedArrays. More... | |
template<... > | |
unsigned int | watersheds3D (...) |
Region Segmentation by means of the watershed algorithm. More... | |
template<... > | |
Label | watershedsMultiArray (...) |
Watershed segmentation of an arbitrary-dimensional array. More... | |
template<... > | |
unsigned int | watershedsRegionGrowing (...) |
Region segmentation by means of a flooding-based watershed algorithm. More... | |
template<... > | |
unsigned int | watershedsUnionFind (...) |
Region segmentation by means of the union-find watershed algorithm. More... | |
Watersheds, SLIC superpixels, and seeded region growing.
enum SRGType |
Choose between different types of Region Growing
unsigned int vigra::unionFindWatershedsBlockwise | ( | ... | ) |
Blockwise union-find watersheds transform for MultiArrays and ChunkedArrays.
Declaration:
The resulting labeling is equivalent to a labeling by watershedsUnionFind, that is, the components are the same but may have different ids. If temporary_storage is provided, this array is used for intermediate result storage. Otherwise, a newly created vigra::ChunkedArrayLazy is used.
Return: the number of labels assigned (=largest label, because labels start at one)
Usage:
#include <vigra/blockwise_watersheds.hxx>
Namespace: vigra
Label vigra::watershedsMultiArray | ( | ... | ) |
Watershed segmentation of an arbitrary-dimensional array.
See also unionFindWatershedsBlockwise() for a parallel version of the watershed algorithm.
This function implements variants of the watershed algorithms described in
[1] L. Vincent and P. Soille: "Watersheds in digital spaces: An efficient algorithm based on immersion simulations", IEEE Trans. Patt. Analysis Mach. Intell. 13(6):583-598, 1991
[2] J. Roerdink, R. Meijster: "The watershed transform: definitions, algorithms, and parallelization strategies", Fundamenta Informaticae, 41:187-228, 2000
The source array data is a boundary indicator such as the gaussianGradientMagnitude() or the trace of the boundaryTensor(), and the destination labels is a label array designating membership of each point in one of the regions found. Plateaus in the boundary indicator are handled via simple tie breaking strategies. Argument neighborhood specifies the connectivity between points and can be DirectNeighborhood
(meaning 4-neighborhood in 2D and 6-neighborhood in 3D, default) or IndirectNeighborhood
(meaning 8-neighborhood in 2D and 26-neighborhood in 3D).
The watershed variant to be applied can be selected in the WatershedOptions object: When you call WatershedOptions::regionGrowing()
(default), the flooding algorithm from [1] is used. Alternatively, WatershedOptions::unionFind()
uses the scan-line algorithm 4.7 from [2]. The latter is faster, but does not support any options (if you pass options nonetheless, they are silently ignored).
The region growing algorithm needs a seed for each region. Seeds can either be provided in the destination array labels (which will then be overwritten with the result) or computed automatically by an internal call to generateWatershedSeeds(). In the former case you have full control over seed placement, while the latter is more convenient. Automatic seed computation is performed when you provide seeding options via WatershedOptions::seedOptions()
or when the array labels is empty (all zeros), in which case default seeding options are chosen. The destination image should be zero-initialized for automatic seed computation.
Further options to be specified via WatershedOptions are:
keepContours()
: Whether to keep a 1-pixel-wide contour (with label 0) between regions (otherwise, a complete grow is performed, i.e. all pixels are assigned to a region). stopAtThreshold()
: Whether to stop growing when the boundaryness exceeds a threshold (remaining pixels keep label 0). biasLabel()
: Whether one region (label) is to be preferred or discouraged by biasing its cost with a given factor (smaller than 1 for preference, larger than 1 for discouragement). The option turboAlgorithm()
is implied by method regionGrowing()
(this is in contrast to watershedsRegionGrowing(), which supports an additional algorithm in 2D only).
watershedsMultiArray() returns the number of regions found (= the highest region label, because labels start at 1).
Declaration:
Usage:
#include <vigra/multi_watersheds.hxx>
Namespace: vigra
Example: watersheds of the gradient magnitude (the example works likewise for higher dimensions).
void vigra::seededRegionGrowing | ( | ... | ) |
Region Segmentation by means of Seeded Region Growing.
This algorithm implements seeded region growing as described in
R. Adams, L. Bischof: "Seeded Region Growing", IEEE Trans. on Pattern Analysis and Maschine Intelligence, vol 16, no 6, 1994, and
Ullrich Köthe: Primary Image Segmentation, in: G. Sagerer, S. Posch, F. Kummert (eds.): Mustererkennung 1995, Proc. 17. DAGM-Symposium, Springer 1995
The seed image is a partly segmented image which contains uniquely labeled regions (the seeds) and unlabeled pixels (the candidates, label 0). The highest seed label found in the seed image is returned by the algorithm.
Seed regions can be as large as you wish and as small as one pixel. If there are no candidates, the algorithm will simply copy the seed image into the output image. Otherwise it will aggregate the candidates into the existing regions so that a cost function is minimized. Candidates are taken from the neighborhood of the already assigned pixels, where the type of neighborhood is determined by parameter neighborhood
which can take the values FourNeighborCode()
(the default) or EightNeighborCode()
. The algorithm basically works as follows (illustrated for 4-neighborhood, but 8-neighborhood works in the same way):
Find all candidate pixels that are 4-adjacent to a seed region. Calculate the cost for aggregating each candidate into its adjacent region and put the candidates into a priority queue.
While( priority queue is not empty and termination criterion is not fulfilled)
Take the candidate with least cost from the queue. If it has not already been merged, merge it with it's adjacent region.
Put all candidates that are 4-adjacent to the pixel just processed into the priority queue.
SRGType
can take the following values:
CompleteGrow
KeepContours
StopAtThreshold
max_cost
. KeepContours | StopAtThreshold
max_cost
. The cost is determined jointly by the source image and the region statistics functor. The source image contains feature values for each pixel which will be used by the region statistics functor to calculate and update statistics for each region and to calculate the cost for each candidate. The RegionStatisticsArray
must be compatible to the ArrayOfRegionStatistics functor and contains an array of statistics objects for each region. The indices must correspond to the labels of the seed regions. The statistics for the initial regions must have been calculated prior to calling seededRegionGrowing()
(for example by means of inspectTwoImagesIf()).
For each candidate x
that is adjacent to region i
, the algorithm will call stats[i].cost(as(x))
to get the cost (where x
is a SrcIterator
and as
is the SrcAccessor). When a candidate has been merged with a region, the statistics are updated by calling stats[i].operator()(as(x))
. Since the RegionStatisticsArray
is passed by reference, this will overwrite the original statistics.
If a candidate could be merged into more than one regions with identical cost, the algorithm will favour the nearest region. If StopAtThreshold
is active, and the cost of the current candidate at any point in the algorithm exceeds the optional max_cost
value (which defaults to NumericTraits<double>::max()
), region growing is aborted, and all voxels not yet assigned to a region remain unlabeled.
In some cases, the cost only depends on the feature value of the current pixel. Then the update operation will simply be a no-op, and the cost()
function returns its argument. This behavior is implemented by the SeedRgDirectValueFunctor. With SRGType == KeepContours
, this is equivalent to the watershed algorithm.
Declarations:
pass 2D array views:
Usage:
#include <vigra/seededregiongrowing.hxx>
Namespace: vigra
Example: implementation of the voronoi tesselation
Further requirements are determined by the RegionStatisticsArray
.
void vigra::seededRegionGrowing3D | ( | ... | ) |
Three-dimensional Region Segmentation by means of Seeded Region Growing.
This algorithm implements seeded region growing as described in
The seed image is a partly segmented multi-dimensional array which contains uniquely labeled regions (the seeds) and unlabeled voxels (the candidates, label 0). Seed regions can be as large as you wish and as small as one voxel. If there are no candidates, the algorithm will simply copy the seed array into the output array. Otherwise it will aggregate the candidates into the existing regions so that a cost function is minimized. Candidates are taken from the neighborhood of the already assigned pixels, where the type of neighborhood is determined by parameter neighborhood
which can take the values NeighborCode3DSix()
(the default) or NeighborCode3DTwentySix()
. The algorithm basically works as follows (illustrated for 6-neighborhood, but 26-neighborhood works in the same way):
Find all candidate pixels that are 6-adjacent to a seed region. Calculate the cost for aggregating each candidate into its adjacent region and put the candidates into a priority queue.
While( priority queue is not empty)
Take the candidate with least cost from the queue. If it has not already been merged, merge it with it's adjacent region.
Put all candidates that are 4-adjacent to the pixel just processed into the priority queue.
SRGType
can take the following values:
CompleteGrow
KeepContours
StopAtThreshold
max_cost
. KeepContours | StopAtThreshold
max_cost
. The cost is determined jointly by the source array and the region statistics functor. The source array contains feature values for each pixel which will be used by the region statistics functor to calculate and update statistics for each region and to calculate the cost for each candidate. The RegionStatisticsArray
must be compatible to the ArrayOfRegionStatistics functor and contains an array of statistics objects for each region. The indices must correspond to the labels of the seed regions. The statistics for the initial regions must have been calculated prior to calling seededRegionGrowing3D()
For each candidate x
that is adjacent to region i
, the algorithm will call stats[i].cost(as(x))
to get the cost (where x
is a SrcImageIterator
and as
is the SrcAccessor). When a candidate has been merged with a region, the statistics are updated by calling stats[i].operator()(as(x))
. Since the RegionStatisticsArray
is passed by reference, this will overwrite the original statistics.
If a candidate could be merged into more than one regions with identical cost, the algorithm will favour the nearest region. If StopAtThreshold
is active, and the cost of the current candidate at any point in the algorithm exceeds the optional max_cost
value (which defaults to NumericTraits<double>::max()
), region growing is aborted, and all voxels not yet assigned to a region remain unlabeled.
In some cases, the cost only depends on the feature value of the current voxel. Then the update operation will simply be a no-op, and the cost()
function returns its argument. This behavior is implemented by the SeedRgDirectValueFunctor.
Declarations:
pass 3D array views:
Usage:
#include <vigra/seededregiongrowing3d.hxx>
Namespace: vigra
See seededRegionGrowing() for an example
unsigned int vigra::generateSlicSeeds | ( | ... | ) |
Generate seeds for SLIC superpixel computation in arbitrary dimensions.
The source array src must be a scalar boundary indicator such as the gradient magnitude. Seeds are initially placed on a regular Cartesian grid with spacing seedDist und then moved to the point with smallest boundary indicator within a search region of radius searchRadius around the initial position. The resulting points are then marked in the output array seeds by consecutive labels.
The function returns the number of selected seeds, which equals the largest seed label because labeling starts at 1.
Declaration:
use arbitrary-dimensional arrays:
Usage:
#include <vigra/slic.hxx>
Namespace: vigra
For more details and examples see slicSuperpixels().
unsigned int vigra::slicSuperpixels | ( | ... | ) |
Compute SLIC superpixels in arbitrary dimensions.
This function implements the algorithm described in
R. Achanta et al.: "SLIC Superpixels Compared to State-of-the-Art Superpixel Methods", IEEE Trans. Patt. Analysis Mach. Intell. 34(11):2274-2281, 2012
The value type T
of the source array src must provide the necessary functionality to compute averages and squared distances (i.e. it must fulfill the requirements of a LinearSpace and support squaredNorm(T const &)). This is true for all scalar types as well as vigra::TinyVector and vigra::RGBValue. The output array labels will be filled with labels designating membership of each point in one of the superpixel regions.
The output array can optionally contain seeds (which will be overwritten by the output) to give you full control over seed placement. If labels is empty, seeds will be created automatically by an internal call to generateSlicSeeds().
The parameter seedDistance specifies the radius of the window around each seed (or, more precisely, around the present regions centers) where the algorithm looks for potential members of the corresponding superpixel. It thus places an upper limit on the superpixel size. When seeds are computed automatically, this parameter also determines the grid spacing for seed placement.
The parameter intensityScaling is used to normalize (i.e. divide) the color/intensity difference before it is compared with the spatial distance. This corresponds to parameter m in equation (2) of the paper.
The options object can be used to specify the number of iterations (SlicOptions::iterations()
) and an explicit minimal superpixel size (SlicOptions::minSize()
). By default, the algorithm merges all regions that are smaller than 1/4 of the average superpixel size.
The function returns the number of superpixels, which equals the largest label because labeling starts at 1.
Declaration:
use arbitrary-dimensional arrays:
Usage:
#include <vigra/slic.hxx>
Namespace: vigra
This works for arbitrary-dimensional arrays.
unsigned int vigra::generateWatershedSeeds | ( | ... | ) |
Generate seeds for watershed computation and seeded region growing.
The source image is a boundary indicator such as the gradient magnitude or the trace of the boundaryTensor(). Seeds are generally generated at locations where the boundaryness (i.e. the likelihood of the point being on the boundary) is very small. In particular, seeds can be placed by either looking for local minima (possibly including minimal plateaus) of the boundaryness, of by looking at level sets (i.e. regions where the boundaryness is below a threshold). Both methods can also be combined, so that only minima below a threshold are returned. The particular seeding strategy is specified by the options
object (see SeedOptions).
The pixel type of the input image must be LessThanComparable
. The pixel type of the output image must be large enough to hold the labels for all seeds. (typically, you will use UInt32
). The function will label seeds by consecutive integers (starting from 1) and returns the largest label it used.
Pass IndirectNeighborhood or DirectNeighborhood (first form of the function) or vigra::EightNeighborCode or vigra::FourNeighborCode (second and third forms) to determine the neighborhood where pixel values are compared.
Declarations:
use arbitrary-dimensional arrays:
Usage:
#include <vigra/multi_watersheds.hxx> (MultiArray variant)
#include <vigra/watersheds.hxx> (deprecated variants)
Namespace: vigra
For detailed examples see watershedsMultiArray() and watershedsRegionGrowing().
unsigned int vigra::watershedsUnionFind | ( | ... | ) |
Region segmentation by means of the union-find watershed algorithm.
Note: This function is largely obsolete, watershedsMultiArray() should be preferred unless top speed is required.
This function implements the union-find version of the watershed algorithms described as algorithm 4.7 in
J. Roerdink, R. Meijster: "The watershed transform: definitions, algorithms, and parallelization strategies", Fundamenta Informaticae, 41:187-228, 2000
The source image is a boundary indicator such as the gaussianGradientMagnitude() or the trace of the boundaryTensor(). Local minima of the boundary indicator are used as region seeds, and all other pixels are recursively assigned to the same region as their lowest neighbor. Pass vigra::EightNeighborCode or vigra::FourNeighborCode to determine the neighborhood where pixel values are compared. The pixel type of the input image must be LessThanComparable
. The function uses accessors.
Note that VIGRA provides an alternative implementation of the watershed transform via watershedsRegionGrowing(). It is slower, but offers many more configuration options.
Declarations:
pass 2D array views:
Usage:
#include <vigra/watersheds.hxx>
Namespace: vigra
Example: watersheds of the gradient magnitude.
unsigned int vigra::watershedsRegionGrowing | ( | ... | ) |
Region segmentation by means of a flooding-based watershed algorithm.
Note: This function is largely obsolete, watershedsMultiArray() should be preferred unless top speed is required.
This function implements variants of the watershed algorithm described in
L. Vincent and P. Soille: "Watersheds in digital spaces: An efficient algorithm based on immersion simulations", IEEE Trans. Patt. Analysis Mach. Intell. 13(6):583-598, 1991
The source image is a boundary indicator such as the gaussianGradientMagnitude() or the trace of the boundaryTensor(), and the destination is a label image designating membership of each point in one of the regions. Plateaus in the boundary indicator (i.e. regions of constant gray value) are handled via a Euclidean distance transform by default.
By default, the destination image is assumed to hold seeds for a seeded watershed transform. Seeds may, for example, be created by means of generateWatershedSeeds(). Note that the seeds will be overridden with the final watershed segmentation.
Alternatively, you may provide SeedOptions in order to instruct watershedsRegionGrowing() to generate its own seeds (it will call generateWatershedSeeds() internally). In that case, the destination image should be zero-initialized.
You can specify the neighborhood system to be used by passing FourNeighborCode or EightNeighborCode (default).
Further options to be specified via WatershedOptions are:
[0, ..., bucket_count-1]
, where bucket_count
is specified in the options object), it only supports complete growing (no contour between regions is possible), and it handles plateaus in a simplistic way. It also saves some memory because it allocates less temporary storage. Note that VIGRA provides an alternative implementation of the watershed transform via watershedsUnionFind().
Declarations:
pass 2D array views:
Usage:
#include <vigra/watersheds.hxx>
Namespace: vigra
Example: watersheds of the gradient magnitude.
unsigned int vigra::watersheds3D | ( | ... | ) |
Region Segmentation by means of the watershed algorithm.
This function is deprecated, use watershedsMultiArray() instead.
Declarations:
This function implements the union-find version of the watershed algorithms as described in
J. Roerdink, R. Meijster: "The watershed transform: definitions, algorithms, and parallelization strategies", Fundamenta Informaticae, 41:187-228, 2000
The source volume is a boundary indicator such as the gradient magnitude of the trace of the boundaryTensor(). Local minima of the boundary indicator are used as region seeds, and all other voxels are recursively assigned to the same region as their lowest neighbor. Pass vigra::NeighborCode3DSix or vigra::NeighborCode3DTwentySix to determine the neighborhood where voxel values are compared. The voxel type of the input volume must be LessThanComparable
.
Usage:
#include <vigra/watersheds3D.hxx>
Namespace: vigra
Example: watersheds3D of the gradient magnitude.
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|