IPSDK 4.2
IPSDK : Image Processing Software Development Kit
Adaptive Threshold Mean 2d
image = adaptiveThresholdMean2dImg (inImg,halfKnlSize)

Detailed Description

binarize an input image according an adaptive threshold based on the mean intensity of the pixel's neighbourhood

For each pixel, the algorithm computes a threshold according to a neighbourhood described by $InKnlSize$. The computed threshold $T$ is the mean intensity along the pixel's neighbourhood $\aleph$ :

\[ T(x, y) = \frac{1}{N} \sum_{(i, j) \in \aleph}{InImg(x+i, y+j)} \]

Where $N$ is the number of pixels in $\aleph$.

This algorithm is equivalent to the Adaptive Threshold 2d binarization algorithm, with each kernel coefficient set to $1/N$. However, it is optimized to compute a mean adaptive threshold based binarization and yields better performances.

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 kernel size of 5 ( $InKnlSize=2$) :

adpativeThresholdMean2dImg.png

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLBinarization as bin

Code Example

# opening of input images
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# threshold computation with a given kernel
outImg = bin.adaptiveThresholdMean2dImg(inImg, halfKnlSize)

Example of C++ code :

Example informations

Header file

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

Code Example

// Loading the input image
// ------------------------------------
ImagePtr pInImg = loadTiffImageFile(inputPath);
// Sample with a generated output image
// ------------------------------------
// compute absolute value of input image
ImagePtr pAutoOutImg = adaptiveThresholdMean2dImg(pInImg, halfKnlSize);
// Sample with a provided output image
// -----------------------------------
// Retrieve the input image size
const ipUInt64 sizeX = pInImg->getSizeX();
const ipUInt64 sizeY = pInImg->getSizeY();
// 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
adaptiveThresholdMean2dImg(pInImg, halfKnlSize, pOutImg);