IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Adaptive Threshold 3d binarizationSee full documentation
imageadaptiveThreshold3dImg (inImg3d,inKnlXYZ)
imageadaptiveThresholdGaussian3dImg (inImg3d,halfKnlSize)

Detailed Description

Binarize a 3d input image according an adaptive threshold based on the voxel's neighbourhood.

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

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

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

Note
The kernels coefficients must be normalized :

\[ \sum_{(i, j, k) \in \aleph}{InKnlXY(i, j, k)} = 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 voxels in the neighbourhood.

It is also possible to call the adaptiveThresholdGaussian3dImg 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 \times KnlSize $.

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

See Adaptive Threshold 2d binarization for a 2d example of the adaptative threshold result.

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.rectangularKernelXYZ(halfKnlSize, halfKnlSize, halfKnlSize, coeffColl)
# threshold computation with a given kernel
outImg = bin.adaptiveThreshold3dImg(inImg, inKnl)
# threshold computation with a predifined Gaussian kernel
outImgGauss = bin.adaptiveThresholdGaussian3dImg(inImg, halfKnlSize)

Example of C++ code :

Example informations

Header file

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

Code Example

// Sample with a generated output image
// ------------------------------------
// compute absolute value of input image
ImagePtr pAutoOutImg = adaptiveThreshold3dImg(pInImg, pInKnlXYZ);
// Sample with a provided output image
// -----------------------------------
// create output image
ImageGeometryPtr pOutputImageGeometry = geometry3d(eImageBufferType::eIBT_Binary, sizeX, sizeY, sizeZ);
boost::shared_ptr<MemoryImage> pOutImg(boost::make_shared<MemoryImage>());
pOutImg->init(*pOutputImageGeometry);
// compute absolute value of input image
adaptiveThreshold3dImg(pInImg, pInKnlXYZ, pOutImg);
// Sample with an automatically computed
// Gaussian kernel and a generated output image
// --------------------------------------------
// compute absolute value of input image
ImagePtr pAutoGaussOutImg = adaptiveThresholdGaussian3dImg(pInImg, halfKnlSize);