IPSDK 4.1
IPSDK : Image Processing Software Development Kit
Otsu Threshold computation
scalarotsuThreshold (inImg)
scalarotsuThreshold (inImg,histogram)

Detailed Description

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

Otsu'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 minimizing their intra-class variance. In this implementation, the alternate method (maximizing the inter-classes variance) is used. It has the advantage to be faster than the first method.

See also
http://en.wikipedia.org/w/index.php?title=Otsu%27s_method&oldid=617320940 for more details.

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
otsuThresholdValue = bin.otsuThreshold(inImg)

Example of C++ code :

Example informations

Header file

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

Code Example

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