0% found this document useful (0 votes)
15 views6 pages

Fosip Expt 9

This document outlines an experiment on using morphological operations for boundary extraction in digital images, comparing it with traditional edge detection methods like Sobel. The implementation demonstrates the effectiveness of mathematical morphology in producing clear boundaries and highlights its advantages, such as noise resistance and lower computational cost. The conclusion emphasizes the applicability of morphological boundary extraction in various fields, including object counting and medical imaging.

Uploaded by

varsha bojja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Fosip Expt 9

This document outlines an experiment on using morphological operations for boundary extraction in digital images, comparing it with traditional edge detection methods like Sobel. The implementation demonstrates the effectiveness of mathematical morphology in producing clear boundaries and highlights its advantages, such as noise resistance and lower computational cost. The conclusion emphasizes the applicability of morphological boundary extraction in various fields, including object counting and medical imaging.

Uploaded by

varsha bojja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

BHARATIYA VIDYA BHAVAN’S

SARDAR PATEL INSTITUTE OF TECHNOLOGY


Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing

NAME: Tejas Billava (2022300009)


Sushant Bodade (2022300010)
Varsha Bojja (2022300012)

CLASS: TE COMPS A

EXPERIMENT 9

Aim: Use Image Processing using Morphological Operation

Objective: The objective of this implementation is to demonstrate the application of


mathematical morphology for boundary extraction in digital images.
Specifically, the aim is to:
● Apply morphological operations to extract object boundaries from
binary images
● Compare the effectiveness of morphological boundary extraction
with traditional edge detection methods like Sobel
● Implement an efficient, practical application of morphological theory
as discussed in the research paper "Morphological Operations for
Image Processing: Understanding and its Applications"

Introduction: Mathematical morphology is a theoretical model for digital image


processing based on set theory rather than traditional linear signal
processing. It provides a powerful framework for analyzing shapes and
structures within an image. Morphological operations are particularly useful
for:
● Removing imperfections in image structure
● Shape extraction and analysis
● Image segmentation
● Feature detection and recognition
The fundamental operations in mathematical morphology are dilation and
erosion, which can be combined to create more complex operations such
as opening, closing, and boundary extraction.
Boundary extraction is a crucial task in image processing and computer
vision, as it identifies the outer edges of objects, allowing for shape analysis
and object recognition. While traditional methods like Sobel, Prewitt, and
Canny edge detectors use gradient-based approaches, morphological
boundary extraction offers an alternative approach based on set
operations, which can be particularly effective for binary images.

The morphological boundary extraction algorithm leverages the principle


that the boundary of an object can be obtained by subtracting the eroded
version of the image from the original image. This operation yields the outer
pixels that were removed during erosion.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing
Block
Diagram:

Implementati import numpy as np


on: import matplotlib.pyplot as plt
from skimage import io, color, filters, morphology
from PIL import Image
import os

def morphological_boundary_extraction(image):
"""
Extract the boundary of objects in an image using
morphological operations.
As per the paper, boundary extraction can be done by
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing
subtracting the eroded image from the original.

Args:
image: Input binary image

Returns:
The boundary of objects in the image
"""
# Define a structuring element (as mentioned in the
paper)
# Using a 3x3 square structuring element
se = np.ones((3, 3), dtype=np.uint8)

# Perform erosion
eroded = morphology.erosion(image, se)

# Extract boundary by using logical_and with the


original image and NOT of eroded image
# This is equivalent to subtraction for binary images
boundary = np.logical_and(image,
np.logical_not(eroded))

return boundary

def main():
# Specify the path to your local image
image_path = "man.jpg" # Change this to your image
file path

try:
# Check if file exists
if not os.path.exists(image_path):
raise FileNotFoundError(f"Image file not
found: {image_path}")

# Load and convert to grayscale image


img =
np.array(Image.open(image_path).convert('L'))
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing
# Threshold image to binary
binary_img = img > 128

# Apply boundary extraction using morphological


operation
boundary =
morphological_boundary_extraction(binary_img)

# For comparison, use Sobel edge detector as


mentioned in paper
sobel_edges = filters.sobel(img)

# Plot the results


plt.figure(figsize=(12, 4))

plt.subplot(1, 3, 1)
plt.imshow(img, cmap='gray')
plt.title('Original Image')
plt.axis('off')

plt.subplot(1, 3, 2)
plt.imshow(boundary, cmap='gray')
plt.title('Boundary using Morphology')
plt.axis('off')

plt.subplot(1, 3, 3)
plt.imshow(sobel_edges, cmap='gray')
plt.title('Edge Detection using Sobel')
plt.axis('off')

plt.tight_layout()
plt.show()

except Exception as e:
print(f"Error loading image: {e}")
print("Using a test image instead...")

# Create a simple test image if loading fails


img = np.zeros((200, 200), dtype=np.uint8)
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing
img[50:150, 50:150] = 255 # Create a square

# Convert to binary
binary_img = img > 128

# Apply boundary extraction


boundary =
morphological_boundary_extraction(binary_img)

# For comparison, use Sobel edge detector


sobel_edges = filters.sobel(img)

# Plot the results


plt.figure(figsize=(12, 4))

plt.subplot(1, 3, 1)
plt.imshow(img, cmap='gray')
plt.title('Test Image')
plt.axis('off')

plt.subplot(1, 3, 2)
plt.imshow(boundary, cmap='gray')
plt.title('Boundary using Morphology')
plt.axis('off')

plt.subplot(1, 3, 3)
plt.imshow(sobel_edges, cmap='gray')
plt.title('Edge Detection using Sobel')
plt.axis('off')

plt.tight_layout()
plt.show()

if name == " main ":


main()
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING


SUBJECT: Fundamental of Signal and Image Processing
Output:

Conclusion:
This implementation shows that morphological operations effectively extract
boundaries in binary images. Key insights include:

● Effectiveness: Produces clear, single-pixel wide boundaries.

● Compared to Sobel/gradient methods: Offers cleaner, more


connected edges, better noise resistance, and lower computational
cost.

● Structuring Element: Results depend on the element used; a 3×3


square is generally effective, though other shapes suit specific
needs.

● Limitations: Best suited for binary images; grayscale or color


images may need pre-processing.

● Applications: Useful in object counting, shape analysis, document


processing, medical imaging, and quality control.

Morphological boundary extraction is a robust, noise-resistant alternative to


traditional edge detection, especially in binary image analysis.

You might also like