I have a task to implement a 3×3 x-derivative image filter that makes use of central difference and performs at the same time a Gaussian smoothing in the y direction.
I have a formula for that task in the x-direction (h=1), and I am not sure whether I understand it correctly:
(f(x+h;y)-f(x-h;y)) / 2*h
Relative from my current pixel (x), I take the pixel value +1 ahead of my current pixel and subtract the value from the pixel on the position -1 behind my current pixel. Is this value divided by 2 then more or less my first order derivation in the x direction? Isn’t my actual current pixel value used at all?
Traditionally for images, the center isn’t used for a derivative filter. The reasoning can be found as follows.
Given these two points, and especially the first one, it is evident that the kernel should have an odd number of elements, and the center should be 0. Essentially, if the kernel is odd, then it will tend to preserve the original edge.
Taking a 1 dimensional example, and apply the formula you provided, trimming the edges (Forcing them to 0), will result as follows:
Note that the two highest magnitude values are right at the peak. Try playing with other kernels, including some that don’t have the center value be 0, and see what results.
(*) Kernel represents the function you are performing. In the case you have provided, the kernel is [1 0 -1]