Professional Documents
Culture Documents
Journal 8
Journal 8
_________________________________
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
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.
Page 2
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:
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.
Page 3
Page 4
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
Page 5
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:
+++++++++++++++++++++++++++
Page 6