Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA

DEPARTMENT OF ELECTRICAL ENGINEERING

DIGITAL IMAGE PROCESSING LAB


Lab-11 & 12: Morphological Image Processing
OBJECTIVE:
To understand the morphological operators and use them for image processing.

INTRODUCTION:
Morphology is a broad set of image processing operations that process images based on shapes.
Morphological operations apply a Structuring Element (SE) to an input image, creating an output
image of the same size. In a morphological operation, the value of each pixel in the output image
is based on a comparison of the corresponding pixel in the input image with its neighbors. By
choosing the size and shape of the neighborhood, you can construct a morphological operation that
is sensitive to specific shapes in the input image.
LEARNING TASKS:
Download chapter 9 images of the Gonzalez DIP 3rd edition book from the link given below.
https://www.imageprocessingplace.com/DIP-3E/dip3e_book_images_downloads.htm

1. Explore different types of morphological SEs available in the MATLAB.


a. Define diamond, disk, octagon and square shape SEs of size 13 × 13 using the
strel command. Also define a rectangle shape SE of size 3 × 13 and a horizontal
line SE of size 1 × 13. SE values can be observed by viewing the Neighborhood
property values of the defined object. Mention the values of all SEs in your report.
b. View and display all 6 defined SEs of part-a in a single 2 × 3 subplot grid with
proper titles.
c. Define an arbitrary SE of your choice and view its elements.
Erosion & Dilation
The erosion of 𝐴 by 𝐵, denoted 𝐴 ⊖ 𝐵, is the set of pixel locations 𝑧, where the SE 𝐵 translated
to location 𝑧, i.e., 𝐵𝑧 , completely overlaps only with foreground pixels in 𝐴. Defined
mathematically as: 𝐴 ⊖ 𝐵 = {𝑧|𝐵𝑧 ⊆ 𝐴}
The dilation of 𝐴 by 𝐵, denoted 𝐴 ⊕ 𝐵, is the set of pixel locations 𝑧, where the reflected SE 𝐵 ^
translated to location 𝑧, i.e., 𝐵 ^ 𝑧 overlaps with foreground pixels in 𝐴. Defined mathematically as:
𝐴 ⊕ 𝐵 = {𝑧|[𝐵 ^ 𝑧 ∩ 𝐴] ⊆ 𝐴}

2. Read and view Fig0905(a)(wirebond-mask).tif in MATLAB.


a. Remove all components except the center square from the image using the
morphological erosion operation. Define suitable size diamond shape and square
shape SEs and use the MATLAB imerode command. What is the minimum size
of both SEs which can be used to accomplish the said task? Display the eroded
image from both SEs. Which shape is more suitable for the said task?
b. Create a suitable SE to filter out all the lines (except horizontal and vertical) from
the image using the morphological erosion process. Include the selected SE in your
report. Your filtered image should look like the image depicted below.

Semester: Fall-2023 Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING

3. Read and view Fig0907(a)(text_gaps_1_and_2_pixels).tif in MATLAB.


a. The given image is a poor resolution image as the text is broken. What could be the
reason for it? What could have gone wrong during the image acquisition?
b. One way to bridge or join the gaps between the characters is to thick characters
which can be accomplished via dilation operation. Use the MATLAB imdilate
command with a 3 × 3 size square and diamond shape SEs. Display the dilated
images from both SEs along with the original image in a single 1 × 3 subplot grid
with proper titles. Which SE results in the better results for the said task and why?
What happens if we increase the size of the SE?
Opening & Closing
The opening of set 𝐴 by SE 𝐵, denoted 𝐴 ∘ 𝐵, is defined as
𝐴 ∘ 𝐵 = (𝐴 ⊖ 𝐵) ⊕ 𝐵
The closing of set 𝐴 by SE 𝐵, denoted 𝐴 ⋅ 𝐵, is defined as
𝐴 ∙ 𝐵 = (𝐴 ⊕ 𝐵) ⊖ 𝐵
4. Read and view Fig0911(a)(noisy_fingerprint).tif in MATLAB.
a. Filter the image using the morphological image processing.
b. Perform the opening followed by the closing morphological image processing on
the image using the MATLAB imopen and imclose commands. Use a square
SE of size 3 × 3. Display the three images: original image, opened image and
closing performed on the opened image, in a single 1 × 3 subplot grid with titles.

5. Read and view Task5Img.png in MATLAB.


a. Filter the image using the morphological image processing by removing all
diagonal and horizontal image components. The filtered image should contain only
the vertical image components of the same size as in the original image. Include
the SE along with the filtered image in your report.
b. Repeat part-b, but this the filtered image should contain only the horizontal
components of the same size as in the original image.

Semester: Fall-2023 Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir
UNIVERSITY OF ENGINEERING AND TECHNNOLOGY, TAXILA
DEPARTMENT OF ELECTRICAL ENGINEERING

Connected Component Analysis


Extraction of connected components from a binary image is central to many automated image
analysis applications. It can be used to count the objects and is frequently used in the automated
inspections.

6. Read and view Fig0918(a)(Chickenfilet with bones).tif in MATLAB.


a. Binarize the grayscale image using a suitable threshold value to retain most of the
bone fragments present in the image. Display the binary image.
b. Perform the connected component analysis using the command bwconncomp.
Open the structure variable from the workspace and see the number of objects
present in the image.
c. Retain the three largest objects present in the image and remove all the remaining
objects. Use the command bwareaopen to remove the objects.

7. Read and view the default MATLAB image circles.tif .


a. How many objects (circles) can you count in this image?
b. If we use the connected component analysis, how many objects will be returned?
Use the bwconncomp command to count the number of objects in the image. Is
there any difference when you use 4-connectivity in contrast to the default 8-
connectivity?
c. Pre-process the image to get the correct number of objects present in the image.

8. Understand the function and the usage of the following morphological image processing
commands in the MATLAB.
a. imbothat
b. imtophat
c. bwhitmiss

Semester: Fall-2023 Instructor: Dr. Junaid Mir


Session: 2K20 Designed by: Dr. Junaid Mir

You might also like