IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Image posterization from k-means results algorithm

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

IPSDKIPLCLASSIFICATION_API image::ImagePtr ipsdk::imaproc::classif::kMeansPosterizeImg (const image::ImageConstPtr &pInImg, const image::ImageConstPtr &pClassImg, const ipsdk::imaproc::attr::ClustersCentersConstPtr &pClustersCenters)
 wrapper function for Posterize an image using the results from k-means algorithm More...
 
IPSDKIPLCLASSIFICATION_API image::ImagePtr ipsdk::imaproc::classif::kMeansPosterizeImg (const image::ImageConstPtr &pInImg, const image::ImageConstPtr &pClassImg, const ipsdk::image::ImageConstPtr &pMaskImg, const ipsdk::imaproc::attr::ClustersCentersConstPtr &pClustersCenters)
 wrapper function for Posterize an image using the results from k-means algorithm More...
 
IPSDKIPLCLASSIFICATION_API void ipsdk::imaproc::classif::kMeansPosterizeImg (const image::ImageConstPtr &pInImg, const image::ImageConstPtr &pClassImg, const ipsdk::imaproc::attr::ClustersCentersConstPtr &pClustersCenters, const image::ImagePtr &pOutImg)
 wrapper function for Posterize an image using the results from k-means algorithm More...
 
IPSDKIPLCLASSIFICATION_API void ipsdk::imaproc::classif::kMeansPosterizeImg (const image::ImageConstPtr &pInImg, const image::ImageConstPtr &pClassImg, const ipsdk::image::ImageConstPtr &pMaskImg, const ipsdk::imaproc::attr::ClustersCentersConstPtr &pClustersCenters, const image::ImagePtr &pOutImg)
 wrapper function for Posterize an image using the results from k-means algorithm More...
 

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

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InHomogeneousImg [Input] Homogeneous image X
ipsdk::imaproc::attr::InClustersCenters [Input] centers of clusters X
ipsdk::imaproc::attr::InClassImg [Input] Image of classes X
ipsdk::imaproc::attr::InOptSingleGreyMaskImg [Input Optional] Binary image for masking operation for each (x, y, z) coordinate regardless to (c, t) coordinates X
ipsdk::imaproc::attr::OutPosterizedImg [Output] PosterizedImg ipsdk::imaproc::duplicateInOut (_pOutPosterizedImg, _pInHomogeneousImg)

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::matchSize (eMatchImageSizeType::eMIST_3d,_pInHomogeneousImg,_pInClassImg) && 
ipsdk::imaproc::classif::clustersCentersCollMatchImgSize (_pInClustersCenters,_pInHomogeneousImg) && 
ipsdk::imaproc::matchSizeAndType (_pInHomogeneousImg,_pOutPosterizedImg) && 
ipsdk::processor::If (
 ipsdk::processor::isSet (_pInOptSingleGreyMaskImg),
 ipsdk::imaproc::matchSize (eMatchImageSizeType::eMIST_3d,_pInHomogeneousImg,_pInOptSingleGreyMaskImg),
 ipsdk::processor::none ())

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

Associated library

IPSDKIPLClassification

Header file

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);
See also
KMeansPosterizeImgLvl1
KMeansPosterizeImgLvl2
KMeansPosterizeImgLvl3

Function Documentation

◆ kMeansPosterizeImg() [1/4]

IPSDKIPLCLASSIFICATION_API image::ImagePtr ipsdk::imaproc::classif::kMeansPosterizeImg ( const image::ImageConstPtr pInImg,
const image::ImageConstPtr pClassImg,
const ipsdk::imaproc::attr::ClustersCentersConstPtr pClustersCenters 
)

wrapper function for Posterize an image using the results from k-means algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ kMeansPosterizeImg() [2/4]

IPSDKIPLCLASSIFICATION_API image::ImagePtr ipsdk::imaproc::classif::kMeansPosterizeImg ( const image::ImageConstPtr pInImg,
const image::ImageConstPtr pClassImg,
const ipsdk::image::ImageConstPtr pMaskImg,
const ipsdk::imaproc::attr::ClustersCentersConstPtr pClustersCenters 
)

wrapper function for Posterize an image using the results from k-means algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ kMeansPosterizeImg() [3/4]

IPSDKIPLCLASSIFICATION_API void ipsdk::imaproc::classif::kMeansPosterizeImg ( const image::ImageConstPtr pInImg,
const image::ImageConstPtr pClassImg,
const ipsdk::imaproc::attr::ClustersCentersConstPtr pClustersCenters,
const image::ImagePtr pOutImg 
)

wrapper function for Posterize an image using the results from k-means algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ kMeansPosterizeImg() [4/4]

IPSDKIPLCLASSIFICATION_API void ipsdk::imaproc::classif::kMeansPosterizeImg ( const image::ImageConstPtr pInImg,
const image::ImageConstPtr pClassImg,
const ipsdk::image::ImageConstPtr pMaskImg,
const ipsdk::imaproc::attr::ClustersCentersConstPtr pClustersCenters,
const image::ImagePtr pOutImg 
)

wrapper function for Posterize an image using the results from k-means algorithm

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure