Friday, June 29, 2018

Konvolusi Tepi Citra Dengan Matlab

function konvolusicitra
%titik pusat di tengah
a=imread('cameraman.tif');
g=[0 -1 0;-1 4 -1;0 -1 0];
x=a;
a=double(a);
[baris kolom]=size(a);
for i=2:baris-1
    for j=2:kolom-1
        y(i,j)=(a(i-1,j-1)*g(1,1)+a(i-1,j)*g(1,2)+a(i-1,j+1)*g(1,3)+a(i,j-1)*g(2,1)+a(i,j)*g(2,2)+a(i,j+1)*g(2,3)+a(i+1,j-1)*g(3,1)+a(i+1,j)*g(3,2)+a(i+1,j+1)*g(3,3));
        if y(i,j)>255
            y(i,j)=255;
        else
           if y(i,j)<0
             y(i,j)=0;
         end
     end
 end
end
out=uint8(y);
subplot(2,2,1),imshow(x);
subplot(2,2,2),imhist(x);
subplot(2,2,3),imshow(out);
subplot(2,2,4),imhist(out);

No comments:

Post a Comment