0% found this document useful (0 votes)
8 views4 pages

Exp 6

The document outlines an experiment focused on implementing image sharpening filters and edge detection using gradient filters in MATLAB. It details the theory behind sharpening filters like the Laplacian and Unsharp Masking, as well as edge detection techniques using Sobel, Prewitt, and Roberts operators. The procedure includes reading and processing an image, applying filters, and displaying results, with an emphasis on hands-on learning outcomes for students.
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)
8 views4 pages

Exp 6

The document outlines an experiment focused on implementing image sharpening filters and edge detection using gradient filters in MATLAB. It details the theory behind sharpening filters like the Laplacian and Unsharp Masking, as well as edge detection techniques using Sobel, Prewitt, and Roberts operators. The procedure includes reading and processing an image, applying filters, and displaying results, with an emphasis on hands-on learning outcomes for students.
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/ 4

EXPERIMENT – 6

AIM: Implementation of Image Sharpening filters and Edge Detection using Gradient Filters.

APPARATUS: MATLAB version R2023b, jpeg image.

THEORY:

1) Image Sharpening Filters: Image sharpening is a technique used to enhance the details and edges
in an image, making it appear clearer and more defined. Sharpening filters work by increasing the
contrast of edges and high-frequency components in the image. There are various sharpening filters,
but two common ones are the Laplacian filter and the Unsharp Masking (USM) filter.

1.1) Laplacian Filter: The Laplacian filter is a high-pass filter that enhances the edges and details
in an image by emphasizing the second derivative of the image intensity. It is often used for
edge detection and image sharpening.
1.2) Unsharp Masking (USM) Filter: The Unsharp Masking (USM) filter is a sharpening
technique that works by subtracting a blurred version of the image from the original image.
This enhances the edges and details in the image while reducing noise.

2) Edge Detection using Gradient Filters: Edge detection is a fundamental operation in image
processing that aims to identify the boundaries between objects in an image. Gradient-based edge
detection methods compute the rate of change of pixel intensity values in the image to locate edges.
Common gradient-based edge detection filters include the Sobel, Prewitt, and Roberts operators.

2.1) Sobel Operator: The Sobel operator is a widely used edge detection filter that enhances
edges by computing intensity changes in both horizontal and vertical directions using 3×3
convolution kernels. It emphasizes edges more than Prewitt and produces thicker,
smoother edges, making it suitable for detecting significant boundaries while reducing noise
sensitivity.

2.2) Prewitt Operator: The Prewitt operator is similar to Sobel but uses simpler, uniform-
weighted kernels. It also detects edges in horizontal and vertical directions but with less
emphasis on intensity variation. It is computationally faster than Sobel and provides
sharper but thinner edges, making it better for noisy images.

2.3) Roberts Operator: The Roberts operator is the simplest gradient-based edge detector,
using 2×2 convolution kernels to detect diagonal edges. It works best for sharp, fine
details in high-contrast images but is more sensitive to noise compared to Sobel and
Prewitt. It is the fastest among the three but may not handle smooth edges well.

PROCEDURE:

1. Read the Image: Read the image you want to process using the imread function.
2. Convert to Grayscale: Convert the image to grayscale if it is in RGB format using the rgb2gray
function.
3. Apply Image Sharpening Filters:

• Define a sharpening kernel (e.g., Laplacian, unsharp masking).


• Use the imfilter function with the defined kernel to apply the sharpening filter.

4. Apply Edge Detection using Gradient Filters:

• Define gradient filter kernels (e.g., Sobel, Prewitt).


• Use the imfilter function with the gradient filter kernels to compute gradient magnitude and
direction.
• Optionally, apply non-maximum suppression and edge thinning to refine the edges.

5. Display the Original and Processed Images:

• Display the original image along with the images after sharpening and edge detection.

6. Adjust Parameters and Experiment:

• Modify the sharpening filter kernels and gradient filter kernels to observe different effects

Code:
% Read the image
i = imread('edge_detection.jpeg');

% Convert to grayscale if it's RGB


if size(i,3) == 3
g = rgb2gray(i);
else
g = i;
end

% Create a figure for better visualization


figure;

% Display Original and Grayscale Images


subplot(3,3,1); imshow(i); title('Original Image');
subplot(3,3,2); imshow(g); title('Grayscale Image');

% Apply Laplacian Filter for Edge Enhancement


laplacian_filter = fspecial('laplacian', 0.3); % Increased sharpness effect
laplacian_result = imfilter(g, laplacian_filter, 'replicate');
subplot(3,3,3); imshow(laplacian_result); title('Laplacian Filter');

% Apply Sobel Edge Detection


sobel_edges = edge(g, 'sobel');
subplot(3,3,4); imshow(sobel_edges); title('Sobel Edge Detection');
% Apply Prewitt Edge Detection
prewitt_edges = edge(g, 'prewitt');
subplot(3,3,5); imshow(prewitt_edges); title('Prewitt Edge Detection');

% Apply Roberts Edge Detection


roberts_edges = edge(g, 'roberts');
subplot(3,3,6); imshow(roberts_edges); title('Roberts Edge Detection');

% Apply Horizontal and Vertical Sobel Edge Detection


sobel_horizontal = edge(g, 'sobel', 'horizontal');
sobel_vertical = edge(g, 'sobel', 'vertical');

subplot(3,3,7); imshow(sobel_horizontal); title('Sobel - Horizontal');


subplot(3,3,8); imshow(sobel_vertical); title('Sobel - Vertical');

% Combine Horizontal and Vertical Sobel Edges


sobel_combined = sobel_horizontal | sobel_vertical;
subplot(3,3,9); imshow(sobel_combined); title('Sobel - Combined');

Result:
Learning Outcome:
Students learned how to apply image sharpening filters such as the Laplacian to enhance edges and
details. They understood the principles of gradient-based edge detection using Sobel, Prewitt, and
Roberts operators and how these methods differ in detecting edges in various directions. Additionally,
they gained hands-on experience in implementing these techniques in MATLAB and analyzing their
effects on images.

You might also like