Reputation: 25
I need to apply these two kernels on an image.
+1 0 0 0 0 0 0 0 -1
and 0 0 +1 0 0 0 -1 0 0
And then combine the two output images. But I have no idea how to write the loops/ apply filters to an image in general.
Upvotes: 1
Views: 2372
Reputation: 4448
You can use function called filter2d. It allows you to apply arbitrary kernel to image, so you don't need to perform any loops yourself. Just store the kernel you mentioned in Mat and provide it as input to filter2d together with your image.
Example of use:
float m[9] = {0,0,0,-1,0,1,0,0,0};
Mat kernel(Size(3,3), CV_32F, m);
filter2D(src, dst, -1, kernel);
Upvotes: 6