1 | initial version |
The magnitude formula is:
mag=sqrt(dX*dX+dY*dY)
It does the same thing than the cartToPolar function, without calculating the gradient angles. Technique1 and Technique2 don't calculate the magnitude accurately (however they can be used for a faster approximation).
Technique3 is unnecessary, as mag
is always positive.
Technique4 will produce a normalized result between 0-255, so it's the best for display from the methods above. However the intensity will change for each image, based on the strongest gradient.
To get the best representation, so the same intensity for every image, you have to divide everything by the highest theoretical value of the Sobel operator intensity (1024*sqrt(2)=1448):
# Technique 5
mag_disp = mag / 1448 # for double values to have a result between 0-1
mag_disp_byte = mag / 5.6 # for uchar values between 0-255