Introdução ao PID
Processamento de
Imagens Digitais
Filtros Morfológicos
Glaucius Décio Duarte
Instituto Federal Sul-rio-grandense
Engenharia Elétrica
2015
FILTROS MORFOLÓGICOS
De acordo com Serra (1994) os filtros morfológicos constituem alternativas
interessantes à filtragem não-linear e são caracterizados por uma transformação
crescente e idempotente.
Neste sentido, a erosão e a dilatação, por não serem idempotentes, não constituem
filtros morfológicos. Por sua vez, a abertura e o fechamento são exemplos típicos de
operadores de filtragem, cuja composição também define filtros. Esta composição pode
ser considerada a partir de aberturas e fechamentos com elementos estruturantes de
tamanho variável o que conduz, entre outros, à definição de filtros com comportamento
simétrico em relação às estruturas claras e escuras da imagem (SERRA, 1988)
(COSTER; CHERMANT, 1989).
Elemento estruturante (strel)
­­ Function File: strel (SHAPE, PARAMETERS)
Create a strel (structuring element) object for morphology
operations.
The structuring element can have any type of shape as specified by
SHAPE, each one with its PARAMETERS.
­­ Function File: strel ("arbitrary", NHOOD)
­­ Function File: strel ("arbitrary", NHOOD, HEIGHT)
Create arbitrary shaped structuring elements.
NHOOD must be a matrix of 0's and 1's. Any number with of
dimensions are possible. To create a non­flat SE, the HEIGHT can
be specified. See individual functions that use the strel object
for an interpretation of non­flat SEs.
Note that if an arbitrary shape is used, it will not be possible to
perform structuring element decomposition which may have a
performance hit in some cases. ­­ Function File: strel ("ball", RADIUS, HEIGHT)
Create ball shaped NONFLAT structuring element. RADIUS must be a
nonnegative integer that specifies the ray of a circle in X­Y
plane. HEIGHT is a real number that specifies the height of the
2 de 7
center of the circle.
­­ Function File: strel ("cube", EDGE)
Create cube shaped FLAT structuring element. EDGE must be a
positive integer that specifies the length of its edges. This
shape meant to perform morphology operations in volumes, see the
square shape for 2 dimensional images.
­­ Function File: strel ("diamond", RADIUS)
Create diamond shaped flat structuring element. RADIUS must be a
positive integer.
­­ Function File: strel ("disk", RADIUS)
Create disk shaped flat structuring element. RADIUS must be a
positive integer.
­­ Function File: strel ("hypercube", N, EDGE)
Create N dimensional cube (n­cube) shaped FLAT structuring element.
EDGE must be a positive integer that specifies the length of its
edges.
­­ Function File: strel ("hyperrectangle", DIMENSIONS)
Create N dimensional hyperrectangle (or orthotope) shaped flat
structuring element. DIMENSIONS must be a vector of positive
integers with its lengtht at each of the dimensions.
­­ Function File: strel ("line", LEN, DEG)
Create line shaped flat structuring element. LEN must be a
positive real number. DEG must be a 1 or 2 elements real number,
for a line in in 2D or 3D space. The first element of DEG is the
angle from X­axis to X­Y projection of the line while the second is
the angle from Z­axis to the line.
­­ Function File: strel ("octagon", APOTHEM)
Create octagon shaped flat structuring element. APOTHEM must be a
non­negative integer, multiple of 3, that specifies the distance
from the origin to the sides of the octagon.
­­ Function File: strel ("pair", OFFSET)
Create flat structuring element with two members. One member is
3 de 7
placed at the origin while the other is placed with OFFSET in
relation to the origin. OFFSET must then be a 2 element vector for
the coordinates.
­­ Function File: strel ("periodicline", P, V)
Create periodic line shaped flat structuring element. A periodic
line will be built with 2*P+1 points around the origin included.
These points will be displaced in accordance with the offset V at
distances: 1*V, ­1*V, 2*V, ­2*V, ..., P*V, ­P*V. Therefore V must
be a 2 element vector for the coordinates.
­­ Function File: strel ("rectangle", DIMENSIONS)
Create rectangular shaped flat structuring element. DIMENSIONS
must be a two element vector of positive integers with the number
of rows and columns of the rectangle.
­­ Function File: strel ("square", EDGE)
Create square shaped flat structuring element. EDGE must be a
positive integer that specifies the length of its edges. For use
in volumes, see the cube shape.
The actual structuring element neighborhood, the logical matrix
used for the operations, can be accessed with the 'getnhood'
method. However, most morphology functions in the image package
will have an improved performance if the actual strel object is
used, and not its element neighborhood.
se = strel ("square", 5);
getnhood (se)
=>
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
4 de 7
Exemplo:
im = randp (5, 2000) > 15;
se = strel ("square", 20);
t = cputime (); imdilate (im, se); cputime () ­ t => 0.77605
se = strel (ones (20));
t = cputime (); imdilate (im, se); cputime () ­ t => 2.9082
Erosão (imerode)
Erosão e dilatação são as operações elementares da MM e formam a base para a
construção das transformações mais complexas. Assim, numa cadeia morfológica de
processamento de imagens, podemos encontrar um grande número de operadores
encadeados, todos definidos a partir destas funções elementares.
­­ Loadable Function: imerode (IM, SE)
­­ Loadable Function: imerode (IM, SE, SHAPE)
Perform morphological erosion.
The image IM must be a numeric matrix with any number of
dimensions. The erosion is performed with the structuring element
SE which can be a:
* strel object;
* array of strel objects as returned by '@strel/getsequence';
* matrix of 0's and 1's.
To perform a non­flat erosion, SE must be a strel object.
The size of the result is determined by the optional SHAPE argument
which takes the following values:
'"same" (default)'
Return image of the same size as input IM.
5 de 7
'"full"'
Return the full erosion (image is padded to accomodate SE near
the borders).
'"valid"'
Return only the parts which do not include the padded edges.
In case of a SE with a size of even length, the center is
considered at indices 'floor ([size(SE)/2] + 1)'.
Exemplo :
imo = uint8(imread('imagem_para_erosao.jpg'));
figure(1);
imshow(imo);
se = strel('square',5);
ime = imerode(imo,se);
figure(2);
imshow(ime);
Figura 1 – Erosão de uma imagem.
6 de 7
Dilatação (imdilate)
­­ Loadable Function: imdilate (IM, SE)
­­ Loadable Function: imdilate (IM, SE, SHAPE)
Perform morphological dilation.
The image IM must be a numeric matrix with any number of
dimensions. The dilation is performed with the structuring element
SE which can be a:
* strel object;
* array of strel objects as returned by '@strel/getsequence';
* matrix of 0's and 1's.
To perform a non­flat dilation, SE must be a strel object.
The size of the result is determined by the optional SHAPE argument
which takes the following values:
'"same" (default)'
Return image of the same size as input IM.
'"full"'
Return the full dilation (matrix is padded to accomodate SE
near the borders).
'"valid"'
Return only the parts which do not include the padded edges.
In case of a SE with a size of even length, the center is
considered at indices 'floor ([size(SE)/2] + 1)'.
Exemplo:
imo = uint8(imread('imagem_para_dilatacao.jpg'));
figure(1);
imshow(imo);
se = strel('square',5);
imd = imdilate(imo,se);
figure(2);
imshow(imd);
7 de 7
Figura 2 – Dilatação de uma imagem.
Abertura (imopen)
­­ Function File: imopen (IMG, SE)
Perform morphological opening.
The matrix IMG must be numeric while SE can be a:
* strel object;
* array of strel objects as returned by '@strel/getsequence';
* matrix of 0's and 1's.
The opening corresponds to an erosion followed by a dilation of
IMG, using the same SE, i.e., it is equivalent to:
imdilate (imerode (img, se), se);
Exemplo:
imo = uint8(imread('Lena.png'));
figure(1);
imshow(imo);
se = strel('square',5);
ima = imopen(imo,se);
figure(2);
imshow(ima);
8 de 7
Figura 3 – Abertura de uma imagem.
Fechamento (imclose)
­­ Function File: imclose (IMG, SE)
Perform morphological closing.
The matrix IMG must be numeric while SE can be a:
* strel object;
* array of strel objects as returned by '@strel/getsequence';
* matrix of 0's and 1's.
The closing corresponds to a dilation followed by an erosion of
IMG, using the same SE, i.e., it is equivalent to:
imerode (imdilate (img, se), se);
Exemplo:
imo = uint8(imread('Lena.png'));
figure(1);
imshow(imo);
se = strel('square',5);
imf = imclose(imo,se);
figure(2);
imshow(imf);
9 de 7
Figura 4 – Fechamento de uma imagem.
Referências
COSTER, M.; CHERMANT, J. L. Précis d'analyse d'images. Presses du CNRS, 1989.
SERRA, J. Morphological filtering: an overview. Signal Processing, n. 38, p. 3-11, 1994.
__________. Image analysis and mathematical morphology, volume 2: Theoretical
Advances. Academic Press, 1988.
10 de 7
Download

Filtros Morfológicos - Instituto Federal Sul-rio