Ancient secrets of computer vision
It's nice, but missing the most valuable (and simplest) take from computer vision: the Hough transforms.<p>Let's take the circle Hough transform as it's one of the most enlightening ones!<p>Say you are looking for a circle of a given diameter. After a binarization to make the edge stand out, make all the potential points "vote" for a circle center.<p>The method is simple: using a matrix, you +1 all the points that are as far from this point as the radius of the circle will allow.<p>Do this for every point, and take the max: <a href="https://en.wikipedia.org/wiki/Circle_Hough_Transform" rel="nofollow">https://en.wikipedia.org/wiki/Circle_Hough_Transform</a><p>Simple, and works in guaranteed time.<p>Extension 1: if you don't know the radius, apply iteratively for a range of values, then again, take the max: if you imagine how it works (or code it as an example then animate the result), it's like doing a "mathematical" focus.<p>Extension 2: if it's too costly to do a dense exploration of the space of values for the radius, while you know there's only one circle, do a gradient descent on the increase.<p>Extension 3: If there are more that one circle, other techniques exist - the easiest to picture are based on the maximization of variance of the distribution of values in the matrix resulting from the binarization, but you can also use 2d lattices and other fun tricks.