Digital Image Processing
( DSE – 3 )
Practical File
Submitted By
ALKA VERMA
Roll No.: 23DOECBTEC000094 (Batch – ECE B)
B. Tech Electronics and Communication Engineering
(5rd Semester)
To
Dr. Gurinder Singh
Assistant Professor
Department of Electronics and Communication Engineering
FACULTY OF TECHNOLOGY
UNIVERSITY OF DELHI
NEW DELHI – 110007
(2025 – 2026)
ASSIGNMENT 8
Image Morphological operation and Boundary Extraction using MATLAB/Python
1. Morphological Operations on a Grayscale Image
Write a MATLAB or Python program to perform the following morphological operations on
a grayscale image:
1. Erosion
2. Dilation
3. Opening
4. Closing
Your program must include:
• Reading and converting the image to grayscale
• Creating a 5×5 structuring element
• Applying all four operations
• Displaying the results in a single figure using subplots
• A short explanation of how each operation modifies the image
clc;
clear all;
close all;
% Step 1: Read image and convert to grayscale
img = imread('[Link]');
figure,
imshow(img),
title('Original Image');
% Step 2: Create 5×5 structuring element
SE = strel('square', 5);
% Step 3: Apply morphological operations
% Erosion
eroded = imerode(img, SE);
% Dilation
dilated = imdilate(img, SE);
% Opening (erosion followed by dilation)
opened = imopen(img, SE);
% Closing (dilation followed by erosion)
closed = imclose(img, SE);
% Step 4: Display results
figure;
subplot(2,3,1),
imshow(img),
title('Original Image');
subplot(2,3,2),
imshow(eroded),
title('Erosion');
subplot(2,3,3),
imshow(dilated),
title('Dilation');
subplot(2,3,4),
imshow(opened),
title('Opening');
subplot(2,3,5),
imshow(closed),
title('Closing');
2. Boundary Extraction Using Morphology
Write a MATLAB/Python program to extract the boundary of objects in a binary or
grayscale image using the formula:
Boundary = Dilation(A) − Erosion(A)
Your answer should include:
• Code to read and preprocess the image
• Morphological dilation and erosion
• Computation of boundary image
• Display of original and boundary-extracted image
• Interpretation of the obtained boundary
%2
% Step 1: Read and preprocess the image
I = imread('[Link]'); % or any image
bw = imbinarize(I); % convert to binary (thresholding)
% Step 2: Create structuring element
SE = strel('square', 3); % 3x3 structuring element
% Step 3: Perform dilation and erosion
dilated_img = imdilate(bw, SE);
eroded_img = imerode(bw, SE);
% Step 4: Boundary extraction
boundary_img = dilated_img - eroded_img;
% Step 5: Display results
figure;
subplot(1,4,1)
imshow(bw); title('Original Binary Image');
subplot(1,4,2)
imshow(dilated_img); title('Dilated Image');
subplot(1,4,3)
imshow(eroded_img); title('Eroded Image');
subplot(1,4,4)
imshow(boundary_img); title('Extracted Boundary');