I am implementing a Canny Edge detector for a class which I have based off the code found here. For the first derivative mask that I will convolve with the image, I am using the Sobel mask, although the website uses the Prewitt. As you can see in the samples on the website, the code is perfectly functional. However, I noticed different results when I changed the orientation of the Sobel gradient mask as I explain below.The typical mask for taking the derivative in the x direction in my class notes is shown to be:[-1 0 1][-2 0 2][-1 0 1]For the y direction it is:[-1 -2 -1][0 0 0][1 2 1]For an experiment, I changed the orientation for the x direction to:[1 0 -1][2 0 -2][1 0 -1]And for the y direction:[1 2 1][0 0 0][-1 -2 -1]Oddly enough, this gives me two different results, which I did not expect, since I don't think the direction that I am using for taking the gradient should give me a different result.First result:Second result:Why am I getting this different result? Where should I investigate next?
Difference in orientation of Sobel mask gives different edge detector result
algorithms;image processing
Some questions, then a suggestion.Have you tried your code with the same images and masks as the article. Do you get the same results?Did you try switching masks in the original?A quick scan of the source code tells me that this code is not easy to verify. It's not written in a way to ensure correctness, and it's not testable. I thought I found a problem in the iteration over Filter in Differentiate but on second thoughts it's probably OK.What I did find is this in DetectCannyEdges:if (((-157.5 < Tangent) && (Tangent <= -112.5)) || ((67.5 < Tangent) && (Tangent <= 22.5)))The second part of that looks wrong. It should be:if (((-157.5 < Tangent) && (Tangent <= -112.5)) || ((22.5 < Tangent) && (Tangent <= 67.5)))Or I could be completely wrong.