IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

Compute the Kapur threshold of an input image, and binarize the image using this threshold. More...

IPSDKIPLBINARIZATION_API KapurResult ipsdk::imaproc::bin::kapurThresholdImg (const ipsdk::image::ImageConstPtr &pInImg)
 wrapper function for binarization on one image using Kapur's method. 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::kapurThresholdImg (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::image::ImagePtr &pOutBinImg)
 wrapper function for binarization on one image using Kapur's method. In this version of the function, the histogram of the image is automatically computed, with a bin width of 1.0 More...
 
IPSDKIPLBINARIZATION_API KapurResult ipsdk::imaproc::bin::kapurThresholdImg (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::imaproc::attr::HistogramDataPtr &pHistogram)
 wrapper function for binarization on one image using Kapur's method. histogram used to compute the Kapur's threshold is provided as argument of the function More...
 
IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThresholdImg (const ipsdk::image::ImageConstPtr &pInImg, const ipsdk::imaproc::attr::HistogramDataPtr &pHistogram, const ipsdk::image::ImagePtr &pOutBinImg)
 wrapper function for binarization on one image using Kapur's method. histogram used to compute the Kapur's threshold is provided as argument of the function More...
 

Detailed Description

Compute the Kapur threshold of an input image, and binarize the image using this threshold.

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].

On output, binarized image values are given by:

\[ OutBinImg[i] = \begin{cases} 1, & \text{if } InImg[i] \geq KapurThreshold \\ 0, & \text{otherwise} \end{cases} \]

with $KapurThreshold$ the threshold computed from Kapur's method.

Input and output images must have same size and buffer type.

Here is an example of automatic Kapur image thresholding applied to a 8-bits grey level image (on ouput, computed threshold equals 123) :

kapurThresholdImg.png

[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
ipsdk::imaproc::attr::OutBinImg [Output] binary image for processing operation ipsdk::imaproc::duplicateInOut (_pOutBinImg, _pInImg, image::eImageBufferType::eIBT_Binary)

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::matchSize (_pInImg,_pOutBinImg)

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
outImg, kapurThresholdValue = bin.kapurThresholdImg(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 with a generated output image
// ------------------------------------
// compute thresholded output image
KapurResult kapurResult = kapurThresholdImg(pInImg);
// Sample with a provided output image
// -----------------------------------
// create output image
ImageGeometryPtr pOutputImageGeometry = geometry2d(eImageBufferType::eIBT_Binary, sizeX, sizeY);
boost::shared_ptr<MemoryImage> pOutImg(boost::make_shared<MemoryImage>());
pOutImg->init(*pOutputImageGeometry);
// compute thresholded output image
ipReal64 fOutThreshold = kapurThresholdImg(pInImg, pOutImg);
See also
KapurThresholdImgLvl1

Function Documentation

◆ kapurThresholdImg() [1/4]

IPSDKIPLBINARIZATION_API KapurResult ipsdk::imaproc::bin::kapurThresholdImg ( const ipsdk::image::ImageConstPtr pInImg)

wrapper function for binarization on one image using Kapur's method. 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

◆ kapurThresholdImg() [2/4]

IPSDKIPLBINARIZATION_API KapurResult ipsdk::imaproc::bin::kapurThresholdImg ( const ipsdk::image::ImageConstPtr pInImg,
const ipsdk::imaproc::attr::HistogramDataPtr pHistogram 
)

wrapper function for binarization on one image using Kapur's method. histogram used to compute the Kapur's threshold is provided as argument of the function

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ kapurThresholdImg() [3/4]

IPSDKIPLBINARIZATION_API ipReal64 ipsdk::imaproc::bin::kapurThresholdImg ( const ipsdk::image::ImageConstPtr pInImg,
const ipsdk::image::ImagePtr pOutBinImg 
)

wrapper function for binarization on one image using Kapur's method. 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

◆ kapurThresholdImg() [4/4]

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

wrapper function for binarization on one image using Kapur's method. histogram used to compute the Kapur's threshold is provided as argument of the function

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure