IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Area Percent 2d measurementSee full documentation
DoublesareaPercent2dMsr (inImg)
DoublesareaPercent2dMsr (inImg,inMaskImg)

Detailed Description

Computes the ratio between the number of pixels and the total image size.

This algorithm computes the ratio between the 2D objects surfaces and the total image area. Let AreaPercent(i) be the result for the ith object, Area(i) its area and (sizeX, sizeY) the image size, the calculation can be expressed as follows:

\[ AreaPercent(i) = \frac{Area(i)}{sizeX \times sizeY} \]

In the case of binary images, the result contains the area ratio for the background (pixels set to 0) at index 0 and the area ratio for the foreground (pixels set to 1) at index 1.

In the case of label images, the result contains the area ratio for the background (pixels set to 0) at index 0 and then the area ratio for each label.

Here is an example of result for a label image:

areaPercent2d.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inImg_multiSlice = PyIPSDK.loadTiffImageFile(inputImgPath_multiSlice)
# measurement for a single slice
result = glbmsr.areaPercent2dMsr(inImg)
# retrieve measurement results
print("Area percent for the first shape is " + str(result.coll[1]))
# measurement for a multi-slice case
planIndexedResult = glbmsr.multiSlice_areaPercent2dMsr(inImg_multiSlice)
# retrieve measurement results
resSlice1 = PyIPSDK.toPyDict(planIndexedResult)[(0, 0, 1)]
print("Area percent for the second slice is " + str(resSlice1["Coll"]))

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLGlobalMeasure/Processor/AreaPercent2dMsr/AreaPercent2dMsr.h>

Code Example

// ------------ Calculation on a mono-slice grey level image ------------ //
// Compute area percents on the mono-slice input image
DoublesPtr pResult = areaPercent2dMsr(pInImg);
// Retrieve the results as scalar variables
// pResBinary contains 2 values for binary input images : vResult[0] for background and vResult[1] for foreground
// and nbLabels + 1 values to include the background
const std::vector<ipReal64>& vResult = pResult->getLeafColl<Doubles::Coll>();
// --------------- Calculation on a multi-slice sequence image -------------- //
// Compute area percents on the monoslice input binary image
PlanIndexedDoublesPtr pResult_multiSlice = multiSlice_areaPercent2dMsr(pInImg_multiSlice);
// Retrieve the results as scalar variables for z = 1
const ipUInt64 t = 1;
const std::vector<ipReal64>& vResult_multiSlice = pResult_multiSlice->getValue(0, 0, t).getNode<Doubles::Coll>().getColl();