IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

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

IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::DoublesPtr ipsdk::imaproc::glbmsr::areaPercent2dMsr (const ipsdk::image::ImageConstPtr &pInImg)
 wrapper function for Computes the ratio between the number of pixels and the total image size. More...
 
IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::DoublesPtr ipsdk::imaproc::glbmsr::areaPercent2dMsr (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::image::ImageConstPtr &pInMaskImg)
 wrapper function for Computes the ratio between the number of pixels and the total image size. More...
 
IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::PlanIndexedDoublesPtr ipsdk::imaproc::glbmsr::multiSlice_areaPercent2dMsr (const ipsdk::image::ImageConstPtr &pInImg)
 wrapper function for Computes the ratio between the number of pixels and the total image size. More...
 
IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::PlanIndexedDoublesPtr ipsdk::imaproc::glbmsr::multiSlice_areaPercent2dMsr (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::image::ImageConstPtr &pInMaskImg)
 wrapper function for Computes the ratio between the number of pixels and the total image size. More...
 

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

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InBinLabImg [Input] binary or label image for processing operation X
ipsdk::imaproc::attr::InOptMaskImg [Input Optional] Binary image for masking operation X
ipsdk::imaproc::attr::OutPIValues [Output] plan indexed collection of values ipsdk::imaproc::fromImage (_pOutPIValues, _pInBinLabImg)

Global Rule description

Global rule description for algorithm :
ipsdk::processor::If (
 ipsdk::processor::isSet (_pInOptMaskImg),
 ipsdk::imaproc::matchSize (_pInBinLabImg,_pInOptMaskImg),
 ipsdk::processor::none ()) && 
ipsdk::imaproc::matchImagePlans (_pOutPIValues,_pInBinLabImg,eImagePlansMatchPolicy::eIPMP_ZCT)

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

Associated library

IPSDKIPLGlobalMeasure

Header file

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();
See also
AreaPercent2dMsrLvl1
AreaPercent2dMsrLvl2
AreaPercent2dMsrLvl3

Function Documentation

◆ areaPercent2dMsr() [1/2]

IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::DoublesPtr ipsdk::imaproc::glbmsr::areaPercent2dMsr ( const ipsdk::image::ImageConstPtr pInImg)

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

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ areaPercent2dMsr() [2/2]

IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::DoublesPtr ipsdk::imaproc::glbmsr::areaPercent2dMsr ( const ipsdk::image::ImageConstPtr pInImg,
const ipsdk::image::ImageConstPtr pInMaskImg 
)

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

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ multiSlice_areaPercent2dMsr() [1/2]

IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::PlanIndexedDoublesPtr ipsdk::imaproc::glbmsr::multiSlice_areaPercent2dMsr ( const ipsdk::image::ImageConstPtr pInImg)

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

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ multiSlice_areaPercent2dMsr() [2/2]

IPSDKIPLGLOBALMEASURE_API ipsdk::imaproc::attr::PlanIndexedDoublesPtr ipsdk::imaproc::glbmsr::multiSlice_areaPercent2dMsr ( const ipsdk::image::ImageConstPtr pInImg,
const ipsdk::image::ImageConstPtr pInMaskImg 
)

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

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure