Thursday, 21 April 2011

Adaptive Threshold Edge Detection in GIMP

We have a particular edge detection algorithm that was developed for the OpenIllusionist project specifically to help with detecting fiducials in live video since it was faster and better suited to the task than algorithms such as the canny edge detector.

The original algorithm was designed by Prof. John Robinson at the University of York and then modified and optimised by myself. The following diagram, taken from my thesis, provides an overview of how the algorithm works:


The GIMP is an extremely useful tool, not only for manipulating your photos but also for prototyping machine vision algorithms. Since the edge detection is part of our standard toolkit it would make sense to be able to test it out on images alongside all of the usual filters found in the GIMP.

The porting of this algorithm to a GIMP plugin was not simple, since GIMP plugins usually make use of tile-based processing thereby reducing the overall memory required to handle very large images. However, as can be seen in the above diagram, the adaptive threshold edge detector uses many full and scaled down buffers to produce the final result and as such cannot easily be modified to work with tiles. The current implementation of my plugin simply uses full image regions and therefore the user must be aware that it may have issues if applied to very large images.

One problem that this particular algorithm attempts to address is that of edge ringing in images, especially those captured from low-quality cameras or affected by compression artefacts. The following image is based on an example from wikipedia but also includes the results from our edge detector which clearly shows that it is unaffected by the jpeg compression artefacts present in the lossy image:


The code for the plugin along with a binary for Linux x64 can be found in my github plugins repository and further examples of the algorithm in action are shown below.

Source image copyright Dan Parnham

Source image copyright Benh Lieu Song

4 comments:

  1. very interesting!
    even if maybe was not intended for that i found it useful to create lineart from photos, and if combined with other filters, nice artistic effect

    But for lineart if from one hand the result are much cleaner then from other edge detection filter, from the other hand the lines are sort of oversharp and jagged

    and where in the original image were dots, the outline of the dots is squared.

    let say that outline of very little dots tend to be a tiny squares with sharp corners , instead then a little circles ( even squares but with rounded corners will be better)

    I tried to add a bit of of gaussian blur, but that don't solve too much, the corners in the jagged lines and in the little squares are so sharp that would be need too much blur to smooth them

    I was wondering if you have some other idea to smooth a bit the lines and roundify a bit the corners without use gaussian blur

    if you want i may post the link to some visual example of what i intend for "little squares and jagged lines.

    best regard

    ReplyDelete
  2. PS
    the link for your thesis

    (http://vision.cs.man.ac.uk/theses/thesis.php?parnham2007a )

    seems dead or incorrect

    ReplyDelete
  3. @PhotoComix,

    I'm glad that you are finding uses for the plugin.

    With regards to the lack of anti-aliasing, this is due to the fact that the algorithm was designed for real-time machine vision and is therefore intended to be used in conjunction with other forms of analysis. For example, the fiducial detector in the OpenIllusionist project performs grouping and then ellipse fitting on the detected line segments.

    Since the implementation of the edge detection as a GIMP plugin was intended to aid us in the prototyping of machine vision algorithms it does not make sense to modify it to produce more aesthetically pleasing results. However, I understand the desire for anti-aliasing when using the plugin for more artistic purposes.

    It would require a significant reworking of the algorithm to correctly perform the sub-pixel analysis necessary to produce anti-aliased results, however I may consider looking at this as an optional feature in the future (if time permits).

    In the mean time the only way to achieve the results you desire are to work with images at a much higher resolution and then scale down the end result.

    The link to my thesis was correct the other day, but it looks as though the entire website for the thesis archive is down at the moment! If you check back after the bank holiday I'm sure they will have it running again.

    Regards,
    Dan

    ReplyDelete
  4. Thank for the prompt reply
    Actually i am very interested to port the algorithm as a filter for Gmic.
    (for both the command line and the gimp plugin)

    Not sure if i will able to do without help as you may guess from http://www.flickr.com/groups/gmic/discuss/72157626432203553/ but maybe i will or other will took the challenge

    In case i may well add as first step a option for 2x upscale,(a option because will made the filter even more intensive )
    ...th but are you sure that will help to limit the tendency to "squarify" the dots ?

    ReplyDelete