IPSDK 4.2
IPSDK : Image Processing Software Development Kit
Kittler Threshold computation
scalar = kittlerThreshold (inImg)
scalar = kittlerThreshold (inImg,histogram)

Detailed Description

Computation of the binary threshold on one image, using Kittler method.

Kittler's method is used to automatically perform the binarization of an input image [1]. It assumes that the image is bi-modal (pixel intensities can be distinguished in 2 classes: background pixels and foreground pixels) and that each mode can be approximated by a Gaussian. It then calculates the optimal threshold $t$ that separates these 2 classes, by minimizing the error :

\begin{eqnarray*} E & = & 1 + 2*(P_1(t)*\log(\sigma_1(t)) + P_2(t)*\log(\sigma_2(t)))\\ & & \quad - 2*(P_1(t)*\log(P_1(t)) + P2(t)*\log(P_2(t))) \end{eqnarray*}

Where $P_i$ is the cumulated histogram for the class $i = \left\{1, 2\right\}$ and $sigma_i$ is the associated standard deviation :

\begin{eqnarray*} P_1(t) = & \sum_{i=1}^{t}{h(i)} \qquad & P_2(t) = \sum_{i=t+1}^{N}{h(i)}\\ \mu_1(t) = & \sum_{i=1}^{t}{\frac{h(i) \times i}{P_1(t)}} \qquad & \mu_2(t) = \sum_{i=t+1}^{N}{\frac{h(i) \times i}{P_2(t)}}\\ \sigma_1(t) = & \frac{\sum_{i=1}^{t}{h(i) \times (i-\mu_1(t))^2}}{P_1(t)} \qquad & \sigma_2(t) = \frac{\sum_{i=t+1}^{N}{h(i) \times (i-\mu_2(t))^2}}{P_2(t)} \end{eqnarray*}

With $N$ being the number of pixel in the image and $h(i)$ the histograme value for the intensity $i$.

[1] Kittler, J. & Illingworth, J. Minimum error thresholding Pattern Recognition, 1986, 19, 41 - 47

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLBinarization as bin

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# otsu threshold computation
kapurThresholdValue = bin.kittlerThreshold(inImg)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLBinarization/Processor/KittlerThreshold/KittlerThreshold.h>

Code Example

// open input image
ImageGeometryPtr pInputImageGeometry = geometry2d(inType, sizeX, sizeY);
ImagePtr pInImg = loadRawImageFile(inPath, *pInputImageGeometry);
// Sample calculating automatically the histogram
// ----------------------------------------------
// compute Kittler threshold associated to input image
ipReal64 outThresholdValue = kittlerThreshold(pInImg);
// Sample with the histogram as input parameter
// ----------------------------------------------
// Set the histogram parameters
const ipReal64 min = 50.;
const ipReal64 max = 250.;
const ipReal64 fBinWidth = 2.;
HistoMsrParamsPtr pHistoPrms = createHistoMsrParamsWithBinWidth(min, max, fBinWidth);
// Compute the histogram
HistogramDataPtr pHistogramData = histogramMsr(pInImg, pHistoPrms);
// compute otsu threshold associated to input image
ipReal64 outThresholdValue_manualHisto = kittlerThreshold(pInImg, pHistogramData);