0

Im using sobel edge detection.

Here is the sample image file if you have Matlab enter image description here

How does Matlab, by itself manage to achieve very thin edges like this one (using just the Matlab's edge function with 'sobel' as parameter)

matlabsobel = edge(originalImage,'sobel')
imshow(matlabsobel)

enter image description here

but when I try to do sobel algorithm my own way, assuming the process is just the same..

originalImage = gaussianizedimage;
threshold = 60.5;
k = [1 2 1; 0 0 0; -1 -2 -1];
H = conv2(double(originalImage),k, 'same');
V = conv2(double(originalImage),k','same');
E = sqrt(H.*H + V.*V);
edgeImage = uint8((E > threshold) * 255);
imshow(edgeImage);
title('sobel algorithm')

enter image description here

Why is that its different? What is still lacking in my implementation to achieve Matlab's thin edges?

Thanks

Unapiedra
  • 15,037
  • 12
  • 64
  • 93
vvavepacket
  • 1,882
  • 4
  • 25
  • 38
  • 1
    Out of curiosity, what do you get with Matlab's algorithm when you use the "nothinning" option? – Benoit_11 Aug 21 '14 at 01:19
  • @Benoit_11 by default, if we execute matlabsobel = edge(originalImage,'sobel'),, it always show thin edges... There is nothinning option with the edge function – vvavepacket Aug 21 '14 at 01:22
  • 2
    They probably use non-maximum suppression as well as a variety of other things. `sobel` is probably the first step in estimating the local gradient. If you actually do `edit edge` in the command prompt, you may be able to see what they're doing under the hood. I don't have MATLAB here, so I can't verify that for you. – rayryeng Aug 21 '14 at 01:26
  • 1
    yes that was my point; if you tell Matlab not to thin edges I was wondering if the image would look like yours – Benoit_11 Aug 21 '14 at 01:26

1 Answers1

1

Thanks to rayryeng

Sobel is the first step, and in order to get thin edges, you need to perform skelotinization

>> BW3 = bwmorph(bww,'skel',Inf);
>> figure()
>> imshow(BW3)

The resulting image is the following

enter image description here

vvavepacket
  • 1,882
  • 4
  • 25
  • 38