Shape 2d area measurement (measure based on polygonal approximation)
Area2d measure is based on polygonal approximation of shapes. It computes area of polygons using Surveyor's triangulation algorithm.
Note that shape 2d area and number of pixels may differ since area is computed with respect to a given polygonal approximation while the number of pixels only take care of the initial image binary shape.
Here is an example of area 2d measurement :
Shape 2d area measurement (measure based on polygonal approximation)
Measure synthesis :
Measure Type | Measure Unit Type | Parameter Type | Result Type | Shape Requirements |
Geometry 2d
|
Area
|
PolygonArea2dMsrParams |
Value (ipsdk::ipReal64)
|
Boundary Approximation
|
See Shape measurement for additional information on these pictograms Example of Python code :
Generic example in 2d case :
import PyIPSDK
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis
inMeasureInfoSet2d = PyIPSDK.createMeasureInfoSet2d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "AreaMinusHoles", "PolygonArea2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(True))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "AreaWithHoles", "PolygonArea2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(False))
outMeasureSet = shapeanalysis.labelAnalysis2d(inGreyImg, inLabelImg2d, inMeasureInfoSet2d)
PyIPSDK.saveCsvMeasureFile(os.path.join(tmpPath, "shape_analysis_results.csv"), outMeasureSet)
outAreaMinusHolesMsr = outMeasureSet.getMeasure("AreaMinusHoles")
outAreaWithHolesMsr = outMeasureSet.getMeasure("AreaWithHoles")
outAreaWithHolesValues = outAreaWithHolesMsr.getMeasureResult().getColl(0)
print("First label area with holes measurement equal " + str(outAreaWithHolesValues[1]))
Example of C++ code :
Example informations
Associated library
IPSDKIPLShapeAnalysis
Code Example
Shape2dCollPtr pShape2dColl = boost::make_shared<Shape2dColl>();
IPSDK_REQUIRE(readFromXmlFile(inputShape2dCollPath, *pShape2dColl) == true);
MeasureInfoSetPtr pMeasureInfoSet = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet, "PolygonArea2dMsr", createHolesBasicPolicyMsrParams(bProcessHoles));
MeasureSetPtr pOutMeasureSet =
shapeAnalysis2d(pInGreyImg2d, pShape2dColl, pMeasureInfoSet);
const MeasureConstPtr& pPolygonArea2dOutMsr = pOutMeasureSet->getMeasure("PolygonArea2dMsr");
const ipsdk::shape::analysis::ValueMeasureResult<ipsdk::ipReal64>& outResults = static_cast<const ipsdk::shape::analysis::ValueMeasureResult<ipsdk::ipReal64>&>(pPolygonArea2dOutMsr->getMeasureResult());