shape extraction from label 2d image algorithm
This algorithm allows to extract shapes from a label (Connected Component 2d) input 2d image. These contours are stored into a collection of shape 2d objets (ipsdk::geom::Shape2d) indexed by their label.
Each shape is define with respect to a neighborhood 2d policy and can be optionally simplified by a polygonal approximation algorithm.
Four options allow to control processing (See ContourExtractionSettings) :
- a flag EnablePolygApprox which specify whether we should compute polygons associated to shapes row intersections. Note that disabling polygons computation will allows faster computation but will also inhibit some shape analysis and measurement features (measures such as area computation based on polygonal shape representation).
- a neighborhood 2d type Neighborhood2dType (report to 2d neighborhood models for further informations)
- a maximum distance for polygonal approximation PolygApproxMaxDist (a null value stands for no approximation). This parameter define maximum distance between an original point and resulting shape polygonal approximation.
- a minimum number of points to proceed to polygonal approximation NbMinPointForPolygApprox. This parameter allows to avoid empty polygons on approximation output.
In a standard case where input label image is obtained using IPSDK connected component 2d algorithm, a given label index will be associated to a single shape (used neighborhood 2d type should be the same for connected component 2d and for label shape extraction 2d operations).
In some other cases a given label index may be associated to several "unconnected" components. In this case a label index may be associated to several shapes.
Here is an example of a label shape extraction 2d operation applied to a label input image composed of a single connected component :
- without polygonal approximation (InOptPolygApproxMaxDist == 0)
- with polygonal approximation (InOptPolygApproxMaxDist == 1.5)
Here is an other example of a label shape extraction 2d operation applied to a label input image composed of a single connected component with a hole :
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLAdvancedMorphology as advmorpho
import PyIPSDK.IPSDKIPLShapeSegmentation as shapesegmentation
Code Example
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inLabelImg2d = advmorpho.connectedComponent2dImg(inImg)
outShape2dColl = shapesegmentation.labelShapeExtraction2d(inLabelImg2d)
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLShapeSegmentation/Processor/LabelShapeExtraction2d/LabelShapeExtraction2d.h>
Code Example
ImagePtr pInLabelImg2d =
connectedComponent2dImg(pInBinImg2d, pContourExtractionSettings->getValue<ContourExtractionSettings::Neighborhood2dType>());
Shape2dCollPtr pShape2dColl = labelShapeExtraction2d(pInLabelImg2d, pContourExtractionSettings);