Compute clusters centroids given an input image and the image of classes.
Consider:
- an image of size (x, y, z, c, t) (with x, y and z the sizes respectively along x, y and z-axis, c the number of color channels and t the number of elements in temporal sequence) as a set of x*y*z data vector of c*t dimension, and a set of n clusters of dimensions c*t (n > 1),
- and an image of size (x, y ,z) giving the class of each data vector.
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:
: the input image of data vectors,
: image giving, for each data vector, the class which it belongs to; this image must be a single grey-level image, and it must have same size than
along x, y and z axis,
: total number of clusters; if not intialized, this number is computed by the algorithm from the InClassImg, which may require a little bit more time,
: collection of clusters properties computed by the algorithm, namely:
- clusters centers,
- clusters standard deviations for each dimension,
- clusters compactnesses; a cluster compactness equals to the sum of the squared distances between the cluster center and all the clusters elements,
- global compactnesses, that is the sum of all clusters compactnesses,
: optional; collection of population per cluster.
- 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
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inClassImg = PyIPSDK.loadTiffImageFile(inputClassImgPath)
outClustersCenters = classif.kMeansComputeCenters(inImg, inClassImg)
firstClusterCenter = outClustersCenters.coll[0].elements
Example of C++ code :
Example informations
Header file
#include <IPSDKIPL/IPSDKIPLClassification/Processor/KMeansComputeCenters/KMeansComputeCenters.h>
Code Example
const ipUInt64 nbExpectedClusters = 4;
ClustersCentersPtr pOutClustersCenters = classif::kMeansComputeCenters(pInImg, pInClassImg, nbExpectedClusters);
ClusterCenterPtr clusterCenter = pOutClustersCenters->getNodeColl<ClustersCenters::Coll>()[0];
const std::vector<ipReal64>& vRandomClusterElements = clusterCenter->getLeafColl<ClusterCenter::Elements>();