IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Shape Analysis 2dSee full documentation
typedef ShapeAnalysisOptParams< ipsdk::shape::segmentation::Shape2dColl > ipsdk::imaproc::shape::analysis::ShapeAnalysis2dOptParams
typedef ShapeAnalysisOptParams< ipsdk::shape::segmentation::PlanIndexedShape2dColl > ipsdk::imaproc::shape::analysis::ShapeAnalysis2dPIOptParams
MeasureSet = shapeAnalysis2d (inOptGreyMsrImg1,inLabelsShape2d,inMeasureInfoSet2d)
MeasureSet = shapeAnalysis2d (inMeasureInfoSet2d,inLabelsShape2d,shapeAnalysis2dOptParams)

Detailed Description

Shape 2d analysis and measurement algorithm.

This algorithm allows to process measurements and analysis on shape 2d connected components.

User should first extract contours on a connected component label image (see Label shape extraction 2d).

For more information on shape analysis and measurement framework, please refers to Shape Analysis and Measurement.

Shape 2d measurements and analysis can be decomposed in three main groups :

Here is an example of shape 2d measurement and analysis :

shapeAnalysis2d.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLAdvancedMorphology as advmorpho
import PyIPSDK.IPSDKIPLShapeSegmentation as shapesegmentation
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis

Code Example

# opening of input images
inGreyImg = PyIPSDK.loadTiffImageFile(inputGreyImgPath)
inBinImg = PyIPSDK.loadTiffImageFile(inputBinImgPath)
# connected components analysis of binary image
inLabelImg2d = advmorpho.connectedComponent2dImg(inBinImg)
# label contour extraction computation
inShape2dColl = shapesegmentation.labelShapeExtraction2d(inLabelImg2d)
# definition of proceeded measure
inMeasureInfoSet2d = PyIPSDK.createMeasureInfoSet2d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "AreaMinusHoles", "PolygonArea2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(True))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "AreaWithHoles", "PolygonArea2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(False))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "EquivalentRay", "EquivalentRayMsr")
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "SumMsr")
# shape analysis computation
outMeasureSet = shapeanalysis.shapeAnalysis2d(inGreyImg, inShape2dColl, inMeasureInfoSet2d)
# save results to csv format
PyIPSDK.saveCsvMeasureFile(os.path.join(utTmpPath, "shape_analysis_results.csv"), outMeasureSet)
# retrieve measure results
outAreaMinusHolesMsr = outMeasureSet.getMeasure("AreaMinusHoles")
outAreaWithHolesMsr = outMeasureSet.getMeasure("AreaWithHoles")
outEquivalentRayMsr = outMeasureSet.getMeasure("EquivalentRay")
outSumMsr = outMeasureSet.getMeasure("SumMsr")
# retrieve measure valus for area with holes measurement
outAreaWithHolesValues = outAreaWithHolesMsr.getMeasureResult().getColl(0)
print("First label area with holes measurement equal " + str(outAreaWithHolesValues[1]))

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLShapeAnalysis/Processor/ShapeAnalysis2d/ShapeAnalysis2d.h>

Code Example

// opening grey level input image
ImagePtr pInGreyImg2d = loadTiffImageFile(inputGreyImgPath);
// opening binary input image
ImagePtr pInBinImg2d = loadTiffImageFile(inputBinImgPath);
// connected components analysis
ImagePtr pInLabelImg2d = connectedComponent2dImg(pInBinImg2d);
// extract contours from connected component (label) image
Shape2dCollPtr pShape2dColl = labelShapeExtraction2d(pInLabelImg2d);
// define a measure info set
MeasureInfoSetPtr pMeasureInfoSet = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet, "AreaMinusHoles", "PolygonArea2dMsr", createHolesBasicPolicyMsrParams(true));
createMeasureInfo(pMeasureInfoSet, "AreaWithHoles", "PolygonArea2dMsr", createHolesBasicPolicyMsrParams(false));
createMeasureInfo(pMeasureInfoSet, "EquivalentRay", "EquivalentRayMsr");
createMeasureInfo(pMeasureInfoSet, "SumMsr");
// compute measure on extracted data
MeasureSetPtr pOutMeasureSet = shapeAnalysis2d(pInGreyImg2d, pShape2dColl, pMeasureInfoSet);
// complete csv dump of results
saveCsvMeasureFile(csvOutputPath, *pOutMeasureSet);
// retrieve associated results
const MeasureConstPtr& pAreaMinusHolesOutMsr = pOutMeasureSet->getMeasure("AreaMinusHoles");
const MeasureConstPtr& pAreaWithHolesOutMsr = pOutMeasureSet->getMeasure("AreaWithHoles");
const MeasureConstPtr& pEquivalentRayOutMsr = pOutMeasureSet->getMeasure("EquivalentRay");
const MeasureConstPtr& pSumOutMsr = pOutMeasureSet->getMeasure("SumMsr");