Determine thickness, head and tail of a snake in OpenCV C++

Viewed 470

I'm trying to analyze an image of a snake and determine the thickest point and which end is the head and which end is the tail. Here is the original image.

enter image description here

So far I have processed the image through grayscale, binary and processed the canny contours of the snake.

enter image description here

I also have the skeleton of the canny via thinning algorithm which is roughly the center line of the snake.

enter image description here

Now that I have the Canny contours and skeleton contours what techniques could be used to determine the pixel width of the fattest part of the snake body and also determine the head and tail?

c

I havent been able to find any techniques with OpenCV C++ that I can use to create these measurements or determine head from tail.

Any help and guidance would be greatly appreciated.

1 Answers

Here is my suggestion, assuming computational cost is not a problem:

  • Thickness: for each point of the skeleton, the local thickness can be approximated by computing the distance from the current point of the skeleton and each point of the contour and keeping the smallest distance. Then the thickest point is simply the one where the local thickness is maximal. thickness(x_skelet) = min([distance(x_skelet, x_contour) for x_contour in countour]) (yeah I know this is bad python style pseudo code, hope it make sense)
  • Hear/Tail differentiation: The main difference between head and tail is the average thickness. First off I would define which percentage of the body the tail and head are (at first glance I'd say 5%). Then, using the local thickness defined above I'd compute the average thickness over the 5% points of each side of the serpent. The head should be the side with the highest average thickness. And by definition the tail is the other.

From looking at your image, this should be robust enough to overlook the small artifacts in your image. Know that this implementation of local thickness is a little off close to the extremities but it should be good enough for what you described.

Hope this is useful to you.

Related