Why does the 'skel' function leave gaps in the skeletons produced?

1 view (last 30 days)
Hi there,
I've been trying to create skeleton images, but I am finding that it doesn't work effectively for shapes that aren't thin (for example, I can get insects to work, but I can't with filled shapes.) My other issue is that there are always gaps in the skeleton, but my understanding of skeletons is that the skeleton of a single object should all be joined up.
Below is my code, which is a 3x3 subplot of 3 images, the images in binary and their corresponding skeletons. The jpg files can be replaced with other images, though the threshold may need to change. I've generally used images against white backgrounds.
clear all
close all
clc
s = imread('stickin.jpg');
a = 1;
p = rgb2gray(s);
p = (p<=220) ;
figure(1)
subplot(3,3,1)
colormap(gray)
imagesc(p)
subplot(3,3,4)
bw = bwmorph(p, 'skel', Inf);
colormap(gray)
imagesc(bw)
% Image 2
b = imread('daddy.jpg');
a = 1;
d = rgb2gray(b);
c = (d<=248) ;
subplot(3,3,2)
colormap(gray)
imagesc(c)
subplot(3,3,5)
bw1 = bwmorph(c, 'skel', Inf);
colormap(gray)
imagesc(bw1)
% Image 3
s1 = imread('widow.jpg');
a = 1;
p1 = rgb2gray(s1);
p1 = (p1<=200) ;
subplot(3,3,3)
colormap(gray)
imagesc(p1)
subplot(3,3,6)
bw1 = bwmorph(p1, 'skel', Inf);
colormap(gray)
imagesc(bw1)
% Plot real images
subplot(3,3,7)
imagesc(s)
subplot(3,3,8)
imagesc(b)
subplot(3,3,9)
imagesc(s1)
Any help would be greatly appreciated.
Thanks,
Annie
  2 Comments
Nicola Ferrier
Nicola Ferrier on 6 Jan 2016
I thought I had this same problem - it appears to be a function of the DISPLAY (different on Windows vs Linux for me). Save the skeleton, use a different image viewer - perhaps the skeleton is fine (as in my case) but the display was the problem. Check on graphics (try using 'opengl hardwarebasic').
Image Analyst
Image Analyst on 6 Jan 2016
You mean that even when you zoomed way in, like I suggested in my answer, so that the pixels were hugely magnified, there were gaps that were not gaps when you looked in the variable editor?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Oct 2014
The skeleton doesn't leave gaps but may appear to if it shrunk down your image (subsampled) for display. Examine the image in the variable editor and see if the gaps are really there.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!