Download - Filtering an image is to apply a convolution
![Page 1: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/1.jpg)
Filtering an image is to apply a
convolution operation to an
image to achieve: blurring,
sharpening , edge extraction or
noise removal.
FILTERING OF IMAGES
![Page 2: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/2.jpg)
INPUT MATRIX TO BE TAKEN:
Sumw=(w1+w2+w3+w4+w5+w6+w7+w8+w9)
![Page 3: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/3.jpg)
RESULTANT MATRIX:
![Page 4: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/4.jpg)
The simplest convolution kernel or filter is
of size 3x3 with equal weights and is
represented as follows:
![Page 5: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/5.jpg)
LOW PASS FILTERS
This filter produces a simple average (or arithmetic
mean)of the nearest neighbors of each pixel in the
image.
It is one of a class of what are known as low pass filters.
They pass low frequencies in the image or equivalently
pass long wavelengths in the image
![Page 6: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/6.jpg)
LOW PASS FILTERS
It correspond to abrupt changes in image intensity, i.e.
edges. Thus we get blurring.
Also, because it is replacing each pixel with an average
of the pixels in its local neighborhood, one can
understand why it tends to blur the image.
Blurring is typical of low pass filters.
![Page 7: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/7.jpg)
CODE:
![Page 8: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/8.jpg)
INPUT GRAYSCALE IMAGE:
![Page 9: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/9.jpg)
MATLAB OUTPUT
![Page 10: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/10.jpg)
EFFECT OF USING LARGER MATRIX:
The result of using a larger filter(here 10X10) will be that
the low pass filtered image is blurrier than for the 5x5
case and the high pass filtered image will have thicker
edges.
![Page 11: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/11.jpg)
HIGH PASS FILTERS:
It passes only short wavelengths, i.e. where there
are abrupt changes in intensity
It removes long wavelengths, i.e. where the
image intensity is varying slowly.
Thus when applied to an image, it shows only
the edges in the image.
![Page 12: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/12.jpg)
HIGH PASS FILTERS:
High pass filtering of an image can be achieved
by the application of a low pass filter to the
image and subsequently subtraction of the low
pass filtered result from the image
In abbreviated terms, this is H = I – L, where H =
highpass filtered image, I = original image and L
= low pass filtered image.
![Page 13: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/13.jpg)
CODE:
j=zeros(5)
j(3,3)=1
h=ones(5)/25;
j=j-h;
g=filter2(j,gs,'same');
imshow(g/255)
![Page 14: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/14.jpg)
OUTPUT:
![Page 15: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/15.jpg)
3. FFT Filters:
FFT Filters provide precisely controlled low- and high-pass
filtering (smoothing and sharpening, respectively) using a
Butterworth characteristic.
The image is converted into spatial frequencies using a
Fast Fourier Transform, the appropriate filter is applied.
Then the image is converted back using an inverse FFT.
![Page 16: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/16.jpg)
PREDEFINED FILTERS IN MATLAB:
Predefined function used is fspecial:
Types available:
Averaging
![Page 17: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/17.jpg)
AVERAGING:
Code:
f = fspecial ('average')
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 18: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/18.jpg)
OUTPUT:
![Page 19: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/19.jpg)
DISK(Circular averaging filter):
Code:
f = fspecial (‘disk‘,5)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 20: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/20.jpg)
OUTPUT:
![Page 21: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/21.jpg)
GAUSSIAN(Low pass filter)
Code:
f = fspecial (‘gaussian‘,5)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 22: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/22.jpg)
LAPLACIAN:
Code:
f = fspecial (‘laplacian‘);
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 23: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/23.jpg)
OUTPUT:
![Page 24: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/24.jpg)
LOG(Laplacian of Gaussian filter):
Code:
f = fspecial (‘log‘,5)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 25: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/25.jpg)
OUTPUT:
![Page 26: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/26.jpg)
MOTION(Linear motion of camera):
Code:
f = fspecial (‘motion‘)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 27: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/27.jpg)
OUTPUT:
![Page 28: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/28.jpg)
PREWITT(Horizontal edge detection):
Code:
f = fspecial (‘prewitt‘)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 29: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/29.jpg)
OUTPUT:
![Page 30: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/30.jpg)
SOBEL(A Better version of prewitt):
Code:
f = fspecial (‘sobel‘)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o)
![Page 31: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/31.jpg)
OUTPUT:
![Page 32: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/32.jpg)
UNSHARP(Contrast enhancing filter):
Code:
f = fspecial (‘unsharp‘,5)
I = imread ('tulips.jpg');
gs = rgb2gray(i);
o = filter2(f,gs);
imshow(o/255)
![Page 33: Filtering an image is to apply a convolution](https://reader034.vdocument.in/reader034/viewer/2022042615/55a796d31a28ab7a1f8b4800/html5/thumbnails/33.jpg)
OUTPUT: