[Insight-users] canny filter thresholds

Luis Ibanez luis.ibanez at kitware.com
Sat Mar 21 12:18:37 EDT 2009

Hi Hu,

    You are not alone !

    Parameter setting is one of the most important aspects of the
    practice of image processing. It is unfortunately, rarely discussed
    in appropriate detail in technical publications. this is simply
    and evidence of the uselessness of current Journals, and how they
    despise the practice of real image processing, while getting obsessed
    with the vanity of letting authors pretend to be the first ones to
    invent something, or to be the ones who provide a method that is
    better than anything else.


    The selection of parameter values for this filter (as for many other
    filters) is something that in practice is done by trial an error.

    Half of the reason is the one that you pointed out: without seeing
    the gradient magnitude image, is very hard to select the threshold.

    The other half of the reason is that "There is no such thing as
    the *RIGHT* output of the CannyFilter."

    That is, the CannyFilter (just as most image processing filters) is
    a tool that will help you extract information, but it is by no means,
    self regulated.

    Only *you* or *your customers* know what edges from your image are
    significant to you. Therefore, only you (or your customers) can
    define the level of those thresholds. What you want to do is to
    setup an easy-to-use program in which your (or your customers) can
    play with the parameters until they find a satisfactory range.

    You want to do this with a series of images (not just a couple),
    and from that series of experiments select the values of these two

    My practical suggestion would be:

    Start playing with the ITK example:


    and use as input the image:


    Note that you need to fit three parameters, (not just two).
    They are:

      * variance
      * upperThreshold
      * lowareThreshold

    You want to start by selecting a large variance (sigma^2).
    That in this case, is measured in Pixels, not in mm.

    Start with 2.0 for example.

    Then you select a large upperThreshold and a lowerThreshold
    very close to the upperThreshold.

    For example:  upperThreshold = 10.0
                  lowerThreshold =  9.0

    run the  filter, look at the image.

    If you see any contours that you wont want to extract,
    then raise the upperThreshold, and repeat the process.

    If you see only pieces of the contours that you want to extract,
    then you can keep that upperThreshold value, and start lowering
    the value of the lowerThreshold. At each lower value the contours
    will be longer and more complete (but always attached to the ones
    that you found when lowerThreshold was close to upperThreshold.)

    Keep lowering the lowerThreshold until you start getting too many
    small contours.

    If you get to very low values of the lowerThreshold and you
    still miss some of the contours that you wanted to extract,
    then reduce the value of Variance, and repeat the process of
    fine tunning the values of the two thresholds.

    This exercise will give you a sense of how to set the parameters
    for a known image.

    Once you are familiar with the effect of changing each one of
    the parameters, then you are ready to apply the same process
    to your own image.

    For this particular image, good paramers for seeing the ventricles,
    gray/white matter interface and the skull, are:

         Variance       =  1.5
         UpperThreshold = 10.0
         LowerThreshold =  3.0

     If you only want to see the skull, then you could use

         Variance       =  1.5
         UpperThreshold = 20.0
         LowerThreshold =  3.0



Zhiqiang Hu wrote:
> Hi All,
> I would appreciate very much your help regarding the usuage of itk 
> implementation of the canny edge filter. As you all know, there are 2 
> thresholds for it. My question is how should I set them without knowing 
> the magnitude of the gradient images that I am going to apply the 
> thresholds on. I feel blind when I tune those parameters. 
> I checked both matlab and idl implementations of this filter; in both 
> cases the two thresholds are normalized to be choices between 0 and 1.
> Thank you very much in advance for the help!
> Hu
> ------------------------------------------------------------------------
> _____________________________________
> Powered by www.kitware.com
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

More information about the Insight-users mailing list