2
$\begingroup$

How to compute Image gradients?

In X Direction - Kernel : -1 0 1

In Y Direction - Kernel : -1 0 1

Let's assume my input image is: unsigned char* imgImage;

Could any one please share code. I am newbie to image processing. Is it possible to do in OpenCV with this same kernel?

Thanks a lot in advance!

$\endgroup$
1
  • $\begingroup$ The simplest way is to make FFT of your kernel, by-pixel multiply it on image's FFT and make IFFT. But in your case, when kernel is so small, it would be better to make direct convolution. $\endgroup$
    – Eddy_Em
    Commented Jul 4, 2013 at 7:19

2 Answers 2

2
$\begingroup$

You can create your own custom kernel filter using something similar to this example.

if you just want to find image gradients there are other options such as sobel and laplace

If your aim is edge detection, I find canny is best for this in most cases.

$\endgroup$
1
$\begingroup$

In Matlab, there is a simple function called imfilter that does this job. I am sure there is a similar function, probably with a similar name in OpenCV.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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