DGtal
0.9.4beta

In this example, we show how to retrieve the contour of a connected subset of an image and estimate its perimeter.
Let us assume that the following image has been loaded into an image object:
First of all, we implicitely extract a digital set from an image, using a simple threshold on gray level values:
This predicate returns true for each dark pixel of the following image:
The extraction of the contour is performed in a cellular space (with 0, 1, and 2cells), given an adjacency (0, 1, 2adjacency). See Cellular grid space and topology, unoriented and oriented cells, incidence for the basic concepts of cellular topology.
Then, the contour of each connected component can be retrieved as follows:
The GridCurve object is merely built from one retrieved contour, which is stored as a vector of signed 1cells:
Now, we want to get a perimeter estimation of the grid curve c. Several length estimators have been implemented in DGtal, but we are using in what follows the one based on a greedy segmentation of the curve into digital straight segments (DSS).
Since the DSS recognition algoritm deals with digital points, we get the points range of the grid curve c.
The DSS segmentation looks like this:
Then, we initialize the DSS length estimator from the points range and get the estimated length.
You should see in the standard output:
You should include these common files:
For loading the image and extracting a digital set by thresholding:
For extracting the contours of the digital set:
And finally, for estimating the length of the retrieved contours, you should include this: