MATLAB: How does Matlab produce thin edges

digital image processingedgeImage Processing Toolboxsobel

Im using sobel edge detection.
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)
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')
Why is that its different? What is still lacking in my implementation to achieve Matlab's thin edges? Can anyone provide code to make it look/similar to Matlab native sobel edge detection?
Thanks

Best Answer

edge() takes a grayscale edge image like you'd get with imgradient(), and then thresholds it and skeletonizes the thresholded image, like you'd get with bwmorph(BW, 'Skel', inf).
Related Question