Contour fitting around bright objects

Viewed 121

I have an image with white arrows and a contour of 1 such an arrow. See here: enter image description here

Now I want to rotate and translate this contour such that it fits as well as possible. In this specific case the goals is thus to fit the blue contour around the bottom arrow.

My current approach is to select a raster of (x, y) coordinates. On each of these coordinates I rotate the contour in 360 directions, each time measuring the summed pixel values contained within this contour. The position & angle with the highest value is then chosen as the most likely position & angle for this contour to be correctly fitted.

However, this is a pretty slow procedure and the quality strongly depends on the raster density. Is there a better way to do this?

General advice would be welcome as would any packages/code in python providing examples of how to do this.

1 Answers

You can use template matching concepts like Normalized Cross-Correlation instead of measuring the summed pixel values. It's invariant to local average intensity and contrast but still slow.

Another approach would be feature extraction methods like SURF, SIFT, etc. Create a binary image from the contour. SIFT will find the exact position with the right angle and even scale for you. You can find these algorithms in opencv-python. For example this link.

Related