Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mean of the distance transform

I need to use openCV python to find the average width of the curve as attached in the image.

image description

I used distance transform to find the maximum width :

dist = cv2.distanceTransform(img, cv2.DIST_L2, 3)
mnv, mv, _, mp = cv2.minMaxLoc(dist)
print(mv * 2, mp)  # (half)width*2, pos

For the average width, i tried:

avgwid=2*np.mean(dist)

as well as:

avgwid= 0.5*(mnv+mv)

However, both options are giving me the incorrect results. What is the correct way to find average width of the curve ? A solution in python would be highly appreciated. Thanks.