public abstract class WatershedVincentSoille1991
extends java.lang.Object
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:
getOutput() this border is removed automatically by creating a sub-image.RemoveWatersheds[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.
| Modifier and Type | Class and Description |
|---|---|
static class |
WatershedVincentSoille1991.Connect4
Implementation which uses a 4-connect rule
|
static class |
WatershedVincentSoille1991.Connect8
Implementation which uses a 8-connect rule
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
currentDistance |
protected int |
currentLabel |
protected boofcv.struct.image.GrayS32 |
distance |
protected org.ddogleg.struct.CircularQueue_I32 |
fifo |
protected org.ddogleg.struct.GrowQueue_I32[] |
histogram |
static int |
INIT |
static int |
MARKER_PIXEL |
static int |
MASK |
protected boofcv.struct.image.GrayS32 |
output |
protected boofcv.struct.image.GrayS32 |
outputSub |
protected RemoveWatersheds |
removeWatersheds |
static int |
WSHED |
| Constructor and Description |
|---|
WatershedVincentSoille1991() |
| Modifier and Type | Method and Description |
|---|---|
protected 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 watershed
|
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.
|
boofcv.struct.image.GrayS32 |
getOutput()
Segmented output image with watersheds.
|
boofcv.struct.image.GrayS32 |
getOutputBorder()
The entire segmented image used internally.
|
int |
getTotalRegions()
Returns the total number of regions labeled.
|
protected void |
handleNeighborAssign(int indexTarget,
int indexNeighbor) |
void |
process(boofcv.struct.image.GrayU8 input)
Perform watershed segmentation on the provided input image.
|
void |
process(boofcv.struct.image.GrayU8 input,
boofcv.struct.image.GrayS32 seeds)
Segments the image using initial seeds for each region.
|
void |
removeWatersheds()
Removes watershed pixels from the output image by merging them into an arbitrary neighbor.
|
protected void |
sortPixels(boofcv.struct.image.GrayU8 input)
Very fast histogram based sorting.
|
public static final int WSHED
public static final int INIT
public static final int MASK
public static final int MARKER_PIXEL
protected org.ddogleg.struct.GrowQueue_I32[] histogram
protected boofcv.struct.image.GrayS32 output
protected boofcv.struct.image.GrayS32 outputSub
protected boofcv.struct.image.GrayS32 distance
protected int currentDistance
protected int currentLabel
protected org.ddogleg.struct.CircularQueue_I32 fifo
protected RemoveWatersheds removeWatersheds
public void process(boofcv.struct.image.GrayU8 input)
input - Input gray-scale image.public void process(boofcv.struct.image.GrayU8 input,
boofcv.struct.image.GrayS32 seeds)
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.
input - (Input) Input imageseeds - (Output) Segmented image containing seeds. Note that all seeds should have a value > 0 and have a
value ≤ numRegions.protected abstract void assignNewToNeighbors(int index)
index - Pixel whose neighbors are being examinedprotected abstract void checkNeighborsAssign(int index)
index - Index of the target pixelprotected void handleNeighborAssign(int indexTarget,
int indexNeighbor)
protected abstract void checkNeighborsMasks(int index)
index - Pixel whose neighbors are being examined.protected void checkMask(int index)
protected void sortPixels(boofcv.struct.image.GrayU8 input)
public boofcv.struct.image.GrayS32 getOutput()
getOutputBorder() to remove
the outside border of -1 valued pixels.public boofcv.struct.image.GrayS32 getOutputBorder()
public void removeWatersheds()
public int getTotalRegions()
THIS IS NOT VALID IF SEEDS ARE USED!!!