Write a MATLAB code to implement the smoothing and edge detection (sobel, laplacian) spatial filter on the image.



CODE:
clear all;
close all;
clc;
a=imread('cameraman.tif');
a=double(a);
so=[-1,-2,-1;0,0,0;1,2,1];
lo=[1,1,1;1,-8,1;1,1,1];
l=[];
s=[];


for m=2:255
    for n=2:255
       s(m,n)=a(m+1,n+1)*so(1,1) + a(m+1,n)*so(1,2) + a(m+1,n-1)*so(1,3) + a(m,n+1)*so(2,1) + a(m,n)*so(2,2) + a(m,n-1)*so(2,3) + a(m-1,n+1)*so(3,1) + a(m-1,n)*so(3,2) + a(m-1,n-1)*so(3,3);
    end
       
end

for m=2:255
    for n=2:255
       l(m,n)=a(m+1,n+1)*lo(1,1) + a(m+1,n)*lo(1,2) + a(m+1,n-1)*lo(1,3) + a(m,n+1)*lo(2,1) + a(m,n)*lo(2,2) + a(m,n-1)*lo(2,3) + a(m-1,n+1)*lo(3,1) + a(m-1,n)*lo(3,2) + a(m-1,n-1)*lo(3,3);
    end
       
    end

  
subplot(1,3,1);
imshow(uint8(a));
title('image of cameramen','color','r'); 

subplot(1,3,2);
imshow(uint8(s));
title('image-SOBEL ','color','r'); 
subplot(1,3,3);
imshow(uint8(l));
title('image-LAPLACIAN','color','r'); 




OUTPUT: