se = strel(`disk`,10)

advertisement
Morphology Image Processing
Lab 6
Dilation
grow image regions
Erosion
shrink image regions
Opening
removal of image region
Closing
filling in image region
Thickening
thickens objects by adding pixels to the exterior of objects.
Thinning
Opposite of thicken
Skeletonization
removes pixels on the boundaries of objects but does not
allow objects to break apart. The pixels remaining make up
the image skeleton.
Dilation & Erosion
Dilation
Erosion
Operation that “grows” or “expand”
objects in an image.
Operation that “shrinks” or “reduce”
objects in an image.
D = imdilate(image, structuring element);
E = imerode(image, structuring element);
Both are controlled by a shape referred to as a structuring element.
The image could be binary(black&white) OR intensity(grayscale) image
Function strel
• Create morphological structuring element
(STREL), with a variety of shapes and sizes.
se = strel(shape,parameters);
Syntax
Description
SE = strel('diamond',R)
R specifies the distance from the structuring element origin to
the points of the diamond.
SE = strel('disk',R)
R specifies the radius.
SE = strel('line',LEN,DEG)
LEN specifies the length, and DEG specifies the angle (in degrees)
of the line, as measured in a counterclockwise direction from the
horizontal axis.
Syntax
Description
SE = strel('rectangle',[M,N])
MN specifies the size. MN must be a two-element vector of
nonnegative integers. The first element of MN is the number
of rows in the structuring element neighborhood; the second
element is the number of columns.
SE = strel('square',W)
width is W pixels. W must be a nonnegative integer scalar.
SE = strel('octagon',R)
R specifies the distance from the structuring element origin to
the sides of the octagon, as measured along the horizontal
and vertical axes.
imdilate example with binary
>>bw = imread('text.png');
>>se = strel('line',11,90);
>>bw2 = imdilate(bw,se);
>>imshow(bw), title('Original'), figure, imshow(bw2),
title('Dilated');
imdilate example with grayscale
>>I = imread('cameraman.tif');
>>se = strel(‘rectangle',[5,5]);
>>I2 = imdilate(I,se);
>>imshow(I), title('Original'),figure, imshow(I2),
title('Dilated');
imerode example with binary
>>originalBW = imread('circles.png');
>>se = strel('disk',11);
>>erodedBW = imerode(originalBW,se);
>>imshow(originalBW), figure,
imshow(erodedBW)
imerode example with grayscale
>>I = imread('cameraman.tif');
>> se=strel('rectangle',[5,5]);
>>I2 = imerode(I,se);
>>imshow(I), title('Original'), figure, imshow(I2),
title('Eroded‘);
imdilate, imerode Example
>> BW = imread('circbw.tif');
>> se=strel('square',3);
>> BWD = imdilate(BW,se);
>> BWE = imerode(BW,se);
>>imshow(BW),figure,imshow(BWD),figure,imshow(BWE);
Combining Dilation & Erosion
• The most common combinations of dilation
and erosion:
 opening.
 closing.
opening
closing
Erosion  Dilation
Erodes an image and then dilates the
eroded image using the same structuring
element for both operations.
Used for: removal of image region
Dilation  Erosion
Dilates an image and then erodes the
dilated image using the same structuring
element for both operations.
Used for: filling in image region
OIM = imopen(image ,structuring element)
CIM = imclose(image, structuring element)
Both are controlled by a shape referred to as a structuring element
Image could be binary(black&white) OR intensity(grayscale) image
imopen Example
• This example uses imopen to filter out the smaller
objects in an image.
>> I = imread('snowflakes.png');
• Create a disk-shaped structuring element with a radius
of 5 pixels.
>>se = strel('disk',5);
• Remove snowflakes having a radius less than 5 pixels
by opening it with the disk-shaped structuring element.
>> I_opened = imopen(I,se);
>>Imshow(I), figure, imshow(I_opened,[]);
imclose example
• This example uses imclose to join the circles in
the image together by filling in the gaps between
them and by smoothening their outer edges.
>>originalBW = imread('circles.png');
• Create a disk-shaped structuring element. Use a
disk structuring element to preserve the circular
nature of the object. Specify a radius of 10 pixels
so that the largest gap gets filled.
>>se = strel('disk',10);
>>closeBW = imclose(originalBW,se);
>> imshow(originalBW),figure, imshow(closeBW);
Some morphological operations
• There are a variety of morphological operations
based on combinations of dilations, erosions,
and lookup table operations:
Thickening.
Thinning.
Skeletonization.
• These operations can be accomplished by
bwmorph function in matlab.
bwmorph
• g = bwmorph( i , operation , n)
• i  the input image(should be black&white)
• operation  string specifying the operation
‘thicken’
‘thin’
thickens objects by adding pixels to the exterior of objects.
‘skel’
removes pixels on the boundaries of objects but does not allow objects
to break apart. The pixels remaining make up the image skeleton.
opposit of thicken
• n  number of times the operation should be
repeated.
 If n is ommited  n=1
If n = Inf  repeat the operation until the image stops
changing. (should used with ‘skel’)
Examples
BW1 = imread('circbw.tif');
BW2 = bwmorph(BW1,'skel',Inf);
imshow(BW1) ,figure, imshow(BW2);
BW = imread('circles.png');
BW2 = bwmorph(BW,'skel',Inf);
imshow(BW) ,figure, imshow(BW2);
Download