# Implementing a 2d butterworth filter for image processing?

I am at the moment trying to implement a bandpass butter worth filter which i then can use to apply on my original image. Problem is though My implementation of it using OpenCV doesn't seem to be correct.

I have written some code which is capable of displaying the DFT of an image, and based from that i able see what i want to filter out.

The freq spectrum of the image looks like this My idea was to implement a butterworth notch band reject filter, but something seems wrong my implementation, or I am just applying incorrectly.

cv::Mat bandpass(double d0, double n, int wy, int wx, int cx, int cy)
{
cv::Mat_<cv::Vec2f> pf(wy, wx);
for(int y = 0; y < wy; ++y) {
for(int x = 0; x < wx; ++x) {
// Real part
for(int i = 0; i < 3 ; i++)
{
const double d = std::sqrt( double((x-cx)*(x-cx)) + double((y-cy)*(y-cy)) );
const double d_k = std::sqrt(pow(x-cx-(cx+100),2.0) + pow(y-cy-(cy+100),2.0));
const double d_mk = std::sqrt(pow(x-cx+(cx+0),2.0) + pow(y-cy+(cy+0),2.0));
if(d==0) // Avoid division by zero
pf(y,x) = 0;
else
//  pf(y,x) = 1.0 / (1.0 + std::pow(d0/d, 2.0*n));
pf(y,x) *= (1.0/(1+pow((d0/d_k),2.0*n)))*(1.0/(1+pow((d0/d_mk),2.0*n)));
// Imaginary part
pf(y,x) = 0;
}
}
}
return pf;
}


and i use mulspectrum to apply it. But the output image from an inverse dft is a black image, which in some way tells me that is not the right filter type i am using..