5
$\begingroup$

Prewitt operator is a common operator to compute image gradient in edge detection, and I knew that to apply this Prewitt operator to an image is just to convolve them together, say, the image is represent as $A$, and as the wikipedia page lays out, the Prewitt operator for *x-gradient is $$G_x=\pmatrix{ -1 & 0 & 1\\\ -1 & 0 & 1\\\ -1 & 0 & 1}$$, for y-gradient is $$G_y=\pmatrix{1 & 1 & 1\\\ 0 & 0 & 0\\\ -1 & -1 & -1}$$

So if I want to compute the x-gradient of image $A$, convolve them like this,$$A_x=A*G_x$$, but here comes my problem. $G_x$ is the kernel, when convolve it with $A$, $G_x$ should be flipped which turn it into this, $$G_x=\pmatrix{1 &0 &-1\\\ 1 &0 &-1\\\ 1 &0 &-1}$$ right? If so, the x-gradient will be something like this, $$\nabla A_x=A(x-1,y)-A(x+1,y)$$ , BUT I think it should be $$\nabla A_x=A(x+1,y) - A(x-1,y)$$.

So I presume that either $G_x$ and $G_y$ should not be flipped when convolve them with $A$, or $G_x$ doesn't look like the above, and it should be this,$$G_x=\pmatrix{1& 0& -1\\\ 1& 0& -1\\\ 1& 0& -1}$$

Anyone can help me with this?

$\endgroup$
5
$\begingroup$

This is a common question and there are a few other answers on this site which may be helpful. What you have noticed is correct. To be clear, convolution is defined by this flipping, it gives the convolution operation some nice maths properties. Non-flipping convolution is called cross-correlation.

For these kernels, the only thing flipping changes is the sign of the result. You can safely use the inverse (flip) of the kernels to get the form you desire.

$\endgroup$
  • $\begingroup$ But for my case, if I don't flip the matrix, then I'll get the right image-gradient, but if I do flip, the image-gradient will be the inverse, right? Is that ok? $\endgroup$ – avocado Jun 14 '13 at 8:31
  • $\begingroup$ Yea, I think both should be inverted. Maybe the wikipedia page needs changing. $\endgroup$ – geometrikal Jun 14 '13 at 11:12
  • $\begingroup$ This is the reason I always prefer using Central Differences to approximate the gradient. $\endgroup$ – David Jun 25 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.