IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Adaptive Threshold 2d binarization

Binarize an input image according an adaptive threshold based on the pixel's neighbourhood. More...

IPSDKIPLBINARIZATION_API ipsdk::image::ImagePtr ipsdk::imaproc::bin::adaptiveThreshold2dImg (const ipsdk::image::ImageConstPtr &pInImg, const KernelXYConstPtr &pInKnlXY)
 wrapper function for Binarize an input image according an adaptive threshold based on the pixel's neighbourhood More...
 
IPSDKIPLBINARIZATION_API void ipsdk::imaproc::bin::adaptiveThreshold2dImg (const image::ImageConstPtr &pInImg, const KernelXYConstPtr &pInKnlXY, const ipsdk::image::ImagePtr &pOutBinImg)
 wrapper function for Binarize an input image according an adaptive threshold based on the pixel's neighbourhood More...
 
IPSDKIPLBINARIZATION_API ipsdk::image::ImagePtr ipsdk::imaproc::bin::adaptiveThresholdGaussian2dImg (const ipsdk::image::ImageConstPtr &pInImg, const ipUInt64 halfKnlSize)
 wrapper function for binarize an input image according an adaptive threshold based on the pixel's neighbourhood. Here, the threshold is defined as the sum of the intensities on the neighbourhood, weighted by Gaussian coefficients. The Gaussian coefficients are computed with the folowing standard deviation : $ 0.3*(halfKnlSize - 1) + 0.8 $ More...
 
IPSDKIPLBINARIZATION_API void ipsdk::imaproc::bin::adaptiveThresholdGaussian2dImg (const image::ImageConstPtr &pInImg, const ipUInt64 halfKnlSize, const ipsdk::image::ImagePtr &pOutBinImg)
 wrapper function for binarize an input image according an adaptive threshold based on the pixel's neighbourhood. Here, the threshold is defined as the sum of the intensities on the neighbourhood, weighted by Gaussian coefficients. The Gaussian coefficients are computed with the folowing standard deviation : $ 0.3*(halfKnlSize - 1) + 0.8 $ More...
 

Detailed Description

Binarize an input image according an adaptive threshold based on the pixel's neighbourhood.

For each pixel, the algorithm computes a threshold $T$ according to a neighbourhood described by the input kernel size as follows :

\[ T(x, y) = \sum_{(i, j) \in \aleph}{InImg(x+i, y+j) \times InKnlXY(i, j)} \]

Where $\aleph$ is the pixel's neighbourhood.

Note
The kernels coefficients must be normalized :

\[ \sum_{(i, j) \in \aleph}{InKnlXY(i, j)} = 1\]

For example, the threshold can be the mean intensity in the neighbourhood with each kernel coefficients set to $1/N$, with $N$ being the number of pixels in the neighbourhood.

It is also possible to call the adaptiveThresholdGaussian2dImg wrapper, which needs the half kernel size instead of the kernel as input data. In this case, a predifined Gaussian kernel is used, whose coefficients are computed with the folowing standard deviation $\sigma$ (see http://docs.opencv.org/2.4/modules/imgproc/doc/filtering.html#Mat%20getGaussianKernel%28int%20ksize,%20double%20sigma,%20int%20ktype%29) :

\[ \sigma = 0.3*((KnlSize-1)*0.5 - 1) + 0.8 \]

Where $KnlSize$ is the kernel size : $ N = KnlSize \times KnlSize $.

Note
To avoid a noisy binarization, it is advised to filter the input image with a median filter before computing the binarization.

Here is an example of an adaptive image thresholding applied to a 8-bits grey level image, with a Gaussian kernel with a size of 5 :

adaptiveThreshold2dImg.png

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InImg [Input] image for processing operation X
ipsdk::imaproc::attr::InKnlXY [Input] kernel xy for processing operation 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)
# Define the kernel according to a coefficients collection
inKnl = PyIPSDK.rectangularKernelXY(halfKnlSize, halfKnlSize, coeffColl)
# threshold computation with a given kernel
outImg = bin.adaptiveThreshold2dImg(inImg, inKnl)
# threshold computation with a predifined Gaussian kernel
outImgGauss = bin.adaptiveThresholdGaussian2dImg(inImg, halfKnlSize)

Example of C++ code :

Example informations

Associated library

IPSDKIPLBinarization

Header file

Code Example

// Sample with a generated output image
// ------------------------------------
// compute absolute value of input image
ImagePtr pAutoOutImg = adaptiveThreshold2dImg(pInImg, pInKnlXY);
// 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 absolute value of input image
adaptiveThreshold2dImg(pInImg, pInKnlXY, pOutImg);
// Sample with an automatically computed
// Gaussian kernel and a generated output image
// --------------------------------------------
// compute absolute value of input image
ImagePtr pAutoGaussOutImg = adaptiveThresholdGaussian2dImg(pInImg, halfKnlSize);
See also
AdaptiveThreshold2dImgLvl1
AdaptiveThreshold2dImgLvl2
AdaptiveThreshold2dImgLvl3

Function Documentation

◆ adaptiveThreshold2dImg() [1/2]

IPSDKIPLBINARIZATION_API ipsdk::image::ImagePtr ipsdk::imaproc::bin::adaptiveThreshold2dImg ( const ipsdk::image::ImageConstPtr pInImg,
const KernelXYConstPtr pInKnlXY 
)

wrapper function for Binarize an input image according an adaptive threshold based on the pixel's neighbourhood

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ adaptiveThresholdGaussian2dImg() [1/2]

IPSDKIPLBINARIZATION_API ipsdk::image::ImagePtr ipsdk::imaproc::bin::adaptiveThresholdGaussian2dImg ( const ipsdk::image::ImageConstPtr pInImg,
const ipUInt64  halfKnlSize 
)

wrapper function for binarize an input image according an adaptive threshold based on the pixel's neighbourhood. Here, the threshold is defined as the sum of the intensities on the neighbourhood, weighted by Gaussian coefficients. The Gaussian coefficients are computed with the folowing standard deviation : $ 0.3*(halfKnlSize - 1) + 0.8 $

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ adaptiveThreshold2dImg() [2/2]

IPSDKIPLBINARIZATION_API void ipsdk::imaproc::bin::adaptiveThreshold2dImg ( const image::ImageConstPtr pInImg,
const KernelXYConstPtr pInKnlXY,
const ipsdk::image::ImagePtr pOutBinImg 
)

wrapper function for Binarize an input image according an adaptive threshold based on the pixel's neighbourhood

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ adaptiveThresholdGaussian2dImg() [2/2]

IPSDKIPLBINARIZATION_API void ipsdk::imaproc::bin::adaptiveThresholdGaussian2dImg ( const image::ImageConstPtr pInImg,
const ipUInt64  halfKnlSize,
const ipsdk::image::ImagePtr pOutBinImg 
)

wrapper function for binarize an input image according an adaptive threshold based on the pixel's neighbourhood. Here, the threshold is defined as the sum of the intensities on the neighbourhood, weighted by Gaussian coefficients. The Gaussian coefficients are computed with the folowing standard deviation : $ 0.3*(halfKnlSize - 1) + 0.8 $

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure