Tuesday, September 30, 2014

Image Processing -Matlab Tutorial 2

Today I'm going to present you some spatial filtering methods. This methods are known as Mask processing methods as well. These filters are used for different purposes.like


  • Image Enhancements
  • Edge Detection
I advise you to find the some applications of these filtering methods.

Smoothing Filters

Averaging Filter

Original Image                                                         Transformed Image
Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%Average filters
H=fspecial('average',[3 3]);
avg=imfilter(gray1,H);
figure,imshow(avg);



Gaussian Filter

Original Image                                                         Transformed Image
Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%Gaussian filters
H=fspecial('gaussian');
gaus=imfilter(gray1,H);
figure,imshow(gaus);



Median Filter
Original Image                                          Noise Added Image                                 Median Filtered Image

Matlab Code


clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%Median filters
 
%adding noise to show the enhancement of median filter where noisy images
J = imnoise(gray1,'salt & pepper',0.02);          
%SSfigure,imshow(J);
M3=medfilt2(J);
figure, imshow(J),figure, imshow(M3);



Sharpening Filters

High Pass Filter

          Original Image                                   High pass filtered Image
Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);
 
%Shapenning filters
%high pass filter 
%A=1
H1=[-1 -1 -1; -1 8 -1; -1 -1 -1]
img1=imfilter(gray1,H1);
figure,imshow(img1);


High Boosted Image

Original Image                                   Transformed Image
Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%high boosted filter
%A=2
H2=[-1 -1 -1; -1 17 -1; -1 -1 -1]
img2=imfilter(gray1,H2);
figure,imshow(img2);


Roberts Filter

      Original Image                                     x- transformed image                               y- transformed image
















Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%Roberts
H3=[1 0; 0 -1]
img3=imfilter(gray1,H3);
figure,imshow(img3);
 
H4=[0 1;-1 0]
img4=imfilter(gray1,H4);
figure,imshow(img4);

Prewitt Filter

                 Original Image                                           x- transformed image                               y- transformed image        
















Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);

%Prewitt
H5=[-1 -1 -1;0 0 0;1 1 1];
img5=imfilter(gray1,H5);
figure,imshow(img5);
 
H6=[-1 0 1;-1 0 1;-1 0 1];
img6=imfilter(gray1,H6);
figure,imshow(img6);


Sobel Filter

  Original Image                                           x- transformed image                               y- transformed image















Matlab Code

clear all
%Load images
[im1 map1]=imread('myimagecmp.jpg');
imshow(im1)
gray1=rgb2gray(im1);
figure, imshow(gray1);


%Sobel
H7=[-1 -2 -1;0 0 0;1 2 1];
img7=imfilter(gray1,H7);
figure,imshow(img7);
 
H8=[-1 0 1;-2 0 2;-1 0 1];
img8=imfilter(gray1,H8);
figure,imshow(img8);


No comments:

Post a Comment