19 Mart 2012 Pazartesi

Matlab - filter Implementation

filter2 fonkiyonuyla yapılan bluring işleminin implementasyonu:

***filter2 ve algoritmanın output imageları aynı pencerede subplot kullanarak gösteriliyor***
**** 3 X 3 bir filter kullanılıyor****
***filter size arttıkça bluring artar***
*** F input image: bir gray scale image***


% Main function
function image_filter(F)

%filter2
I = imread(F);
filt = ones(3 , 3) / 9;
res = filter2(filt, I, 'same');
J = uint8(res);

%our filtering algorithm

height = size(I, 1);
width = size(I, 2);

a = zeros(height + 2, width + 2, 'uint8');


for i = 2 : height + 1
for j = 2 : width + 1
a (i, j) = I(i - 1, j - 1);
end
end
b = zeros(height, width, 'uint8');

for i = 1 : height
for j=1 : width
avg = mean2(a(i : i + 2, j : j + 2));
b(i , j) = avg;
end
end

%display all

subplot(2,2,1);
imshow(I);
title('Input Image');
subplot(2,2,2);
imshow(J);
title('Output image of filter2 function');
subplot(2,2,3);
imshow(b);
title('Output image of our function');

return

Download Code

Hiç yorum yok:

Yorum Gönder