IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Label Analysis 2dSee full documentation
MeasureSet = labelAnalysis2d (inGreyMsrImg,inLabelImg,inMeasureInfoSet2d)
MeasureSet = labelAnalysis2d (inGreyMsrImg,inLabelImg,inOptContourExtractionSettings,inMeasureInfoSet2d)

Detailed Description

Connected component 2d analysis and measurement algorithm.

This algorithm is a simple version of Shape Analysis 2d algorithm. It allows to process measurements and analysis using a label (connected components) image as input which will be proceeded to extract associated 2d shapes (see Label shape extraction 2d).

Note
Note that boundary approximation will only be computed on extracted shapes if the input measure set requests it (ie if at least one mesure among measure set requests it, see Measure requirements).

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

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.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)
# definition of proceeded measure
inMeasureInfoSet2d1 = PyIPSDK.createMeasureInfoSet2d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d1, "AreaMinusHoles", "Area2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(True))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d1, "AreaWithHoles", "Area2dMsr", shapeanalysis.createHolesBasicPolicyMsrParams(False))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d1, "EquivalentRay", "EquivalentRayMsr")
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d1, "SumMsr")
# shape analysis computation
# in this case area measure request boundary approximation of shapes so it will
# be automatically computed
outMeasureSet1 = shapeanalysis.labelAnalysis2d(inGreyImg, inLabelImg2d, inMeasureInfoSet2d1)
# save results to csv format
PyIPSDK.saveCsvMeasureFile(os.path.join(utTmpPath, "shape_analysis_results.csv"), outMeasureSet1)
# retrieve measure results
outAreaMinusHolesMsr = outMeasureSet1.getMeasure("AreaMinusHoles")
outAreaWithHolesMsr = outMeasureSet1.getMeasure("AreaWithHoles")
outEquivalentRayMsr = outMeasureSet1.getMeasure("EquivalentRay")
outSumMsr = outMeasureSet1.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]))
# define a second measure info set which do not implies boundary approximation of shapes
inMeasureInfoSet2d2 = PyIPSDK.createMeasureInfoSet2d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d2, "HistogramQuantileMsr", shapeanalysis.createHistogramQuantileMsrParamsBinWidth(1.0, 25.0))
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d2, "NbPixels2dMsr")
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d2, "MeanMsr")
# in this case area measure request only row intersections of shapes with image so it will
# be automatically computed (boundary approximation are not)
outMeasureSet2 = shapeanalysis.labelAnalysis2d(inGreyImg, inLabelImg2d, inMeasureInfoSet2d2)
# retrieve associated results
outHistogramQuantileMsr = outMeasureSet2.getMeasure("HistogramQuantileMsr")
outNbPixels2dMsr = outMeasureSet2.getMeasure("NbPixels2dMsr")
outMeanMsr = outMeasureSet2.getMeasure("MeanMsr")

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLShapeAnalysis/Processor/LabelAnalysis2d/LabelAnalysis2d.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);
// define a measure info set
MeasureInfoSetPtr pMeasureInfoSet1 = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet1, "AreaMinusHoles", "Area2dMsr", createHolesBasicPolicyMsrParams(true));
createMeasureInfo(pMeasureInfoSet1, "AreaWithHoles", "Area2dMsr", createHolesBasicPolicyMsrParams(false));
createMeasureInfo(pMeasureInfoSet1, "EquivalentRay", "EquivalentRayMsr");
createMeasureInfo(pMeasureInfoSet1, "SumMsr");
// compute measure on extracted data
// in this case area measure request boundary approximation of shapes so it will
// be automatically computed
MeasureSetPtr pOutMeasureSet1 = labelAnalysis2d(pInGreyImg2d, pInLabelImg2d, pMeasureInfoSet1);
// complete csv dump of results
saveCsvMeasureFile(csvOutputPath, *pOutMeasureSet1);
// retrieve associated results
const MeasureConstPtr& pAreaMinusHolesOutMsr = pOutMeasureSet1->getMeasure("AreaMinusHoles");
const MeasureConstPtr& pAreaWithHolesOutMsr = pOutMeasureSet1->getMeasure("AreaWithHoles");
const MeasureConstPtr& pEquivalentRayOutMsr = pOutMeasureSet1->getMeasure("EquivalentRay");
const MeasureConstPtr& pSumOutMsr = pOutMeasureSet1->getMeasure("SumMsr");
// define a second measure info set which do not implies boundary approximation of shapes
MeasureInfoSetPtr pMeasureInfoSet2 = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet2, "HistogramQuantileMsr", createHistogramQuantileMsrParamsBinWidth(1.0, 25.0));
createMeasureInfo(pMeasureInfoSet2, "NbPixels2dMsr");
createMeasureInfo(pMeasureInfoSet2, "MeanMsr");
// compute measure on extracted data
// in this case area measure request only row intersections of shapes with image so it will
// be automatically computed (boundary approximation are not)
MeasureSetPtr pOutMeasureSet2 = labelAnalysis2d(pInGreyImg2d, pInLabelImg2d, pMeasureInfoSet2);
// retrieve associated results
const MeasureConstPtr& pHistogramQuantileOutMsr = pOutMeasureSet2->getMeasure("HistogramQuantileMsr");
const MeasureConstPtr& pNbPixels2dOutMsr = pOutMeasureSet2->getMeasure("NbPixels2dMsr");
const MeasureConstPtr& pMeanOutMsr = pOutMeasureSet2->getMeasure("MeanMsr");