Finds the external contours of binary blobs in linear time. No label image is required. Designed to quickly
move through regions with repeat values of 0 and 1. Input image is modified. The outside border is set to zero
and the value of contour pixels is set to -1 or -2 to indicate that it has been processed. This algorithm is
highly specialized but follows a similar pattern to other finding/tracing algorithms from [1] and [2].
Algorithm:
- Fill in image border with zeros
- Start at pixel x=1,y=1
- Begin Row: Starting at (x,y) scan for a value of not zero. Let this point be (x,y)
- Trace contour. This contour must be an external contour and is saved.
- Resume scanning the row starting at (x+1,y) for a pixel with a value of zero. This pixel will now be (x,y)
- If the pixel (x-1,y) has a value of 1 trace the inner contour. Otherwise move to next step.
- Iterate from "Begin Row" until the end of the row has been reached
- Move to the next row starting at point (1,y+1)
Look at the code for all the details. There are a couple of important points which are glosed over
in the description above.
To get the external contours after processing call
#getExternalContours().
[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
[2] Rosenfeld, Azriel. "Digital topology." American Mathematical Monthly (1979): 621-630.