# Canny Edge Detection - Automatic/Adaptive Thresholding

18 visualizaciones (últimos 30 días)
Philip el 29 de Feb. de 2012
Respondida: Omer Moussaffi el 22 de Mayo de 2014
I have read in the docs for the 'edge' function that when a low and high threshold are not defined when calling the 'canny' edge operator, MATLAB automatically determines the best values for the given image. The threshold values can be obtained by specifying outputs to the argument. But can anyone explain (simply, if possible) how MATLAB calculates these threshold values, and whether the process can be slightly adjusted to bias toward only the stronger edges being identified?
I know the doc files hint at how this is done, but I don't quite understand it...
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (4)

Sean de Wolski el 29 de Feb. de 2012
You could place a break point in the subfunction parse_inputs() of edge().
edit edge
Scroll down and place breakpoint and follow the variable Thresh.
##### 1 comentarioMostrar NingunoOcultar Ninguno
Philip el 15 de Mzo. de 2012
Thanks, I have done this, and found this line of code that sets the high threshold value:
highThresh = find(cumsum(counts) > PercentOfPixelsNotEdges*m*n,1,'first') / 64;
where 'counts' is a histogram of the gradient magnitude of the image (64 bins), PercentOfPixelsNotEdges is a constant (0.7), and m and n are the image dimensions. The low threshold is simply calculated as a multiplication of this output with a ThresholdRatio constant (4).
Is anyone able to help me figure out exactly what 'PercentOfPixelsNotEdges' = 0.7 means. As mentioned, it is a constant, so this value stays the same no matter what image is used...

Iniciar sesión para comentar.

Aaditya Kalsi el 28 de Mzo. de 2012
It means that out of the detected edge values, 70% of the pixels will not be considered edges. Values higher than the 70th percentile among the values in the Edge image will be considered as edges.
That's what it seems like to me!
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

David Young el 28 de Mzo. de 2012
The documentation ought to be explicit about points like this! I think you could reasonably put in an enhancement request.
When I use Canny, I often call the function twice. The first time I capture the second result (and discard the edge image), and then I multiply the returned threshold by a constant to slightly increase or decrease it to get the threshold argument for the second call. Not very efficient, but it does allow reasonable control of edge density.
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

Omer Moussaffi el 22 de Mayo de 2014
Hitching on Phillip's question - can I use the automatic thresholding with the Matlab Coder?
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Object Analysis en Help Center y File Exchange.

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by