clc,clear,close all
%% 中轴线算法
a = imread('cl.jpg');
a = im2bw( a );
m = zeros( size(a) );
figure
imshow(a)
for i = 1:size(m,1)
for j = 1:size(m, 2)
if a(i,j)
sd = 0;
tmp = 1;
while all( tmp )
sd = sd + 1;
u = max(i - sd , 1);
d = min(i + sd , size(m,1));
l = max(j - sd , 1);
r = min(j + sd , size(m,2));
tmp = a( u:d, l:r );
m(i,j) = sum(tmp(:));
end
end
end
end
figure
imshow(m , [])
%%
t = false( size(a) );
for i = 2:size(m,1)-1
for j = 2:size(m, 2)-1
if m(i,j) >= 20
tmp = m(i-1:i+1,j-1:j+1);
tmp = tmp(:);
% tmp([1 3 7 9]) = [];
tmp = sort(tmp);
if m(i,j) >= tmp(end-1);
% && m(i,j)>=m(i-1,j-1) && m(i,j)>=m(i+1,j+1) && ...
% m(i,j)>=m(i+1,j-1) && m(i,j)>=m(i-1,j+1)
t(i,j) = true;
end
end
end
end
figure
imshow( t )
原图:
处理后的图片: