Doubles = | areaPercent2dMsr (inImg) |
Doubles = | areaPercent2dMsr (inImg,inMaskImg) |
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:
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:
Example of Python code :
Example imports
import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr
Code Example
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inImg_multiSlice = PyIPSDK.loadTiffImageFile(inputImgPath_multiSlice)
result = glbmsr.areaPercent2dMsr(inImg)
print("Area percent for the first shape is " + str(result.coll[1]))
planIndexedResult = glbmsr.multiSlice_areaPercent2dMsr(inImg_multiSlice)
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
const std::vector<ipReal64>& vResult = pResult->getLeafColl<Doubles::Coll>();
PlanIndexedDoublesPtr pResult_multiSlice = multiSlice_areaPercent2dMsr(pInImg_multiSlice);
const ipUInt64 t = 1;
const std::vector<ipReal64>& vResult_multiSlice = pResult_multiSlice->getValue(0, 0, t).getNode<Doubles::Coll>().getColl();