richard
richard

Reputation: 762

How to apply multiple filters on one image in opencv?

I'm trying to use opencv to do gabor filter on my image, and I know I should use multiple params and apply several filters, but I have no idea how to apply all these things in one image, can I just use the opencv methd cvAddWeighted? or there is some other way? thanks in advance!

Upvotes: 1

Views: 2708

Answers (2)

berak
berak

Reputation: 39806

to apply several filters, you can just 'chain' them (apply one after the other):

Mat img;
Mat kernel1 = getGaborKernel(...);
Mat kernel2 = getGaborKernel(...);
Mat kernel3 = getGaborKernel(...);
Mat kernel4 = getGaborKernel(...);


cv::filter2D(img, img, CV_32F, kernel1);
cv::filter2D(img, img, CV_32F, kernel2);
cv::filter2D(img, img, CV_32F, kernel3);
cv::filter2D(img, img, CV_32F, kernel4);

Upvotes: 1

Froyo
Froyo

Reputation: 18487

OpenCV has gabor filter in its Image Processing module. As shown here, you can simply get the gabor kernel and apply it on the image. The code from the link

#include "opencv2/imgproc/imgproc.hpp"

cv::Mat kernel = cv::getGaborKernel(cv::Size(kernel_size,kernel_size), sig, th, lm, gm, ps);
Mat src_f; // img converted to float 
Mat dest;
cv::filter2D(src_f, dest, CV_32F, kernel);

You can implement your own Gabor filter. It creates one filter and applies it on the image. Github Repo Link

Upvotes: 2

Related Questions