Reputation: 71
Is it possibile deleting small branches during skeleton procedure?
As in this picture: http://felix.abecassis.me/wp-content/uploads/2011/09/skel_opencv.png
Only O letter is perfect but not all the others letters.
THere is a way during the procedure or after to deleting this little branches? I use python opencv, but a solution also with pymorph or scikit-image is good. Here there is the code i used for skeletonization: Code
Original image: http://felix.abecassis.me/wp-content/uploads/2011/09/opencv.png
Upvotes: 6
Views: 5951
Reputation: 5117
Scikit image has skeletonize and thin that may help accomplish what you want.
The lee version of skeletonize effectively does more thinning of fringe skeleton features than skeleton alone.
Thin gives you the ability to partially skeletonize the image. You can do a partial thin followed by a dilate or open operation to get something close to a morphological prune (https://en.wikipedia.org/wiki/Pruning_(morphology)).
There are examples of the scikit skeleton tools here: https://scikit-image.org/docs/dev/auto_examples/edges/plot_skeleton.html
from skimage.morphology import skeletonize
from skimage import data
import matplotlib.pyplot as plt
from skimage.util import invert
# Invert the horse image
image = invert(data.horse())
# perform skeletonization
skeleton = skeletonize(image)
skeleton_lee = skeletonize(image, method='lee')
# display results
fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(8, 4),
sharex=True, sharey=True)
ax = axes.ravel()
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].axis('off')
ax[0].set_title('original', fontsize=20)
ax[1].imshow(skeleton, cmap=plt.cm.gray)
ax[1].axis('off')
ax[1].set_title('skeleton', fontsize=20)
ax[2].imshow(skeleton_lee, cmap=plt.cm.gray)
ax[2].axis('off')
ax[2].set_title('skeleton lee', fontsize=20)
fig.tight_layout()
plt.show()
Upvotes: 0
Reputation: 7263
Here is the result from scikit-image:
from skimage import io
from skimage import morphology
image = io.imread('opencv.png')
out = morphology.skeletonize(image > 0)
Upvotes: 3