Ask Your Question
2

Creating custom kernels

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

kevgeo gravatar image

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

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 -0500 )edit

Sorry about that sturkmen, is the new edit better?

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

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

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

1 answer

Sort by » oldest newest most voted
4

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

berak gravatar image

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

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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 4,760 times

Last updated: Jun 11 '16