How does Matlab produce thin edges?

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

 採用された回答

Image Analyst
Image Analyst 2014 年 8 月 21 日

1 投票

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).

4 件のコメント

Ivan Matala
Ivan Matala 2014 年 8 月 21 日
@Image Analyst
thanks for you answer,,, Ive searched bwmorph and if by chance,, do you what is the best suited morphological operation to make it look like the 1st image above?
Thanks
Image Analyst
Image Analyst 2014 年 8 月 21 日
I told you that already. Here is is again, formatted as code this time:
thinEdgeImage = bwmorph(thresholdedImage, 'Skel', inf);
Miroslav Hagara
Miroslav Hagara 2018 年 9 月 19 日
編集済み: Miroslav Hagara 2018 年 9 月 19 日
according this, if I use this code:
BW1 = edge(I,'Prewitt');
BW2NT = edge(I,'Prewitt','nothinning');
BW2 = bwmorph(BW2NT, 'Skel',Inf);
I should get the same pictures. But this is not true.
I have get better result with
BW2 = bwmorph(BW2NT, 'thin', Inf)
but still without same pictures.
Royi Avital
Royi Avital 2019 年 9 月 3 日
If you look inside edge() you will see:
if thinning
e = computeedge(b,bx,by,kx,ky,int8(offset),100*eps,cutoff);
else
Which does the magic.
MathWorks doesn't specify what's done there.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by