IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Kapur Threshold computationSee full documentation
scalarkapurThreshold (inImg)
scalarkapurThreshold (inImg,histogram)

Detailed Description

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

Kapur's method is used to automatically perform the binarization of an input image. It assumes that the image is bi-modal (pixel intensities can be distinguished in 2 classes: background pixels and foreground pixels). It then calculates the optimal threshold that separates these 2 classes, by maximizing the sum of their entropies [1].

[1] Kapur, J.; Sahoo, P. & Wong, A., "A new method for gray-level picture thresholding using the entropy of the histogram", Computer Vision, Graphics, and Image Processing, 1985, 29, 273 - 285

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.kapurThreshold(inImg)

Example of C++ code :

Example informations

Header file

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

Code Example

// open input image
ImageGeometryPtr pInputImageGeometry = geometry2d(inType, sizeX, sizeY);
ImagePtr pInImg = loadRawImageFile(inPath, *pInputImageGeometry);
// Sample calculating automatically the histogram
// ----------------------------------------------
// compute Kapur threshold associated to input image
ipReal64 outThresholdValue = kapurThreshold(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 = kapurThreshold(pInImg, pHistogramData);