Sobel Edge Thresholds

55 views (last 30 days)
Philip
Philip on 9 Dec 2011
I would like to test several sobel edge threshold values to identify which threshold is the best suited to a particular task... However, I do not know what range of threshold values to test.
My input images are all grayscale from the range 0-255. I read on a previous answer that if the max. value is 255 and the min. value is 0, the max. gradient becomes
(1 + 2 + 1)*255 - (1 + 2 + 1)*0 = 1020.
Which means the threshold can range from -1020:1020... However, when I use a threshold as small as 0.4, the threshold seems too high because no edges are found.
I would be grateful if anyone can help me to understand the most suitable threshold range to evaluate...
  2 Comments
David Young
David Young on 9 Dec 2011
I suggest you post your code and/or your image, as something must be wrong. You are correct to think that if the image values range up to 255, then 0.4 is a very low threshold.
Philip
Philip on 9 Dec 2011
Here is the image I am using: http://imageshack.us/photo/my-images/33/testimage.png/
I was using the following code to obtain the sobel edge image from the grayscale version of the image:
img_test = rgb2ycbcr(img_original);
img_test = img_test(:,:,1);
img_test_edges = edge(img_test, 'sobel');
However, I think the problem is that the image is of type 'uint8'. When I convert the image to 'double' before performing the edge detection, it can take much higher threshold values.
I now need to find a way of finding the best threshold value that yields the strongest edges only, for 10 different images. In other word, I need to find the most suitable threshold value that works for all the images. --If this is a problem, I could perhaps find a way of constructing an equation that gets the most suitable threshold for each image adaptively.

Sign in to comment.

Answers (3)

Sean de Wolski
Sean de Wolski on 9 Dec 2011
Have you looked at the output for
fspecial('sobel')
I would recommend using a for-loop to traverse a few values to hone in on what threshold you think is best.

David Young
David Young on 10 Dec 2011
I think there are two problems here.
The first is that it's not clear exactly what the Sobel option in edge() really does, as the threshold that it returns seems much lower that is reasonable. Some kind of normalisation seems to be going on, but it's not properly documented. The gv and gh results from edge('sobel', ...) are also smaller in amplitude that I'd expect, by more than the factor of 8 shown in the documentation.
I'd address this by using my own sobel masks (you can use fspecial as Sean suggests, or you can just write them down) and then convolving with conv2, and thresholding myself.
The second problem is that the Sobel operation on its own is too small-scale for most real images - you'll likely get fragmentary edges all over. For most cases a detector that incorporates some smoothing (e.g. Canny, also available using edge()), will give more useful results.
  1 Comment
Image Analyst
Image Analyst on 23 Jan 2013
I agree with your second problem. A difference of Gaussians filter is more flexible than a Sobel and finds lines in all directions (if you want). Actually, I've rarely ever found Sobel useful in practical situations. Kind of like histogram equalization - something everybody learns and wants to try but ends up being useless in practice.

Sign in to comment.


Guanfeng Wang
Guanfeng Wang on 22 Jan 2013
0.4 is not a very low threshold. Because in edge function, it first run a = im2single(a) to scale 0~255 values to 0~1 single precision.

Community Treasure Hunt

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

Start Hunting!