You are on page 1of 6

Lab Journal Lab 8

CEN 472 Digital Image Processing


Lab Journal - Lab 8
Name:

_________________________________

Enrollment #: _________________________________
Class:

_________________________________

Objective
Todays lab covers fundamental morphological operations such as dilation and erosion and
using them in combination: opening and closing. By the end of this lab you should be able to
perform morphological operations on an image in MATLAB and extracting image components
that are useful in representing and describing shapes of a region.
Submission Requirements
You are expected to complete the assigned tasks within the lab session and show them to the
lab engineer/instructor. Get the lab journal signed by your instructor and submit it by the end of
lab session.

Tasks

1. Morphological Operations
The morphological image processing consists of a class of operations that are particularly used
to fill out the incomplete regions of an object or a boundary, or removing certain unnecessary
branches of an object or separating the connected regions.
A morphological operation is union (or intersection) of an image with translated shape (i.e.
structuring element). So applying a morphological operation on an image is a 2 step procedure
in MATLAB, defined below:
1. Create a Structuring Element using function sel = strel(shape, parameters).
Common shapes include line, disk, square, diamond etc. For example:
Digital Image Processing

Page 1

Lab Journal Lab 8

se = strel(line, 5, 0)
Generates a horizontal structuring element of size 5.
se = [1 1 1 1 1]

2. Applying desired morphological operation (i.e. dilation, erosion etc) onto a read image
using imdilate(image, sel) and/or imerode(image, sel) functions. Where sel is the
structuring element created in step 1.

2. Dilation
Dilation grows or thickens objects. It expands the connected set of 1s in a binary image
and thus is useful in growing features, filling holes, and gaps.
For instance, in MATLAB dilation with a disk of radius 5 can be performed as follows:
>> img = imread(coins.png);
>> imgb = im2bw(img);
>> sel = strel(disk, 5);
>> imgn = imdilate(imgb, sel);

The above lines of code will fill-in the gap left within the coins. But this will also result in
connected boundaries of coins, as shown in Figure 1.

Figure 1: Dilation with a disk shaped structuring element


Digital Image Processing

Page 2

Lab Journal Lab 8

3. Erosion
Erosion shrinks or thins objects in a binary image. It shrinks the connected set of 1s in a
binary image and thus is useful in shrinking features, removing branches, and
unnecessary boundaries.
For instance, in MATLAB erosion with a disk of radius 5 can be performed as follows:

>> img = imread(circles.png);


% since read image is binary so no need of conversion.
>> sel = strel(disk, 11);
>> imgn = imerode(img, sel);

The above lines of code will separate out connected circles, as shown below. Although, it
shrunk the circles but this information can further be used in bwlabel function to find
out total number or circles.

Figure 2: Erosion of a binary image to separate objects

4. Combining Erosion and Dilation: Opening and Closing


In practical, morphological operations are performed as a series of erosion and/or
dilation operations using the same, or sometimes different, structuring elements. Such

Digital Image Processing

Page 3

Lab Journal Lab 8

an operation is called compound operation and is named as opening (erosion followed


the dilation) or closing (dilation followed by an erosion).
For instance, in MATLAB opening operation with a disk of radius 5 can be performed as
follows:
>> img = imread(coins.png);
>> sel = strel(disk, 5);
>> imgn = imopen(im2bw(img), sel);

Similarly closing operation can be performed using imclose function.


Opening is performed to smooth object boundaries, remove small objects and bridges
while closing is performed to fill holes or gaps in images.

Figure 3: Opening of a binary image

Digital Image Processing

Page 4

Lab Journal Lab 8

Figure 4: Closing of a binary image

Exercise 1:
Read an image eight.tif. Write a function named myMorphology to extract the boundaries
of coins from the read image.
[HINTS]:
1. First close the image then perform erosion.
2. Take the difference of two images to find boundaries.

Original Image

Extracted Boundaries

Figure 5: Desired Output in Exercise 1

Digital Image Processing

Page 5

Lab Journal Lab 8

Exercise 2:
Read the image lines.gif uploaded on your course web page. Use the
opening operator to separate horizontal and vertical lines.
[HINTS]: Experiment with structuring elements of sizes 7x3,9x3, 11x3
etc. to remove horizontal lines. Use the transpose of these structuring
elements to eliminate vertical lines.

Exercise 3:
Load the image SpaceShip.gif uploaded on your course web
page. Use the closing operator to fill gaps and remove the
small diagonal lines in the ship.

Do Exercises 1, 2 and 3 and get them checked by your instructor. If you are unable to
complete the tasks in the lab session, deposit this sheet alongwith your programs (printed or
handwritten) before the start of the next lab session.
S No.

Exercise

1.

Exercise 1

2.

Exercise 2

3.

Exercise 3

Checked By:

+++++++++++++++++++++++++++

Digital Image Processing

Page 6

You might also like