IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Image posterization from k-means results algorithmSee full documentation
imagekMeansPosterizeImg (inImg,classImg,clustersCenters)
imagekMeansPosterizeImg (inImg,classImg,maskImg,clustersCenters)

Detailed Description

Posterize an image using the results from k-means algorithm.

Fills the output image (that must have the same geometry as the input one), by replacing each pixel value of the input image ( $InImg$) with the value of the center of the cluster which it belongs to. Values of clusters centers are defined by $InClustersPptiesColl$ attribute, and input image clustering is defined by $InClassImg$ attribute. These 2 attributes are usually initialized using K-means algorithm.

Here is an example of posterization algorithm applied to Lena RGB image and to results of K-Means algorithm application (4 clusters expected):

KMeansPosterizeImg.png

It is also possible to provide a mask image. In this case, the posterized image will have a value of 0 where the mask equals False. Here is an example of masked posterization:

KMeansPosterizeImg_mask.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLClassification as classif

Code Example

# load input data from files
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
inClustersCenters, bReadRes = PyIPSDK.readFromXmlFile(inClustersCentersPath)
inClassImg = PyIPSDK.loadTiffImageFile(inClassImgPath)
# apply posterization algorithm, and get posterized image
autoInitializedOutImg = classif.kMeansPosterizeImg(inImg, inClassImg, inClustersCenters)

Example of C++ code :

Example informations

Header file

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

Code Example

// load input image from file
ImagePtr pInImg = loadTiffImageFile(inputImgPath);
// load input class image from file
ImagePtr pInClassImg = loadTiffImageFile(inClassImgFilePath);
// load clusters centers
ClustersCentersPtr pInClustersCenters = boost::make_shared<ClustersCenters>();
readFromXmlFile(inCentersFilePath, *pInClustersCenters);
// apply posterization algorithm on input data, and get posterized image
ImagePtr pOutImg = classif::kMeansPosterizeImg(pInImg, pInClassImg, pInClustersCenters);