IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

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

IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThreshold (const ipsdk::image::ImageConstPtr &pInImg)
 wrapper function for Kapur binary threshold on one image. In this version of the function, the histogram of the image is automatically computed, with a bin width of 1.0 More...
 
IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThreshold (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::imaproc::attr::HistogramDataPtr &pHistogram)
 wrapper function for computing the Kapur binarythreshold on one image, using the histogram provided as argument More...
 

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

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InImg [Input] image for processing operation X
ipsdk::imaproc::attr::InOutOptHistogram [InOut Optional] histogram properties X
ipsdk::imaproc::attr::OutThreshold [Output] threshold value for image binarization X

Global Rule description

Global rule description for algorithm :
ipsdk::processor::none ()

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

Associated library

IPSDKIPLBinarization

Header file

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);
See also
KapurThresholdLvl1

Function Documentation

◆ kapurThreshold() [1/2]

IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThreshold ( const ipsdk::image::ImageConstPtr pInImg)

wrapper function for Kapur binary threshold on one image. In this version of the function, the histogram of the image is automatically computed, with a bin width of 1.0

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ kapurThreshold() [2/2]

IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThreshold ( const ipsdk::image::ImageConstPtr pInImg,
const ipsdk::imaproc::attr::HistogramDataPtr pHistogram 
)

wrapper function for computing the Kapur binarythreshold on one image, using the histogram provided as argument

Note
the binarized image is not computed
Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure