%using second derivative for image sharpening - the laplacian
%page 161
%mask 4
clc;
clear all;
close all;
A=imread('8.jpg');
A=rgb2gray(A);
subplot(1,2,1);
imshow(A);
title('Original Image');
L=[-1 -1 -1; -1 8 -1; -1 -1 -1 ];
if(L(2,2)<0 br=""> C_into=-1;
else
C_into=1;
end
[r,c]=size(A);
B=zeros(r,c);
for i=2:(r-1)
for j=2:(c-1)
m=double(A(i,j));
a1=double(A(i-1,j-1));
a2=double(A(i-1,j));
a3=double(A(i-1,j+1));
a4=double(A(i,j-1));
a5=double(A(i,j+1));
a6=double(A(i+1,j-1));
a7=double(A(i+1,j));
a8=double(A(i+1,j+1));
sum=m*L(2,2)+L(1,1)*a1+L(1,2)*a2+L(1,3)*a3+L(2,1)*a4+L(2,3)*a5+L(3,1)*a6+L(3,2)*a7+L(3,3)*a8;
% sum1=L(1,1)*A(i-1,j-1)+L(1,2)*A(i-1,j)+L(1,3)*A(i-1,j+1);
% sum2=L(2,1)*A(i,j-1)+L(2,2)*A(i,j)+L(2,3)*A(i,j+1);
% sum3=L(3,1)*A(i+1,j-1)+L(3,2)*A(i+1,j)+L(3,3)*A(i+1,j+1);
% sum=double(sum1+sum2+sum3);
C(i,j)=A(i,j)+uint8(C_into*sum);
end
end
subplot(1,2,2);
imshow(C);
title('Sharp Image');0>