DIP Lab.5 L5
DIP Lab.5 L5
➢ Mean filters are averaging filters that replace the center pixel with the average of neighboring pixel values, is a
linear filter.
Mask=
➢ Median filter: Sorts the pixel values in a small neighborhood and replaces the center pixel with the middle
value in the sorted list, is a nonlinear filter.
➢ Enhancement filters:
I. Laplacian Filter: Will bring out image details equally in all directions.
II. Difference Filters will enhance details in the direction specific to the mask selected.
❖ Noise is any undesired information that contaminates an image.
I(r,c) y(r,c)=I(r,c)+n(r,c)
n(r,c)
noise
❖ we can add a noise to an image by using the MATLAB function:
y=imnoise(I,Type,Parameters)
where
- TYPE is a string that can have one of these values
'salt & pepper' "On and Off" pixels
'gaussian' Gaussian white noise with constant mean and variance
- Parameters:
M (mean) default to 0
'gaussian'
V (variance) default to 0.01
'salt & pepper' D (noise density) default to 0.05
NOTES:
1- In mean filtering we will use conv2 MATLAB function
2- In median filtering we will use medfilt2 MATLAB function which has the following syntax:
B = medfilt2(A, [M N])
Where
A is the input image
[M N] is the size of window used for median filtering. 3 × 3 or 5 × 5 or 7 × 7 are typical values for the
window size.
Image with salt and pepper noise image with gaussian noise
1
salt and pepper noise remove using median filter gaussian noise remove using median filter
➢ [Task 2: Using Enhancement Filters to Highlight the Edges and Details of an Image]
Write and execute the following script in MATALB, then write your observations on the result:
clc
clear
close all
I=imread('cameraman.tif');
m=[0 -1 0;-1 5 -1;0 -1 0];
y=imfilter(I,m,'conv');
m1=[0 1 0;0 1 0;0 -1 0];
m2=[0 0 0;1 1 -1;0 0 0];
m3=[1 0 0;0 1 0;0 0 -1];
m4=[0 0 1;0 1 0;-1 0 0];
y1=imfilter(I,m1,'conv');
y2=imfilter(I,m2,'conv');
y3=imfilter(I,m3,'conv');
y4=imfilter(I,m4,'conv');
imshow(I)
figure,imshow(y),title('laplacian filter')
figure,imshow(y1),title('enhanced edges in horizontal direction')
figure,imshow(y2),title('enhanced edges in vertical direction')
figure,imshow(y3),title('enhanced edges in right diagonal direction')
figure,imshow(y4),title('enhanced edges in left diagonal direction')
Eng./Maged Albadany