shashashamti2008
shashashamti2008

Reputation: 2327

Taking a special image derivative using convolution

I have two images at different times. The first image is im1 at time t1 and the second image is im2 at time t2. I want to take the spatial derivative with respect to x. Could someone help me understand the following MATLAB code?

fx = conv2(im1, 0.25 * [-1 1; -1 1]) + conv2(im2,  0.25 *[-1 1; -1 1]);

I would be thankful to if someone can shed light on this kernel.

enter image description here

What type of image derivative the above mentioned code is? Is my understanding of what the kernel does correct, shown below?

enter image description here

where superscripts n and n+1 represent time t1 and t2, respectively. i loops through the rows (vertical) and j loops through the columns (horizontal) of the image function f, as shown in figure below.

enter image description here

Upvotes: 0

Views: 629

Answers (1)

Eugene Sh.
Eugene Sh.

Reputation: 18299

The convolution is done by multiplying a window of 2x2 pixels with the kernel and summing up the result. Since the first term in each row is -1 and the second is 1, the convolution result for each pixel will be the difference between two adjacent horizontal pixels, which is a (discrete) derivative in the horizontal direction.

Upvotes: 2

Related Questions