Question

I have a skeleton image of wheels with 2,4, or 6 diameters drawn. I have also branched point coordinates.

I think about 2 ways for detecting the different wheels:

  1. Counting black areas inside the circle
  2. counting diameters drawn

In both cases i do not know how could i implement them.

wheel 1 wheel 2 wheel 3 wheel 4 wheel 5

As you can see, wheels are not perfect skeletonized, and so it is harder detecting differences.

This is the code i use for skeletonization:

first of all i binarize image, i dilate and then skeletonize.

from skimage import io
import scipy
from skimage import morphology
import cv2
from scipy import ndimage as nd
import mahotas as mah
import pymorph as pm
import pymorph

complete_path = "wheel1.jpg"
gray = cv2.imread(complete_path,0)
print(gray.shape)
cv2.imshow('graybin',gray)
cv2.waitKey()

ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) 
imgbnbin = thresh
print("shape imgbnbin")
print(imgbnbin.shape)
cv2.imshow('binaria',imgbnbin)
cv2.waitKey()

element = cv2.getStructuringElement(cv2.MORPH_CROSS,(6,6)) 
graydilate = cv2.dilate(imgbnbin, element) #imgbnbin
graydilate = cv2.dilate(graydilate, element)
#graydilate = cv2.erode(graydilate, element)

cv2.imshow('dilate',graydilate)
cv2.waitKey()   

#SKELETONIZE
out = morphology.skeletonize(graydilate>0)
skel = out.astype(float)
cv2.imshow('scikitimage',skel)
cv2.waitKey()
io.imsave('wheel.jpg', skel)    
sk = skel
print(sk.shape)

Original images:

wheel 1 wheel 2 wheel 3 wheel 4 wheel 5

Was it helpful?

Solution

You could also apply dilation to connect lines almost touching and use the flood fill algorithm to identify the compartments

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top