0% found this document useful (0 votes)
2 views2 pages

Edge Detection Using Canny Edge Detector: AIM Source Code

The document describes an experiment on edge detection using the Canny edge detector. It includes source code that loads an image, converts it to grayscale, segments it using thresholding, and applies Canny edge detection. The results are displayed in a series of plots, confirming successful implementation of the edge detection process.

Uploaded by

munimahesh2605
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)
2 views2 pages

Edge Detection Using Canny Edge Detector: AIM Source Code

The document describes an experiment on edge detection using the Canny edge detector. It includes source code that loads an image, converts it to grayscale, segments it using thresholding, and applies Canny edge detection. The results are displayed in a series of plots, confirming successful implementation of the edge detection process.

Uploaded by

munimahesh2605
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/ 2

Experiment.No: 4 Name : C.

Muni Mahesh
Roll Number : 21121A0534

Edge detection using Canny edge detector


AIM : Implement Edge detection in a segmented binary image using Canny edge detector.

SOURCE CODE:

import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load the original image


original_image = cv2.imread('tito.jpg')
original_image_rgb = cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB) # Convert to
RGB for display

# Convert to grayscale
gray_image = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)

# Perform basic thresholding for segmentation


def segment_image(gray_image, threshold_value):
_, binary_image = cv2.threshold(gray_image, threshold_value, 255,
cv2.THRESH_BINARY)
return binary_image

# Set the threshold value for segmentation


threshold_value = 127

# Segment the image


binary_image = segment_image(gray_image, threshold_value)

# Apply Canny edge detection


def apply_canny_edge_detection(binary_image, low_threshold, high_threshold):
edges = cv2.Canny(binary_image, low_threshold, high_threshold)
return edges

# Set thresholds for Canny edge detection


low_threshold = 50
high_threshold = 150

# Apply Canny edge detection


edges = apply_canny_edge_detection(binary_image, low_threshold, high_threshold)

# Display the results


plt.figure(figsize=(18, 6))

plt.subplot(1, 3, 1)
plt.title("Original Image")
plt.imshow(original_image_rgb)
plt.axis('off')
plt.subplot(1, 3, 2)
plt.title("Segmented Binary Image")
plt.imshow(binary_image, cmap='gray')
plt.axis('off')

plt.subplot(1, 3, 3)
plt.title("Edges Detected with Canny")
plt.imshow(edges, cmap='gray')
plt.axis('off')

plt.show()

OUTPUT:

RESULT: The above program for edge detection in a segmented binary image using Canny
edge detector has been implemented successfully.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy