Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Image Morphology
Li Yicheng
LIACS
l.y.c.liyicheng@gmail.com
Abstract
Understand the image morphology, and pay attention to the following definitions: open, close, erode,
dilate, structuring element. Understand how to use opencv image processing builtin fucntions to do the
morphology operation. Understand how to use the track bar in openCV, because such tool is important in
future testing.
I.
Image Morphology
I.
Structuring element
Figure 2: Examples
Image morphology
II.
Operation
I Erosion
we denote that g = f s, where f is the original matrix of the image and s is the matrix of
structuring element.
g( x, y) = 1 if s fits the f else g( x, y) = 0 something is not clear enough, and now I am going
to further show how this is done, the operation
is just take every pixel in the matrix and set
it as a center of a structuring element if the
chosen part fit the structuring element then the
center part marked as 1, else marked as 0.
I Dilation
we denote that g = f s, where f is the original matrix of the image and s is the matrix of
structuring element.
g( x, y) = 1 if s fits the f else g( x, y) = 0 something is not clear enough, and now I am going
to further show how this is done, the operation
is just take every pixel in the matrix and set
it as a center of a structuring element if the
chosen part hit the structuring element then
the center part marked as 1, else marked as 0.
II.
I.
11 }
12
13
14 API
15 void morphologyEx ( InputArray s r c ,
OutputArray dst , i n t op , InputArray
k e r n e l , P o i n t anchor= P o i n t ( 1 , 1) , i n t
i t e r a t i o n s =1 , i n t borderType=
BORDER_CONSTANT, c o n s t S c a l a r&
borderValue=
morphologyDefaultBorderValue ( ) )
Parameters:
src - Source image. The number of channels
can be arbitrary. The depth should be one of
CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
dst - Destination image of the same size and
type as src .
element - Structuring element.
op - Type of a morphological operation that
can be one of the following:
MORPH_OPEN - an opening operation
MORPH_CLOSE - a closing operation
MORPH_GRADIENT - a morphological gradient
MORPH_TOPHAT - top hat
MORPH_BLACKHAT - black
hat
II.
1 void E r o d e D i l a t e ( i n t , void )
2 {
3
int n = erode_dilate_pos max_iters ;
4
i n t an = n > 0 ? n : n ;
5
Mat element = g e t S t r u c t u r i n g E l e m e n t (
element_shape , S i z e ( an 2+1 , an
2+1) , P o i n t ( an , an ) ) ;
6
if ( n < 0 )
7
erode ( s r c , dst , element ) ;
8
else
9
d i l a t e ( s r c , dst , element ) ;
10
imshow ( " Erode/ D i l a t e " , d s t ) ;
11 }
Image morphology
= dilate(erode(src, element))
T r a c k b a r C a l l b a c k onChange =0 , void
u s e r d a t a =0)
(1)
= erode(dilate(src, element))
(2)
III.
1
3
4
Trackbar
Parameters:
trackbarname - Name of the created trackbar.
winname - Name of the window that will be
used as a parent of the created trackbar.
value - Optional pointer to an integer variable
whose value reflects the position of the slider.
Upon creation, the slider position is defined by
this variable.
count - Maximal position of the slider. The
minimal position is always 0.
onChange - Pointer to the function to be
called every time the slider changes position.
This function should be prototyped as void
Foo(int,void*); , where the first parameter is
the trackbar position and the second parameter
is the user data (see the next parameter). If the
callback is the NULL pointer, no callbacks are
called, but only value is updated.
userdata - User data that is passed as is to
the callback. It can be used to handle trackbar
events without using global variables.