Abstract:
In 2007 Alexander Overwijk went viral with his 'Perfect Circle' video. The same year a World Freehand Circle Drawing Championship was organized, which he won. In this post we show how a mobile camera, R and the imager package can be used to develop an image analysis based method to judge future instances of the championship.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. The markdown+Rknitr source code of this blog is available under a GNU General Public License (GPL v3) license from github.
Introduction
A few years back I watched with awe the 2007 video of Alexander Overwijk's freehand drawing a 1m diameter circle:
Note: Depending on your browser you might need to click &quot;Watch on Youtube&quot; to see the video.
Ever since watching that video I have wondered how one would go about to judge the winner of such an alleged World Freehand Circle Drawing Championship (WFHCDC). While researching for this post I finally figured it out. On his web page Alexander in the story behind the video &quot;reveals&quot;:
They have a laser machine called the circleometer that creates the perfect circle closest to the one you drew. The circleometer then calculates the difference in area between the laser circle and the circle that you drew. The machine then calibrates the area difference as if you had drawn a circle with radius one meter. The person with the smallest area difference is declared the world freehand circle drawing champion.
Aha! Imaginary circleometers are expensive and my dean of study most likely isn't open for investing in perfect circle measurement equipment... So here is a cheaper solution involving a mobile device camera, R and the imager package by Simon Barthelmé et al. Altogether a combination of modern data science tools, which my dean of study is most likely to approve! We'll use a screenshot from the perfect circle video as motivating example to guide through the 3 phases of the method:
Image Rectification
Freehand circle identification and perfect circle estimation
Quantifying deviation from the perfect circle
We start by loading the screenshot into R using imager:
library(&quot;imager&quot;)
file % grayscale
##Total area covered by the circle
freehandDisc 0
dilatedDisc % dilate_rect(sx=3,sy=3)
freehandCircleThinBorder 0\) the radius we want to find the solution of
\[
\min_{c\in \mathbb{R^2}, r__0} \sum_{j=1}^m F_j(c,r)^2, \quad\text{where}\quad F_j(c,r) = \left|r - ||c-a_j||_2\right|,
\]
and \(||x||_2\) denotes Euclidean distance. Because the curve fitting minimizes the distance between an observed point \(a_j\) and its closest point on the circle and thus involves both the \(x\) and the \(y\) direction , this is a so called total least squares problem. The problem is non-linear and can only be solved by iterative numerical methods. However, the dimension of the parameter space can be reduced by one, because given the center \(c\) we can determine that \(r(c)=\frac{1}{m} \sum_{j=1}^m ||c-a_j||_2\).
##Compute radius given center
radius_given_center