Implementing Skeletonisation Without Using bwmorph (or other in-built functions)
Show older comments
Hello,
I am currently trying to implement sketelonization in matlab without using any of the in-built functions. I think my code is close to being correct, albeit messy, but when I run it the image I get is the exact same as the original (i.e. the skeletonisation procedure doesn't seem to be changing the image). My Matlab skills are not great so any help in how to get my code sucessfully working would be much appreciated :)
im = im2double(imread('mapleleaf.tif'));
%figure(1);
%imshow(im);
[rows, cols] = size(im);
I = imbinarize(im); %gives binary of image
b = bwboundaries(I);
flag = 0;
T = 0;
for x = 2 : rows - 1
for y = 2 : cols - 1
p1 = I(x,y);
p2 = I(x-1,y);
p3 = I(x+1,y-1);
p4 = I(x,y+1);
p5 = I(x+1,y+1);
p6 = I(x,y+1);
p7 = I(x-1,y+1);
p8 = I(x,y-1);
p9 = I(x-1,y-1);
N = p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9;
if ((p2 == 0) && (p3 == 1))
T = T + 1;
end
if ((p3 == 0) && (p4 == 1))
T = T + 1;
end
if ((p4 == 0) && (p5 == 1))
T = T + 1;
end
if ((p5 == 0) && (p6 == 1))
T = T + 1;
end
if ((p6 == 0) && (p7 == 1))
T = T + 1;
end
if ((p7 == 0) && (p8 == 1))
T = T + 1;
end
if ((p8 == 0) && (p9 == 1))
T = T + 1;
end
if ((p9 == 0) && (p2 == 1))
T = T + 1;
end
if ((2 <= N) && (N <= 6) && (T == 1) && (p2*p4*p6 == 0) && (p4*p6*p8 == 0))
flag = p1;
I(x,y) = flag;
else
I(x,y) = p1;
end
if ((2 <= N) && (N <= 6) && (T == 1) && (p2*p4*p8 == 0) && (p2*p6*p8 == 0))
flag = p1;
I(x,y) = flag;
else
I(x,y) = p1;
end
T = 0;
flag = 0;
end
end
figure,
imshow(I);
Answers (0)
Categories
Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!