-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMedian_Max_Min_Filtering.m
More file actions
54 lines (46 loc) · 1.33 KB
/
Median_Max_Min_Filtering.m
File metadata and controls
54 lines (46 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
clc;
clear all;
close all;
img1 = imread('Images\circuit_board_2.png');
img1 = rgb2gray(img1);
img = imnoise(img1,'salt & pepper',0.01);
img = double(img);
%noise = imnoise(img,'salt & pepper',0.1);
%figure; imshow(uint8(noise));
k = input('Enter size of Filter : ');
[n,m] = size(img);
fr = floor(k/2);
fr = fr+1;
for i=1:n
for j=1:m
window = zeros(k*k,1);
x = 1;
for p=i-(fr-1):i+fr-1
if(p<1) %At the edges of an image we are missing pixels to form a neighbourhood.
p = 1;
end
if(p>n)
p = n;
end
for q=j-(fr-1):j+fr-1
if(q<1)
q = 1;
end
if(q>m)
q = m;
end
window(x) = img(p,q);
x = x+1;
end
end
med = sort(window);
medfilted(i,j) = double(med(fr));
minfilted(i,j) = double(med(1));
maxfilted(i,j) = double(med(k*k));
end
end
figure; imshow(uint8(img1)); title('Original Image');
figure; imshow(uint8(img)); title('After Adding salt & pepper noise');
figure; imshow(uint8(medfilted)); title('After Median Filter');
figure; imshow(uint8(minfilted)); title('After Min Filter');
figure; imshow(uint8(maxfilted)); title('After Max Filter');