quinta-feira, 19 de março de 2009

Mathematical Morphology using OpenCV

I did a post about mathematical morphology, I wrote about theory of mathematical morphology.

Now, I want to write about the functions of OpenCV* for manipulate the structural element and apply the operations of erosion and dilatation.

The following function creates the structural element:

IplConvKernel* cvCreateStructuringElementEx( int cols,
int rows,
int anchor_x,
int anchor_y,
int shape,
int* values=NULL );

cols: Number of columns of the structural element

rows: Number of rows of the structural element

anchor_x: Horizontal offset relative to point of anchor, normally equal to 0 (zero)

anchor_y: Vertical offset relative to point of anchor, normally equal to 0 (zero)

shape: Type of structural element, possible values:
  • CV_SHAPE_RECT, square element;
  • CV_SHAPE_CROSS, element in disc;
  • CV_SHAPE_ELLIPSE, elliptic element;
  • CV_SHAPE_CUSTOM, element defined by user. In this case, the parameter values specifies the mask, delimiting the vicinity of the pixel in analysis.
values: Pointer to structural element defined by usuer, this parameter is used just for shape = CV_SHAPE_CUSTOM.

Function of erosion:

void cvErode( const CvArr* src, CvArr* dst,
IplConvKernel* element=NULL, int iterations=1 );

Function of dilatation:

void cvDilate( const CvArr* src, CvArr* dst,
IplConvKernel* element=NULL, int iterations=1 );

src: Input image;
dst: Output image;
element: Structural element. If it's NULL, the structural element is a square 3x3;
iterations: Number of times for apply the operation.
The interfaces for development in Python is the same, and all functions are very fast because they're implemented in C.

More informations here.


----------------------
* OpenCV (Open Computational Vision) is a API for development using Computational Vision. It's a very powerful set of functions for capture, processing and showing of images and videos.

Nenhum comentário: