filtering an image is to apply a convolution

Post on 16-Jul-2015

126 Views

Category:

Engineering

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Filtering an image is to apply a

convolution operation to an

image to achieve: blurring,

sharpening , edge extraction or

noise removal.

FILTERING OF IMAGES

INPUT MATRIX TO BE TAKEN:

Sumw=(w1+w2+w3+w4+w5+w6+w7+w8+w9)

RESULTANT MATRIX:

The simplest convolution kernel or filter is

of size 3x3 with equal weights and is

represented as follows:

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

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.

CODE:

INPUT GRAYSCALE IMAGE:

MATLAB OUTPUT

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.

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.

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.

CODE:

j=zeros(5)

j(3,3)=1

h=ones(5)/25;

j=j-h;

g=filter2(j,gs,'same');

imshow(g/255)

OUTPUT:

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.

PREDEFINED FILTERS IN MATLAB:

Predefined function used is fspecial:

Types available:

Averaging

AVERAGING:

Code:

f = fspecial ('average')

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

DISK(Circular averaging filter):

Code:

f = fspecial (‘disk‘,5)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

GAUSSIAN(Low pass filter)

Code:

f = fspecial (‘gaussian‘,5)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

LAPLACIAN:

Code:

f = fspecial (‘laplacian‘);

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

LOG(Laplacian of Gaussian filter):

Code:

f = fspecial (‘log‘,5)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

MOTION(Linear motion of camera):

Code:

f = fspecial (‘motion‘)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

PREWITT(Horizontal edge detection):

Code:

f = fspecial (‘prewitt‘)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

SOBEL(A Better version of prewitt):

Code:

f = fspecial (‘sobel‘)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o)

OUTPUT:

UNSHARP(Contrast enhancing filter):

Code:

f = fspecial (‘unsharp‘,5)

I = imread ('tulips.jpg');

gs = rgb2gray(i);

o = filter2(f,gs);

imshow(o/255)

OUTPUT:

top related