Seite 1 von 1

Compute Derivatives by central differences

Verfasst: 6. Mai 2012 14:30
von Tigger
I have a little trouble to understand the derivative computation by by central differences as explained it on p46 in the slides.

To compute the derive we shall use: 0.5 * [1 0 -1]

The central difference is defined by:
\(\frac{f(x+h,y)-f(x-h,y)}{2h}\)

in our case h=1 so:
\(\frac{f(x+1,y)-f(x-1,y)}{2}\)
but this would lead to a computation vector of:
0.5 * [-1 0 1]

For example: A vector [1 2 3]. The derive is obviously 1.
To check:
\(\frac{f(3,1)-f(1,1)}{2} = \frac{3-1}{2} = 1\)

With my vector = [1 2 3] * 0.5*[-1 0 1] = 1
With vector from slides = [1 2 3] * 0.5*[1 0 -1] = -1

Is the computation vector in the slides wrong or do I misunderstand something?

Re: Compute Derivatives by central differences

Verfasst: 6. Mai 2012 15:47
von Toobee
Hi,

>but this would lead to a computation vector of: 0.5 * [-1 0 1]

I am not sure what you problem is, but it might be related to filter application by correlation vs. convolution

If you would apply the filter by correlation your proposed filter would be needed, with convolution the one from the slides is the right one, but I am not sure whether that is correct...just an idea.

Re: Compute Derivatives by central differences

Verfasst: 7. Mai 2012 08:45
von Tigger
Toobee hat geschrieben: it might be related to filter application by correlation vs. convolution
It seems you are right, [-1 0 1] is the correlation filter, whereas [1 0 -1] is the corresponding convolution filter. It makes sense to use the convolution filter here, since just convolution is associative and allows precomputing of filter combinations before applying them to an image.

But am i correct, that the correlation filter does not compute the derive, but the negative derive of an image vector? Is it that, why we have two filter functions (corr and conv) in mathlab, so does conv just operate on the negative derive and corr on the positive?

Re: Compute Derivatives by central differences

Verfasst: 7. Mai 2012 09:12
von Toobee
Hi,

from an image processing view point correlation and convolution is basically the same (that changes when working from a signal processing point of view).

>correlation filter does not compute the derive, but the negative derive of an image vector?
"[Convolution is the]Same as correlation except that the mask is flipped both horizontally and vertically"

Because of the flipping of the convolution operation it should hold:
(correlation [-1 0 1]) == (convolution [1 0 -1])

Code: Alles auswählen

image = [3 3 3; 6 6 6; 9 9 9];
filterConv = [1 0 -1]*0.5
filterCor = [-1 0 1] * 0.5;
imfilter(image, filterCor, 'corr', 'same')
imfilter(image, filterConv, 'conv', 'same')
% same filter result ---> it is the same

Re: Compute Derivatives by central differences

Verfasst: 7. Mai 2012 12:45
von qgao
In practice, the sign of derivatives is usually not that important.

But in the exercise problem, we should compute the filters and the derivatives based on the given definition from the problem description.