Class WatershedVincentSoille1991
- Direct Known Subclasses:
WatershedVincentSoille1991.Connect4
,WatershedVincentSoille1991.Connect8
Fast watershed based upon Vincient and Soille's 1991 paper [1]. Watershed segments an image using the idea of immersion simulation. For example, the image is treated as a topological map and if you let a droplet of water flow down from each pixel the location the droplets cluster in defines a region. Two different methods are provided for processing the image, a new region is created at each local minima or the user provides an initial seed for each region for it to grow from. The output will be a segmented image with watersheds being assign a value of 0 and each region a value > 0. Watersheds are assigned to pixels which are exactly the same distance from multiple regions, thus it is ambiguous which one it is a member of.
If the image is processed with process(GrayU8)
then a new region is
created at each local minima and assigned a unique ID > 0. The total number of regions found is returned
by getTotalRegions()
. This technique will lead to over segmentation on many images.
Initial seeds are provided with a call to process(GrayU8, GrayS32)
.
No new regions will be created. By providing an initial set of seeds over segmentation can be avoided, but
prior knowledge of the image is typically needed to create the seeds.
NOTES:
- For faster processing, the internal labeled image has a 1 pixel border around it. If you call
getOutput()
this border is removed automatically by creating a sub-image. - Connectivity is handled by child sub-classes. An index of neighbors could have been used, but the additional additional array access/loop slows things down a little bit.
- Watersheds are included. To remove them using
RemoveWatersheds
- Pixel values are assumed to range from 0 to 255, inclusive.
[1] Vincent, Luc, and Pierre Soille. "Watersheds in digital spaces: an efficient algorithm based on immersion simulations." IEEE transactions on pattern analysis and machine intelligence 13.6 (1991): 583-598.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Implementation which uses a 4-connect rulestatic class
Implementation which uses a 8-connect rule -
Field Summary
Modifier and TypeFieldDescriptionprotected int
protected int
protected GrayS32
protected CircularArray_I32
protected DogArray_I32[]
static final int
static final int
static final int
protected GrayS32
protected GrayS32
protected RemoveWatersheds
static final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract void
assignNewToNeighbors
(int index) See if a neighbor has a label ( > 0 ) or has been assigned WSHED ( == 0 ).protected void
checkMask
(int index) protected abstract void
checkNeighborsAssign
(int index) Check the neighbors to see if it should become a member or a watershedprotected abstract void
checkNeighborsMasks
(int index) Checks neighbors of pixel 'index' to see if their region is MASK, if so they are assigned the currentLabel and added to fifo.Segmented output image with watersheds.The entire segmented image used internally.int
Returns the total number of regions labeled.protected void
handleNeighborAssign
(int indexTarget, int indexNeighbor) void
Perform watershed segmentation on the provided input image.void
Segments the image using initial seeds for each region.void
Removes watershed pixels from the output image by merging them into an arbitrary neighbor.protected void
sortPixels
(GrayU8 input) Very fast histogram based sorting.
-
Field Details
-
WSHED
public static final int WSHED- See Also:
-
INIT
public static final int INIT- See Also:
-
MASK
public static final int MASK- See Also:
-
MARKER_PIXEL
public static final int MARKER_PIXEL- See Also:
-
histogram
-
output
-
outputSub
-
distance
-
currentDistance
protected int currentDistance -
currentLabel
protected int currentLabel -
fifo
-
removeWatersheds
-
-
Constructor Details
-
WatershedVincentSoille1991
protected WatershedVincentSoille1991()
-
-
Method Details
-
process
Perform watershed segmentation on the provided input image. New basins are created at each local minima.- Parameters:
input
- Input gray-scale image.
-
process
Segments the image using initial seeds for each region. This is often done to avoid over segmentation but requires additional preprocessing and/or knowledge on the image structure. Initial seeds are specified in the input image 'seeds'. A seed is any pixel with a value > 0. New new regions will be created beyond those seeds. The final segmented image is provided by
getOutput()
.NOTE: If seeds are used then
getTotalRegions()
will not return a correct solution.- Parameters:
input
- (Input) Input imageseeds
- (Output) Segmented image containing seeds. Note that all seeds should have a value > 0 and have a value ≤ numRegions.
-
assignNewToNeighbors
protected abstract void assignNewToNeighbors(int index) See if a neighbor has a label ( > 0 ) or has been assigned WSHED ( == 0 ). If so set distance of pixel index to 1 and add it to fifo.- Parameters:
index
- Pixel whose neighbors are being examined
-
checkNeighborsAssign
protected abstract void checkNeighborsAssign(int index) Check the neighbors to see if it should become a member or a watershed- Parameters:
index
- Index of the target pixel
-
handleNeighborAssign
protected void handleNeighborAssign(int indexTarget, int indexNeighbor) -
checkNeighborsMasks
protected abstract void checkNeighborsMasks(int index) Checks neighbors of pixel 'index' to see if their region is MASK, if so they are assigned the currentLabel and added to fifo.- Parameters:
index
- Pixel whose neighbors are being examined.
-
checkMask
protected void checkMask(int index) -
sortPixels
Very fast histogram based sorting. Index of each pixel is placed inside a list for its intensity level. -
getOutput
Segmented output image with watersheds. This is a sub-image ofgetOutputBorder()
to remove the outside border of -1 valued pixels. -
getOutputBorder
The entire segmented image used internally. This contains a 1-pixel border around the entire image filled with pixels of value -1. -
removeWatersheds
public void removeWatersheds()Removes watershed pixels from the output image by merging them into an arbitrary neighbor. -
getTotalRegions
public int getTotalRegions()Returns the total number of regions labeled. If watersheds have not been removed then this will including the watershed.THIS IS NOT VALID IF SEEDS ARE USED!!!
- Returns:
- number of regions.
-