IPSDK 0.2
IPSDK : Image Processing Software Development Kit

Measure allowing to compute the zeroth to the third moment ponderated by the gray level of each pixel for shape.

The GreyMoments measurement computes the $0^{th}$, $1^{st}$, $2^{nd}$ and $3^{rd}$ order scale-invariant central moment for each shape, ponderated by the voxels intensities.

The central moment $m_{ij}$ for a given 2d shape $Shape$ are computed by :

\[ m_{ij} = \sum_{\lbrace x, y \rbrace \in Shape}{ \left(x - \bar{x} \right)^i \left(y - \bar{y} \right)^j I(x, y)} \]

Where $\left(\bar{x}, \bar{y}\right)$ are the coordinates of the shape grey barycenter (see GreyBarycenter).

The corresponding scale-invariant central moment $\mu_{ij}$ is calculated by normalizing $m_{ij}$ as follows : The central moment $m_{ij}$ for a given 2d shape $Shape$ are computed by :

\[ \mu_{ij} = \frac{m_{ij}}{m^{1 + \left(i+j \right)/2}_{00}} \]

The central grey moments for a 3d shape are computed using the same formula, using the z-axis in addition to the x and y axises [1] :

\[ m_{ijk} = \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(x - \bar{x} \right)^i \left(y - \bar{y} \right)^j \left(z - \bar{z} \right)^k I(x, y)} \]

Where the grey 3d shape barycenter has coordinates $\left(\bar{x}, \bar{y}, \bar{z}\right)$.

The scale-invariant 3d moments can be obtained with the following equation :

\[ \mu_{ijk} = \frac{m_{ijk}}{m^{1 + \left(i+j+k \right)/3}_{000}} \]

Here is an example of 2d grey moment measurement :

greyMomentsMsr.png

References

[1] "Moments and Moment Invariants in Pattern Recognition, Chap. 2 Moment Invariants to Translation, Rotation and Scaling",Flusser, J.; Suk, T. & Zitova, B., John Wiley & Sons, Ltd, 2009, 13-47

Measure allowing to compute the zeroth to the third moment ponderated by the gray level of each pixel for shape

Measure synthesis :

Measure Type Measure Unit Type Parameter Type Result Type Shape Requirements
Intensity.png
Intensity
none.png
None
none.png
None
Custom.png
Custom
RowIntersections.png
Row Intersections
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
# Create the infoset
inMeasureInfoSet2d = PyIPSDK.createMeasureInfoSet2d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet2d, "GreyMomentsMsr")
#Perform the analysis
outMeasureSet = shapeanalysis.labelAnalysis2d(inGreyImg, inLabelImg2d, inMeasureInfoSet2d)
# save results to csv format
PyIPSDK.saveCsvMeasureFile(os.path.join(tmpPath, "shape_analysis_results.csv"), outMeasureSet)
# retrieve measure results
outMsr = outMeasureSet.getMeasure("GreyMomentsMsr")
# retrieve measure values
outMsrValues = outMsr.getMeasureResult().getColl(0)
print("First label first grey moment measurement equal " + str(outMsrValues[1].getMoment(shapeanalysis.GreyMomentsData.eGreyMoment3Id.eGM3I_X0Y0Z0)))

Generic example in 3d case :

import PyIPSDK
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis
# Create the infoset
inMeasureInfoSet3d = PyIPSDK.createMeasureInfoSet3d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet3d, "GreyMomentsMsr")
#Perform the analysis
outMeasureSet = shapeanalysis.labelAnalysis3d(inGreyImg, inLabelImg, inMeasureInfoSet3d)
# save results to csv format
PyIPSDK.saveCsvMeasureFile(os.path.join(tmpPath, "shape_analysis_results.csv"), outMeasureSet)
# retrieve measure results
outMsr = outMeasureSet.getMeasure("GreyMomentsMsr")
# retrieve measure values
outMsrValues = outMsr.getMeasureResult().getColl(0)
print("First label (X0, Y0, Z0) moment measurement equal " + str(outMsrValues[1].getMoment(shapeanalysis.GreyMomentsData.eGreyMoment3Id.eGM3I_X0Y0Z0)))

Example of C++ code :

Example informations

Associated library

IPSDKIPLShapeAnalysis

Code Example

// opening grey level input image
ImagePtr pInGreyImg2d = loadTiffImageFile(inputGreyImgPath);
// read entity shape 2d collection used for processing
Shape2dCollPtr pShape2dColl = boost::make_shared<Shape2dColl>();
IPSDK_REQUIRE(readFromXmlFile(inputShape2dCollPath, *pShape2dColl) == true);
// define a measure info set
MeasureInfoSetPtr pMeasureInfoSet = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet, "GreyMomentsMsr");
// compute measure on shape 2d collection
MeasureSetPtr pOutMeasureSet = shapeAnalysis2d(pInGreyImg2d, pShape2dColl, pMeasureInfoSet);
// retrieve associated results
const MeasureConstPtr& pGreyMomentsOutMsr = pOutMeasureSet->getMeasure("GreyMomentsMsr");
const GreyMomentsMsrResults& outResults = static_cast<const GreyMomentsMsrResults&>(pGreyMomentsOutMsr->getMeasureResult());