Ask Your Question
3

Creating custom kernels

asked 2016-06-11 07:55:44 -0600

kevgeo gravatar image

updated 2017-12-30 13:58:48 -0600

I want to create custom filters using filter2d function but most of the examples I see use custom methods like ones,zeros and eye but I want to create a 3x3 matrix which contains the values I want.

Like for e.g, [ 1 4 6 -1 3 5 -1 -2 2 ]

How do I make such a kernel using filter2d function?

edit retag flag offensive close merge delete

Comments

@kevgeo Could you be more attentive on tagging your questions.

sturkmen gravatar imagesturkmen ( 2016-06-11 08:54:54 -0600 )edit

Sorry about that sturkmen, is the new edit better?

kevgeo gravatar imagekevgeo ( 2016-06-11 13:17:14 -0600 )edit

@kevgeo thanks. by this way others can find informative content.

sturkmen gravatar imagesturkmen ( 2016-06-11 14:41:58 -0600 )edit

1 answer

Sort by » oldest newest most voted
4

answered 2016-06-11 08:21:16 -0600

berak gravatar image

updated 2016-06-11 08:32:30 -0600

a filter kernel is just another cv::Mat:

Mat_<float> kernel(3,3);
kernel << 1, 4, 6, -1, 3, 5, -1, -2, 2;

// or, if the Mat_<float> is too weird for you, like this:
float kdata[] = {1, 4, 6, -1, 3, 5, -1, -2, 2};
Mat kernel(3,3,CV_32F, kdata);

Mat image = ...
Mat res;
filter2D(image, res, CV_32F, kernel);
edit flag offensive delete link more

Comments

Thanks a lot once again berak :)

kevgeo gravatar imagekevgeo ( 2016-06-11 13:17:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-11 07:55:44 -0600

Seen: 14,347 times

Last updated: Jun 11 '16