IPSDK 0.2
IPSDK : Image Processing Software Development Kit

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

The GreyInertia measurement computes the second order central moment for each shape, ponderated by the voxels intensities, thanks to the inertia matrix $ M $.

\[ M = \begin{bmatrix} m_{xx} & m_{xy} & m_{xz} \\ m_{yx} & m_{yy} & m_{yz} \\ m_{zx} & m_{zy} & m_{zz} \end{bmatrix} \]

Whose the components are computed as follows :

\[ \begin{array}{r c l} m_{xx} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(x - \bar{x} \right)^2 I(x, y, z)} \\ m_{xy} = m_{yx} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(x - \bar{x} \right) \left(y - \bar{y} \right) I(x, y, z)} \\ m_{xz} = m_{zx} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(x - \bar{x} \right) \left(z - \bar{z} \right) I(x, y, z)} \\ m_{yy} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(y - \bar{y} \right)^2 I(x, y, z)}\\ m_{yz} = m_{zy} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(y - \bar{y} \right) \left(z - \bar{z} \right) I(x, y, z)} \\ m_{zz} = m_{zz} & = & \sum_{\lbrace x, y, z \rbrace \in Shape}{ \left(z - \bar{z} \right) \left(z - \bar{z} \right) I(x, y, z)} \end{array} \]

Where $ I(x, y, z) $ is the image intensity at the position $ (x, y, z) $, $ \bar{x} $ , $ \bar{y} $ and $ \bar{z} $ are the grey barycenter coordinates (see GreyBarycenter) and $ Shape $ is the voxel collection of the current shape.

From these composents, three descriptors are extracted in 2d : the minimum and maximum eigen values of $ M $ ( $ \lambda_{Min} $ and $ \lambda_{Max} $ ) and the shape orientation $ \theta $ .

These features are calculated as follows :

\[ \begin{array}{r c l} \delta & = & \sqrt{(m_{xx} - m_{yy}) (m_{xx} - m_{yy}) + 4 m_{xy} m_{xy}} \\ \lambda_{Max} & = & \frac{1}{2} \left( m_{xx} + m_{yy} + \delta \right) \\ \lambda_{Min} & = & \frac{1}{2} \left( m_{xx} + m_{yy} - \delta \right) \\ \theta & = & \tan^{-1} \left( \frac{\lambda_{Max} - m_{xx}}{m_{xy}} \right) \end{array} \]

$ \lambda_{Min} $ and $ \lambda_{Max} $ are proportional to the squared length of the eigenvector axes, represented by green arrows in the figure below.

greyInertia2dMsr_illustration.png

In 3d case, other features are available. They are calculated as follows :

\[ \begin{array}{r c l} q & = & \frac{m_{xx} + m_{yy} + m_{zz}}{3} \\ p & = & \sqrt{\frac{(m_{xx} - q)^2 + (m_{yy} - q)^2 + (m_{zz} - q)^2 + 2 (m_{xy}^2 + m_{xz}^2 + m_{yz}^2)}{6}} \\ \lambda_{Max} & = & q + 2 p \cos(\phi + 2 \pi / 3) \\ \lambda_{Inter} & = & q + 2 p \cos(\phi - 2 \pi / 3) \\ \lambda_{Min} & = & q + 2 p \cos(\phi) \end{array} \]

Where :

\[ \phi = \begin{cases} \pi/3& \text{if } r \leq -1 \\ 0 & \text{if } r \geq 1\\ \frac{\cos^{-1}(r)}{3} &\text{otherwise} \end{cases} \]

And

\[ r = \frac{(m_{xx} - q)(m_{yy} - q)(m_{zz} - q) + 2 m_{xy} m_{xz}m_{yz} - (m_{yy} - q) m_{xz}^2 - (m_{zz} - q) m_{xy}^2 - (m_{xx} - q) m_{yz}^2}{2 p^3} \]

Moreover, the 2d rotation angle $\theta$ is replaced by the 3d rotation angles $\alpha$, $\beta$ and $\chi$, calculated with the coefficients of $M$ :

\[ \begin{array}{r c l} \alpha & = & \tan^{-1} \left( \frac{m_{yz}}{m_{zz}} \right) \\ \beta & = & - \sin \left( m_{xz} \right) \\ \chi & = & \tan^{-1} \left( \frac{m_{xy}}{m_{xx}} \right) \end{array} \]

Here is an example of the grey inertia calculated from a 2d input image :

greyInertia2dMsr.png

Measure allowing to compute the second order 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, "GreyInertiaMsr")
#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("GreyInertiaMsr")
# retrieve measure values
outMsrValues = outMsr.getMeasureResult().getColl(0)
print("First label inertia mxx component measurement equal " + str(outMsrValues[1].mxx()))

Generic example in 3d case :

import PyIPSDK
import PyIPSDK.IPSDKIPLShapeAnalysis as shapeanalysis
# Create the infoset
inMeasureInfoSet3d = PyIPSDK.createMeasureInfoSet3d()
PyIPSDK.createMeasureInfo(inMeasureInfoSet3d, "GreyInertiaMsr")
#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("GreyInertiaMsr")
# retrieve measure values
outMsrValues = outMsr.getMeasureResult().getColl(0)
print("First label inertia mxx component measurement equal " + str(outMsrValues[1].mxx()))

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>();
readFromXmlFile(inputShape2dCollPath, *pShape2dColl);
// define a measure info set
MeasureInfoSetPtr pMeasureInfoSet = MeasureInfoSet::create2dInstance();
createMeasureInfo(pMeasureInfoSet, "GreyInertiaMsr");
// compute measure on shape 2d collection
MeasureSetPtr pOutMeasureSet = shapeAnalysis2d(pInGreyImg2d, pShape2dColl, pMeasureInfoSet);
// retrieve associated results
const MeasureConstPtr& pGreyInertiaOutMsr = pOutMeasureSet->getMeasure("GreyInertiaMsr");
const GreyInertiaMsrResults& outResults = static_cast<const GreyInertiaMsrResults&>(pGreyInertiaOutMsr->getMeasureResult());