How to aplly a kernel to an ofImage?

Hi all.

How can i apply a kernel like this:

float kernel[3][3] = {{ -1, -1, -1},
{ -1, 9, -1},
{ -1, -1, -1}};

to an ofImage.

my Regards.

1 Like

Hi there!

Do you want to do it on the CPU or GPU?

You should check ofxCv for ofImage to cv::Mat conversion:

Using OpenCV, you can do something like

	ofFloatImage img;
	cv::Mat src = ofxCv::toCv(img);
	cv::Mat kernel = (cv::Mat1f(3,3)<<-1,-1,-1,-1,9,-1,-1,-1,-1);
	cv::Mat dst;
	cv::filter2D(src, dst, CV_32F, kernel);
	ofxCv::toOf(dst, img);