topic
the code
Initialization, B is a grayscale image (B=rgb2gary(img)). i means to generate a Laplacian of size i*i.
function init(B,i)
lap=genlaplacian(i);
img_lap=imfilter(B,lap,'replicate');
fr=fspecial('log',[i,i],0.5);
ruihua=enlarge(B,fr,i);
show(B,img_lap,ruihua)
end
Generate Laplacian
function sum=genlaplacian(n)
A=ones(n);
a=fix(n/2)+1;
b=fix(n/2)+1;
A(a,b)=1-n*n;
sum=A;
end
sharpening
function img_result = enlarge(img, w, i)
moban_size = i;
[M,N] = size(img);
img_lap = zeros(M, N);
expand_img = double(wextend('2D','zpd', img, floor(i/2)));
for i=1:M
for j=1:N
ave = sum( sum( expand_img(i:i+moban_size-1,j:j+moban_size-1) .* w));
img_lap(i,j) = ave;
end
end
img_lap = uint8(img_lap);
img_result = img - img_lap;
end
display image
function show(B,img_lap,ruihua)
subplot(1,3,1),imshow(B),title('B')
subplot(1,3,2),imshow(img_lap),title('拉普拉斯')
subplot(1,3,3),imshow(ruihua),title('锐化')
end
Example: use the 5x5 Laplacian operator to sharpen and filter the image, and complete the sharpening enhancement