IPSDK 4.1
IPSDK : Image Processing Software Development Kit
Counting 2d objects
scalarcounting2dMsr (inLabelImg)

Detailed Description

Count the number of objects in the image.

This algorithm simply computes the number of objects in the input label image. If an image with 3 dimensions or more is provided, the algorithms returns the number of objects for each slice of each dimension.

Here is an example of result :

counting2d.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLGlobalMeasure as glbmsr

Code Example

# measurement for a single slice
result = glbmsr.counting2dMsr(inLabelImg)
# retrieve measurement results
print("The number of objects is " + str(result))
# measurement for a multi-slice case
planIndexedResult = glbmsr.multiSlice_counting2dMsr(inLabelImg_multiSlice)
# retrieve measurement results
resSlice = PyIPSDK.toPyDict(planIndexedResult)[(1, 0, 0)]
print("The number of objects in the second slice is " + str(resSlice["Value"]))

Example of C++ code :

Example informations

Header file

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

Code Example

// -------------------------------------------------------
// Case of monoslice calculation
const ipUInt64 count_monoSlice = counting2dMsr(pLabelImg);
// -------------------------------------------------------
// Case of multislice calculation
const PlanIndexedIndexableUInt64Ptr pPICounts = multiSlice_counting2dMsr(pLabelImg_multiSlice);
const ipUInt64 countAtSlice1 = pPICounts->getValue(1, 0, 0).getValue<IndexableUInt64::Value>();