IPSDK 0.2
IPSDK : Image Processing Software Development Kit
Morphological Gradient 2dSee full documentation
imagemorphoGradient2dImg (inImg,inSEXY)

Detailed Description

gradient computation on a 2d image using morphological operations

A morphological gradient is the difference between the dilation and the erosion of a given image. It is a fast way to compute the gradient of an image. Output image pixel values, given a structuring element $ InSEXY $, are given by the following formula :

\[ OutImg = G(InImg)_{InSEXY} = InImg \oplus InSEXY - InImg \ominus InSEXY \]

Note
Behavior of this algorithm is specialized using specific morphological structuring elements (see 2d structuring elements for more informations about these shapes).
Please refer to Usage for examples of usage of different types of specific structuring elements during morphological operations.

Here is an example of a morphological gradient 2d operation applied to a gray scale input image with a circular structuring element with radius 2 :

MorphoGradient2dImg.png

This morphological operation can also be used to enhance gradients in a specific direction. This is illustrated with following example where the same input image has been processed with a linear structuring element with radius 2 and a 60 degrees orientation :

MorphoGradient2dImgLinear.png
See also
http://en.wikipedia.org/wiki/Morphological_gradient
Note
This algorithm is associated with two temporary working images ipsdk::imaproc::attr::OutOptWk1Img and ipsdk::imaproc::attr::OutWk1Img.
  • The first one (ipsdk::imaproc::attr::OutOptWk1Img) is only used in special processing cases defined via ipsdk::imaproc::morpho::eSEProcessingCase enumerate. Such situation can be tested using ipsdk::imaproc::morpho::getSEProcessingCase function and associated image buffer type can be retrieved using ipsdk::imaproc::morpho::getSEWkImageBufferType. This working temporary image can be provided by user or will be automatically allocated when requested.
  • The second one (ipsdk::imaproc::attr::OutWk1Img) is systematically needed for internal processing. This working temporary image can be provided by user or will be automatically allocated.

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLBasicMorphology as morpho

Code Example

# opening of input image
inImg = PyIPSDK.loadTiffImageFile(inputImgPath)
# definition of used structuring element
inSE = PyIPSDK.circularSEXYInfo(8)
# morphological gradient 2d image computation
outImg = morpho.morphoGradient2dImg(inImg, inSE)

Example of C++ code :

Example informations

Header file

#include <IPSDKIPL/IPSDKIPLBasicMorphology/Processor/MorphoGradient2dImg/MorphoGradient2dImg.h>

Code Example

// create a 5x7 rectangular structuring element
StructuringElementXYInfoConstPtr pInSEXY = genericSEXYInfo(*rectangularSEXY(5, 7));
// opening input image
ImagePtr pInImg = loadTiffImageFile(inputImgPath);
// compute morphological gradient on input image
ImagePtr pOutImg = morphoGradient2dImg(pInImg, pInSEXY);