$ \def \J {\Delta} \def \half {\frac{1}{2}} \def \kwart {\frac{1}{4}} \def \hieruit {\quad \Longrightarrow \quad} \def \slechts {\quad \Longleftrightarrow \quad} \def \norm {\frac{1}{\sigma \sqrt{2\pi}} \; } \def \EN {\quad \mbox{and} \quad} \def \OF {\quad \mbox{or} \quad} \def \wit {\quad \mbox{;} \quad} \def \spekhaken {\iint} \newcommand{\dq}[2]{\displaystyle \frac{\partial #1}{\partial #2}} \newcommand{\oq}[2]{\partial #1 / \partial #2} \newcommand{\qq}[3]{\frac{\partial^2 #1}{{\partial #2}{\partial #3}}} \def \erf {\operatorname{Erf}} $

Sharpened Lines and Contours

It happens that the fuzzyfied equation of a straight line (segment) has to be integrated over all (black) pixels in its neighbourhood, resulting in a double integral, which is quite intensive to compute numerically: $$ \spekhaken \frac{1}{\sigma\sqrt{2\pi}} \; . \; e^{-\half \left[ cos(\phi) (x-p) + sin(\phi) (y-p) \right]^2/\sigma^2} \, dx \, dy $$ A well known trick is to convert such an area integral into a line integral, the objective being to save an order of magnitude in computing time. This can be accomplished once again with help of Green's Theorem: $$ \spekhaken \left( \dq{Q}{x} - \dq{P}{y} \right) \, dx \, dy = \oint \left( P\,dx + Q\,dy \right) $$ Where the line integral must be evaluated along the contour enclosing the area of interest. Converting a line integral into an area integral is easy. The reverse, converting an area integral into a line integral, requires some more luck and/or ingenuity. In our case, an educated guess is: $$ P(x,y) = - Er\!f\!\left[ \frac{cos(\phi) (x-p) + sin(\phi) (y-q)}{\sigma} \right] . \; sin(\phi) $$ $$ Q(x,y) = + Er\!f\!\left[ \frac{cos(\phi) (x-p) + sin(\phi) (y-q}{\sigma} \right] . \; cos(\phi) $$ Resulting indeed in the correct integrand for the area integral: $$ \dq{Q}{x} - \dq{P}{y} = \frac{1}{\sigma\sqrt{2\pi}} \; . \; e^{-\half \left[ cos(\phi) (x-p) + sin(\phi) (y-q) \right]^2/\sigma^2} \left[ cos^2(\phi) + sin^2(\phi) \right] $$ Because $cos^2(\phi) + sin^2(\phi) = 1$ . Hence it may be concluded that the equivalent line integral is given by: $$ \oint \left( P\,dx + Q\,dy \right) = $$ $$ \oint Er\!f\!\left[ \frac{cos(\phi) (x-p) + sin(\phi) (y-q)}{\sigma} \right] \left[- sin(\phi) \, dx + cos(\phi) \, dy \right] $$ Where $\left[ - sin(\phi) \, dx + cos(\phi) \, dy \right]$ denote increments along the contour, as they are (counter-clockwise) projected in the direction of the straight line. The last step is to take the limit of the above expression for $\sigma \rightarrow 0$ . This results in an integral over a Heaviside function which is discontinuous just where the straight line is / a Heaviside which is jumping over the straight line - so to speak: $$ \oint H\left[cos(\phi) (x-p) + sin(\phi) (y-q)\right] \left[- sin(\phi) \, dx + cos(\phi) \, dy \right] $$ The outcome of this integral will be the length of the straight line, insofar as it is (covered by the area of interest, which in turn is) enclosed by the contours of the boundary integral $\oint$. The rest of the story should be considered again as a technology, not a theory. But I want to spend a few words on this one as well. The Heaviside function in the abovementioned integral implies again a clipping problem. But we are not finished with just one of these. As any straight line will eventually be restricted to a line segment with finite length, this will give rise to three subsequent clipping problems: one for the line segment itself and two for the lines perpendicular to the segment at its end points.