IPSDK 4.1.0.2
IPSDK : Image Processing Software Development Kit
Clusters centroids computation algorithm
ClustersCenterskMeansComputeCenters (inImg,classImg)
ClustersCenterskMeansComputeCenters (inImg,classImg,maskImg)
ClustersCenterskMeansComputeCenters (inImg,classImg,nbClusters)
ClustersCenterskMeansComputeCenters (inImg,classImg,maskImg,nbClusters)

Detailed Description

Compute clusters centroids given an input image and the image of classes.

Consider:

The algorithm computes the properties of each cluster, namely the centroids, the standard deviation along each dimension and the compactness. For empty clusters, centroids coordinates are set to 0.

Input and output attributes of the algorithm are:

Note
A mask can be provided to use only a subset of pixels/voxels during the calculation.

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLClassification as classif

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# opening of input class image
inClassImg = PyIPSDK.loadTiffImageFile(inputClassImgPath)
# apply "compute centers" algorithm
outClustersCenters = classif.kMeansComputeCenters(inImg, inClassImg)
# Access to the first cluster center
firstClusterCenter = outClustersCenters.coll[0].elements

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLClassification/Processor/KMeansComputeCenters/KMeansComputeCenters.h>

Code Example

ImagePtr pInImg = loadTiffImageFile(inputImgPath);
ImagePtr pInClassImg = loadTiffImageFile(inputClassImgPath);
const ipUInt64 nbExpectedClusters = 4;
// apply clusters centers computation algorithm
ClustersCentersPtr pOutClustersCenters = classif::kMeansComputeCenters(pInImg, pInClassImg, nbExpectedClusters);
// Access to the first generated cluster center elements
ClusterCenterPtr clusterCenter = pOutClustersCenters->getNodeColl<ClustersCenters::Coll>()[0];
const std::vector<ipReal64>& vRandomClusterElements = clusterCenter->getLeafColl<ClusterCenter::Elements>();