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

8 IP Expt Sharpen Spatial Domain Filtering

This document discusses image sharpening using spatial domain filtering. It describes spatial domain filtering as modifying an image based on pixel values in a neighborhood. Convolution is used to perform linear filtering, where each output pixel is a weighted sum of neighboring input pixels. High pass filters like Sobel are described as sharpening filters that enhance edges by approximating the image gradient. The Laplacian is also discussed as a second derivative filter that is more sensitive to noise but can enhance fine details. Sample code demonstrates applying a Laplacian filter to an image to perform edge detection.

Uploaded by

samarth
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)
48 views6 pages

8 IP Expt Sharpen Spatial Domain Filtering

This document discusses image sharpening using spatial domain filtering. It describes spatial domain filtering as modifying an image based on pixel values in a neighborhood. Convolution is used to perform linear filtering, where each output pixel is a weighted sum of neighboring input pixels. High pass filters like Sobel are described as sharpening filters that enhance edges by approximating the image gradient. The Laplacian is also discussed as a second derivative filter that is more sensitive to noise but can enhance fine details. Sample code demonstrates applying a Laplacian filter to an image to perform edge detection.

Uploaded by

samarth
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

Goa College of Engineering

Experiment No. 8 Date:

Image Sharpening using Spatial Domain Filtering

AIM: To sharpen an image by using spatial filtering

SOFTWARE TOOLS: MATLAB

THEORY :
Filtering is a technique for modifying or enhancing an image. Spatial domain operation or
filtering (the processed value for the current pixel processed value for the current pixel depends on
both itself and surrounding pixels). Hence Filtering is a neighborhood operation, in which the value
of any given pixel in the output image is determined by applying some algorithm to the values of
the pixels in the neighborhood of the corresponding input pixel. A pixel's neighborhood is some set
of pixels, defined by their locations relative to that pixel.
Linear filtering of an image is accomplished through an operation called convolution. Convolution
is a neighborhood operation in which each output pixel is the weighted sum of neighboring input
pixels. The matrix of weights is called the convolution kernel, also known as the filter. A convolution
kernel is a correlation kernel that has been rotated 180 degrees.
Following steps are used to compute the output pixel at position (x,y):
1. Rotate the correlation kernel 180 degrees about its center element to create a convolution kernel.
2. Slide the center element of the convolution kernel so that it lies on top of the (x,y) element of A.
3. Multiply each weight in the rotated convolution kernel by the pixel of A underneath.
4. Sum the individual products from step 3.

Types of filters:
Low pass filter:
High Pass Filter:

1|Page Dept. of Electronics and Telecommunication Engineering.


Goa College of Engineering

w(-1,-1) w(-1,0) w(-1,1)


a b

w(0,-1) w(0,0) w(0,1) g( x, y )    ω( s,t ) f ( x  s, y  t )


s  a t  b

g  ω f
w(1,-1) w(1,0) w(1,1)

High Pass Filter:


These are also called as sharpening filters. The main idea of sharpening is the enhance line

structures of other details in an image. Thus, the enhanced image contains the original image with

the line structures and edges in the image emphasized.

The first order derivative at an image location is approximated using intensity difference

values around a pixel. Examples of operators used for computing intensity differences are the

Robert’s cross gradient, Prewitt, and Sobel operators. Robert’s cross gradient operators use an

even sized mask and hence lack in symmetry. Prewitt operator uses a 3×3 mask, but performs

poorly in the presence of noise. Commonly used gradient operator is the sobel operator. It provides

for smoothing against noise while performing the differentiation.

Behavior 1st order derivative 2nd order derivative


f (x) is constant zero zero

f (x) is ramp or step non-zero at the onset and end of the non-zero at the onset and end of
ramp; non-zero along the ramp the ramp; zero along the ramp
The sign of the derivative
changes at the onset and end of
the ramp.
For a step transition a line
joining these two values crosses
the horizontal axis (i.e. crosses
zero) midway between the two
extremes.

Formulation
To compute 1st derivative at location x
we subtract the value of the function at To compute 2nd derivative at
that location from the next point. location x we use the previous
and the next points in the
computation.

2|Page Dept. of Electronics and Telecommunication Engineering.


Goa College of Engineering

1st order derivative 2nd order derivative

The Laplacian operator Δ2f is a 2nd order


derivative. The Laplacian for 2 variables
is formulated as follows:
Denoting we

have The magnitude of vector

Taking and

The filter mask to implement the


Laplacian:

Robert’s cross gradient operator mask:

Prewitt operator mask

Sobel operator mask

The sobel mask approximates the gx and gy using a 3 × 3


neighborhood. These masks are called as the sobel operators.
The Sobel operator has the added advantage that it can do
noise smoothing (because of the factor 2 in the center term)
while detecting the edges.

The formulated masks give a zero response in areas of The formulated masks give a zero
constant intensity. response in areas of constant intensity.

3|Page Dept. of Electronics and Telecommunication Engineering.


Goa College of Engineering
Note that the masks are used to compute the
gx and gy components. The gradient magnitude M(x,y) is then Laplacian does not involve computing
computed using their absolute values or squaring and absolute values, squares or square-
summing them. The latter steps constitute non-linear root. It is a linear operator.
operations.

The Laplacian operator is isotropic. It is


rotation invariant. The final result is the
Isotropic properties are preserved only for rotational
same whether we first rotate the image
increments of 90o.
and then apply the filter, or apply the
filter first and then rotate the image.

The Laplacian’s response is not as strong


The gradient gives a lower response compared to Laplacian to
as the gradient’s response in areas of
noise and fine details. The gradient has a stronger average
intensity ramps and steps. The Laplacian
response in areas of significant intensity transitions. Hence the
is much more sensitive to noise and fine
gradient is better suited to enhance prominent edges in the
details. Hence Laplacian is better suited
image.
to enhance fine details in the image.

The results of high pass filtering can be observed in figure below:

Applications:
Image denoising
Image enhancement (i.e., “make the image more vivid”)
Edge detection, etc.

Algorithm:
1. Read input image.
2. For each pixel compute the filtered value according to the filter/mask applied.
3. Do this for whole image.
4. Display the input image and filtered images.

4|Page Dept. of Electronics and Telecommunication Engineering.


Goa College of Engineering
Source Code:
clc;
%% create a new figure to show the image.
newImg = imread('Water lilies.jpg');
figure(1);
imshow(newImg);
figure(2);
%% create laplacian filter.
H = fspecial('laplacian');
%% apply laplacian filter.
blurred = imfilter(newImg,H);
imshow(blurred); title('Edge detected Image')

%% Laplacian filter is a second derivative edge detector operator .Laplacian is more sensitive to
%noise than sobel and prewitt. Laplacian calculate the difference of center point to the surrounding
%pixels.

%Extra Code Snippets

---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------

5|Page Dept. of Electronics and Telecommunication Engineering.


Goa College of Engineering
CONCLUSION :
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------

6|Page Dept. of Electronics and Telecommunication Engineering.

You might also like