The x-derivative Sobel looks that way:
-1 0 +1
-2 0 +2
-1 0 +1
Lets say there are two samples of my image which look like that (0=black, 1=white):
0 0 1 1 0 0
0 0 1 & 1 0 0
0 0 1 1 0 0
If I perform convolution I'll end up with 4 and -4 respectively.
So my natural response would be to normalize the result by 8 and translate it by 0.5 - is that correct? (I am wondering as can't find Wikipedia etc. mentioning any normalization)
EDIT: I use the Sobel Filter to create a 2D Structure Tensor (with the derivatives dX and dY):
A B
Structure Tensor = C D
with A = dx^2
B = dx*dy
C = dx*dy
D = dy^2
Ultimately I want to store the result in [0,1], but right now I'm just wondering if I have to normalize the Sobel result (by default, not just in order to store it) or not, i.e.:
A = dx*dx
//OR
A = (dx/8.0)*(dx/8.0)
//OR
A = (dx/8.0+0.5)*(dx/8.0+0.5)
The Sobel filter is the composition of a finite difference filter in one dimension:
[ 1 0 -1 ] / 2
and a smoothing filter in the other dimension:
[ 1 2 1 ] / 4
Therefore, the proper normalization to the kernel as typically defined is 1/8.
This normalization is required when a correct estimate of the derivative is needed. When computing the gradient magnitude for detecting edges, the scaling is irrelevant.
The 1/4 in the smoothing filter is to normalize it to 1. The 1/2 in the finite difference filter comes from the distance between the two pixels compared. The derivative is defined as the limit of h to zero of [f(x+h)-f(x)]/h. For the finite difference approximation, we can choose h=1, leading to a filter [1,-1]
, or h=2, leading to the filter above. The advantage with h=2 is that the filter is symmetric, with h=1 you end up computing the derivative in the middle between the two pixels, thus the result is shifted by half a pixel.