public class SegmentFelzenszwalbHuttenlocher04<T extends boofcv.struct.image.ImageBase>
extends java.lang.Object
Implementation of Felzenszwalb-Huttenlocher [1] image segmentation algorithm. It is fast and uses a graph based heuristic with a tuning parameter that can be used to adjust region size. Regions are irregularly shaped.
It works by constructing a graph in which pixels are the nodes and edges describe the relationship between adjacent pixels. Each pixel has a weight that is determined from the difference in pixel values using the F-norm. The weights for all the edges are computed first and sorted from smallest to largest. In the next step the first edge in the list is selected and is tested to see if the nodes should be connected or not. This process is repeated for all edges. Small regions are then merged into large ones. For more details see [1].
NOTE:
getRegionId() to find
out what the ID's are.FhEdgeWeights
class passed in to the constructor.
Algorithmic Changes:
This implementation is a faithful of the original and has been compared against the authors
reference source code. It does produce different results from the reference, some times significant, due to the
sensitivity of the algorithm to minor differences. The sensitivity arises from it being a greedy algorithm.
Here is a list of minor differences that cause different regions due to its sensitivity. The order in which edges with identical weights are sorted is arbitrary. The order that edges are computed is arbitrary. Floating point error in weight calculation gradually causes segmentation to diverge to a different solution even when given the same input.
One difference from the original is that Gaussian blur is not applied to the input image by default. That should be done prior to the image being passed in.
[1] Felzenszwalb, Pedro F., and Daniel P. Huttenlocher. "Efficient graph-based image segmentation." International Journal of Computer Vision 59.2 (2004): 167-181.
| Modifier and Type | Class and Description |
|---|---|
static class |
SegmentFelzenszwalbHuttenlocher04.Edge
Describes the relationship between to adjacent pixels in the image.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.ddogleg.struct.FastQueue<SegmentFelzenszwalbHuttenlocher04.Edge> |
edges |
protected org.ddogleg.struct.FastQueue<SegmentFelzenszwalbHuttenlocher04.Edge> |
edgesNotMatched |
protected boofcv.struct.image.GrayS32 |
graph |
protected org.ddogleg.struct.GrowQueue_I32 |
regionSize |
protected org.ddogleg.struct.GrowQueue_F32 |
threshold |
| Constructor and Description |
|---|
SegmentFelzenszwalbHuttenlocher04(float k,
int minimumSize,
FhEdgeWeights<T> computeWeights)
Specifies tuning parameter
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
computeOutput()
Searches for root nodes in the graph and adds their size to the list of region sizes.
|
void |
configureApproximateSort(int numBins)
If this function is called the exact sort routine will not be used and instead an approximate routine will
be used.
|
protected int |
find(int child)
Finds the root given child.
|
boofcv.struct.image.ImageType<T> |
getInputType() |
org.ddogleg.struct.GrowQueue_I32 |
getRegionId()
List of ID's for each region in the segmented image.
|
org.ddogleg.struct.GrowQueue_I32 |
getRegionSizes()
Number of pixels in each region
|
protected void |
initialize(T input,
boofcv.struct.image.GrayS32 output)
Predeclares all memory required and sets data structures to their initial values
|
protected void |
mergeRegions()
Follows the merge procedure output in [1].
|
protected void |
mergeSmallRegions()
Look at the remaining regions and if there are any small ones marge them into a larger region
|
void |
process(T input,
boofcv.struct.image.GrayS32 output)
Segments the image.
|
protected boofcv.struct.image.GrayS32 graph
protected org.ddogleg.struct.FastQueue<SegmentFelzenszwalbHuttenlocher04.Edge> edges
protected org.ddogleg.struct.FastQueue<SegmentFelzenszwalbHuttenlocher04.Edge> edgesNotMatched
protected org.ddogleg.struct.GrowQueue_I32 regionSize
protected org.ddogleg.struct.GrowQueue_F32 threshold
public SegmentFelzenszwalbHuttenlocher04(float k,
int minimumSize,
FhEdgeWeights<T> computeWeights)
k - Tuning parameter. Larger regions are preferred for larger values of K. Try 300minimumSize - Regions smaller than this are merged into larger regionscomputeWeights - Function used to compute the weight for all the edges.public void configureApproximateSort(int numBins)
numBins - Number of bins. Try 2000. More bins the more accurate it will bepublic void process(T input, boofcv.struct.image.GrayS32 output)
getRegionId(). To get a list of number of pixels in each region call
getRegionSizes().input - Input image. Not modified.output - Output segmented image. Modified.protected void initialize(T input, boofcv.struct.image.GrayS32 output)
protected void mergeRegions()
protected void mergeSmallRegions()
protected int find(int child)
protected void computeOutput()
public org.ddogleg.struct.GrowQueue_I32 getRegionId()
public org.ddogleg.struct.GrowQueue_I32 getRegionSizes()
public boofcv.struct.image.ImageType<T> getInputType()