public class LinearContourLabelChang2004
extends java.lang.Object
Finds objects in a binary image by tracing their contours. The output is labeled binary image, set of external and internal contours for each object/blob. Blobs can be defined using a 4 or 8 connect rule. The algorithm works by processing the image in a single pass. When a new object is encountered its contour is traced. Then the inner pixels are labeled. If an internal contour is found it will also be traced. See [1] for all the details. The original algorithm has been modified to use different connectivity rules.
Output: Background pixels (0 in input image) are assigned a value of 0, Each blob is then assigned a unique ID starting from 1 up to the number of blobs.
The maximum contour size says how many elements are allowed in a contour. if that number is exceeded by the external contour the external contour will be zeroed. Internal contours that exceed it will be discarded. Note that the all external and internal contours will still be traversed they will just not be recorded if too large.
Internally, the input binary image is copied into another image which will have a 1 pixel border of all zeros around it. This ensures that boundary checks will not need to be done, speeding up the algorithm by about 25%.
[1] Fu Chang and Chun-jen Chen and Chi-jen Lu, "A linear-time component-labeling algorithm using contour tracing technique" Computer Vision and Image Understanding, 2004
| Constructor and Description |
|---|
LinearContourLabelChang2004(ConnectRule rule)
Configures the algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
ConnectRule |
getConnectRule() |
org.ddogleg.struct.FastQueue<ContourPacked> |
getContours() |
int |
getMaxContourSize() |
int |
getMinContourSize() |
PackedSetsPoint2D_I32 |
getPackedPoints() |
boolean |
isSaveInternalContours() |
void |
process(GrayU8 binary,
GrayS32 labeled)
Processes the binary image to find the contour of and label blobs.
|
void |
setConnectRule(ConnectRule rule) |
void |
setMaxContourSize(int maxContourSize) |
void |
setMinContourSize(int minContourSize) |
void |
setSaveInternalContours(boolean saveInternalContours) |
public LinearContourLabelChang2004(ConnectRule rule)
rule - Connectivity rule. 4 or 8public void process(GrayU8 binary, GrayS32 labeled)
binary - Input binary image. Not modified.labeled - Output. Labeled image. Modified.public org.ddogleg.struct.FastQueue<ContourPacked> getContours()
public PackedSetsPoint2D_I32 getPackedPoints()
public int getMinContourSize()
public void setMinContourSize(int minContourSize)
public int getMaxContourSize()
public void setMaxContourSize(int maxContourSize)
public boolean isSaveInternalContours()
public void setSaveInternalContours(boolean saveInternalContours)
public void setConnectRule(ConnectRule rule)
public ConnectRule getConnectRule()