DGtal 1.4.0
|
This part of the manual describes a simple way to extract a level set boundary as a FreemanChain contour from an gray level image. The first step is to extract the thresholed Digital set from the image (see. DGtal::SetFromImage) and then to track its boundary (see. DGtal::Surfaces). An example can also be found in the example tutorial-examples/freemanChainFromImage.cpp
The digitalSet can be obtained after thresholding a given image. As described in the section Image and digital object import/export a image can simply be imported with readers as for instance in PGMReader:
From the imported image you can extract a DigitalSet by using thresholds:
You can display the thresholded set:
A KhalimskySpaceND is also needed to extract the region boundary, you can simply use the domain of the imported image to initialise a KhalimskySpaceND:
Another important element is to define the SurfelAdjacency used to track the DigitalSet boundary:
Afterwards the set of all 4-connected contours can be extracted by using the function extractAllPointContours4C from DGtal::Surfaces:
From the previous vector containing the contour points, we can construct and display its associated FreemanChain.
Since the reconstructed freemanchain represents the inter pixels boundary of the digital set we can specify it by using the mode "InterGrid" as follows:
By using the display color defining in the example tutorial-examples/freemanChainFromImage.cpp you may obtain the following result where each contour are represented with a specific color:
Note that if you change the SurfelAdjacency used in the contour extraction:
you will obtain the followings contours:
Project available in the DGtal website (http://libdgtal.org/tools/)
The directory 2dContourTools contains command line program "pgm2freeman" allowing to simply extract level set contours from an pgm image:
This example will load the pgm source file "church.pgm" and applies successive thresholds [100,105], [100, 110].... [100, 220] and selects all the boundary contours with a minimal size equals to 300 and with a distance between its barycenter and point (129 526) less than 300.
The resulting file "contours.fc" contains a freemanchain on each line and can be displayed with the command line program "displayContours":
You will obtain the following result in eps (you can also use the pdf format if cairo is installed on your system).
By adding the obption
the backgroundImage will be rendered with transparency.
You need to include the DGTal basic header files:
To import the image and create digital set you need to include the following header files:
To track the frontier of the digital set and create the digital set you nedd to include:
For the display with gradient color: