IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Clusters assignment algorithm (clusters centroids given in input)See full documentation
imagekMeansAssignImg (inImg,inClustersCenters)
imagekMeansAssignImg (inImg,maskImg,inClustersCenters)

Detailed Description

Clusters pixels of an input image based on minimum distance, given a set of clusters centroids.

This algorithm clusters pixels of an input image to clusters given clusters centroids.

Considering 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); for each data vector of the image, the algorithm assigns the cluster, the closest centroid to the data vector currently considered, based on the euclidean distance computed between data vectors and centroid vectors, both of dimensions c*t.

Note
This algorithm is also used during the "assignment" step of the K-means algorithm.

Input and output attributes of the algorithm are:

Here is an example of clusters assignment algorithm applied to Lena RGB image, with 4 clusters centers: (223, 136, 126), (61, 3, 28) , (237, 230, 224) and (109, 69, 131):

KMeansAssignImg.png

In this figure, the first label (in black) has a value of 1. The label 0 corresponds to the case where a pixel/voxel has a value of False in the optional input mask image, is provided.

Here is an example of cluster assignment, by taking into account a mask with the centers (223, 136, 126), (61, 3, 28) , (237, 230, 224) and (109, 69, 131). In this case, black pixels in the label image correspond to black pixels in the mask image:

KMeansAssignImg_mask.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLClassification as classif

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# initialize input clusters centers (4 centers of dimension 3)
inClustersCenters = PyIPSDK.createClustersCenters([223.0, 136.0, 126.0, 61.0, 3.0, 28.0, 237.0, 230.0, 224.0, 109.0, 69.0, 131.0], 3)
# apply assignment algorithm
outClassImg = classif.kMeansAssignImg(inImg, inClustersCenters)

Example of C++ code :

Example informations

Header file

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

Code Example

// load input image from file
ImagePtr pInImg = loadTiffImageFile(inputImgPath);
// load input clusters centers from file
ClustersCentersPtr pInClustersCenters = boost::make_shared<ClustersCenters>();
readFromXmlFile(inputClustersCentersPath, *pInClustersCenters);
// apply clusters assignment algorithm
const ImagePtr pOutClassImg = classif::kMeansAssignImg(pInImg, pInClustersCenters);