0% found this document useful (0 votes)
23 views5 pages

Image

The document outlines two image segmentation techniques: edge-based segmentation using the Sobel operator and threshold-based segmentation. The Sobel method detects edges by calculating gradients in both horizontal and vertical directions, while the thresholding technique separates pixels into foreground and background based on intensity values. Both methods include algorithms and MATLAB programs for implementation.

Uploaded by

thilagalakshmik
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)
23 views5 pages

Image

The document outlines two image segmentation techniques: edge-based segmentation using the Sobel operator and threshold-based segmentation. The Sobel method detects edges by calculating gradients in both horizontal and vertical directions, while the thresholding technique separates pixels into foreground and background based on intensity values. Both methods include algorithms and MATLAB programs for implementation.

Uploaded by

thilagalakshmik
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/ 5

EDGE-BASED SEGMENTATION

OBJECTIVE:
To perform edge-based segmentation of an image by detecting boundaries using
the Sobel edge detection operator. This process highlights regions in the image
where intensity changes significantly, typically corresponding to object edges.

ALGORITHM:

1. Read the input image and convert it to grayscale (if it's not already).
2. Apply Sobel filters in both horizontal and vertical directions to compute gradients:
Gx: Gradient in the x-direction (horizontal).
Gy: Gradient in the y-direction (vertical).
3. Compute the gradient magnitude using:

4. Normalize the gradient magnitude to scale values between 0 and 1.


5. Apply a threshold to the normalized gradient to create a binary edge map.
6. Display the results using MATLAB subplot for visualization

TECHNIQUE USED:

Edge Detection using the Sobel Operator

 The Sobel operator is a first-order derivative filter that emphasizes regions of


high spatial frequency corresponding to edges.

 It uses two 3x3 convolution kernels:

 One for detecting changes in the horizontal direction.

 One for detecting changes in the vertical direction.

 The resulting gradients are combined to produce an edge magnitude image.


PROGRAM:

Edge-based segmentation using Sobel operator in MATLAB

% Read the input image


I = imread('/MATLAB Drive/d4d7ea481b3cf098a81b46cbb7857dea.jpg');
I_gray = rgb2gray(I); % Convert to grayscale if necessary
% Apply Sobel operator to find horizontal and vertical gradients
Gx = imfilter(double(I_gray), fspecial('sobel')', 'replicate'); % Horizontal
Gy = imfilter(double(I_gray), fspecial('sobel'), 'replicate'); % Vertical
% Compute gradient magnitude
G = sqrt(Gx.^2 + Gy.^2);
% Normalize gradient image to range [0, 1]
G = G / max(G(:));
% Threshold the gradient to get binary edge map
threshold = 0.2; % You can adjust this value
edge_map = G > threshold;
% Display results
figure;
subplot(1, 3, 1), imshow(I_gray), title('Grayscale Image');
subplot(1, 3, 2), imshow(G), title('Gradient Magnitude');
subplot (1, 3, 3), imshow(edge_map), title('Edge-based Segmentation using sobal');
% Optional: Save edge map
imwrite(edge_map, 'edge_segmentation.png');
THRESHOLD BASED SEGMENTATION

OBJECTIVE:
To perform image segmentation using a simple thresholding technique
by converting an image to grayscale and separating pixels into foreground and
background based on intensity values.

ALGORITHM:
Read the Image:
Load an input image file using imread.
Convert to Grayscale:
 Check if the image is RGB (3 channels).
 If so, convert it to grayscale using rgb2gray.
 If already grayscale, use the image as-is.
Set Threshold:
 Choose a fixed threshold value between 0 and 255.
Apply Thresholding:
 Create a binary image initialized to zeros.
 Assign pixels with intensity > threshold to 1 (white/foreground).
 Remaining pixels stay 0 (black/background).

Display Images:
 Show original, grayscale, and binary segmented images using imshow.

TECHNIQUE USED:
Threshold-Based Image Segmentation
 Type: Global Thresholding (fixed threshold value)
 Concept: Pixels are divided into two classes based on intensity:
 Foreground (object): Pixels with intensity > threshold.
 Background: Pixels with intensity ≤ threshold.
 Approach: Simple and efficient for high-contrast images where the
foreground and background are clearly distinguishable.
PROGRAM:
% Read the image
img = imread('/MATLAB Drive/d4d7ea481b3cf098a81b46cbb7857dea.jpg');
imshow(img), title('Original Image');
% Convert to grayscale if image is RGB
if size(img, 3) == 3
gray = rgb2gray(img);
else
gray = img;
end
figure, imshow(gray), title('Grayscale Image');
% Set threshold value (between 0 and 255)
threshold = 100; % You can adjust this value
% Apply thresholding
binaryImage = zeros(size(gray)); % Initialize binary image
binaryImage(gray > threshold) = 1; % Pixels above threshold set to 1 (white)
% Display segmented image
title(['Segmented Image (Threshold = ', num2str(threshold), ')']);

You might also like