Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

1.

Filter mean 1/9 (3x3)


I = imread('family.jpg');
a=rgb2gray(I);
[baris,kolom]=size(a);
a1=double(a);
asli=0;
for i=1:baris
for j=1:kolom
asli=asli+(a1(i,j)^2);
end
end
I_noise = imnoise (a, 'salt & pepper', 0.05);
h = ones (3,3)/3^2;
b = imfilter (I_noise,h);
[baris1,kolom1]=size(b);
b1=double(b);
noise=0;
for y=1:baris1
for z=1:kolom1
noise=noise+((a1(y,z)-b1(y,z))^2);
end
end
snr = 10*(log10(asli/noise));
subplot
subplot
subplot
subplot
SNR

(2,2,1),
(2,2,2),
(2,2,3),
(2,2,4),

imshow
imshow
imshow
imshow

(I), title
(a), title
(I_noise),
(b), title

2. Filter mean 1/16 (3x3)


I = imread('family.jpg');
a=rgb2gray(I);
[baris,kolom]=size(a);
a1=double(a);
asli=0;
for i=1:baris

('gambar asli')
('gray scale')
title ('gambar bernoise')
('gambar setelah difilter')

end

for j=1:kolom
asli=asli+(a1(i,j)^2);
end

I_noise = imnoise (a, 'salt & pepper', 0.05);


h = [1 2 1 ; 2 4 2 ; 1 2 1 ]/16;
b = imfilter (I_noise,h);
[baris1,kolom1]=size(b);
b1=double(b);
noise=0;
for y=1:baris1
for z=1:kolom1
noise=noise+((a1(y,z)-b1(y,z))^2);
end
end
snr = 10*(log10(asli/noise));
subplot
subplot
subplot
subplot
SNR

(2,2,1),
(2,2,2),
(2,2,3),
(2,2,4),

imshow
imshow
imshow
imshow

(I), title
(a), title
(I_noise),
(b), title

('gambar asli')
('gray scale')
title ('gambar bernoise')
('gambar setelah difilter')

3. Filter median (3x3)


. I = imread('family.jpg');
a=rgb2gray(I);
[baris,kolom]=size(a);
a1=double(a);
asli=0;
for i=1:baris
for j=1:kolom
asli=asli+(a1(i,j)^2);
end
end
I_noise = imnoise (a, 'salt & pepper', 0.05);
b = medfilt2(I_noise);
[baris1,kolom1]=size(b);
b1=double(b);

noise=0;
for y=1:baris1
for z=1:kolom1
noise=noise+((a1(y,z)-b1(y,z))^2);
end
end
snr = 10*(log10(asli/noise));
subplot
subplot
subplot
subplot
SNR

(2,2,1),
(2,2,2),
(2,2,3),
(2,2,4),

imshow
imshow
imshow
imshow

(I), title
(a), title
(I_noise),
(b), title

('gambar asli')
('gray scale')
title ('gambar bernoise')
('gambar setelah difilter')

Dapat disimpulkan bahwa SNR menggunakan filter median lebih bagus dari filter
mean.

You might also like