Butterworth filter

Butterworth filter

// Butterworth filter
//fc = cut frequency
//n filter order
//type: if tipo <0, low pass, if >=0 high pass
//the image shoul be square


IplImage *cinza = cvCreateImage(cvSize(img->width,img->height),
IPL_DEPTH_8U, 1);
IplImage *re64 = cvCreateImage(cvSize(img->width,img->height),
IPL_DEPTH_64F, 1);
IplImage *im64 = cvCreateImage(cvSize(img->width,img->height),
IPL_DEPTH_64F, 1);


CvMat *mask = cvCreateMat( img->height,img->width, CV_64FC1 );


int Xmin = -img->width/2;
int Ymin = -img->height/2;
int i, j;


// function transferece filter matrix
for(i=0; iwidth; i++)
for(j=0; jheight; j++)
{
double dxy = sqrt(pow(Xmin+i,2)+pow(Ymin+j,2));
double H;
if(tipo < 0)
{ H = (1/(1 + pow(dxy/fc,2*n)));} //low pass


if(tipo >= 0)
{
if(dxy==0){ H=0;}
else
H = (1/(1 + pow(fc/dxy,2*n))); //high pass
}


cvSetReal2D(mask, j, i, H);
}


cvCvtColor(img, cinza, CV_BGR2GRAY);
cvCvtScale(cinza, re64,1./255);
cvSetZero(im64);


cvFftw(re64,im64,true); //fft


cvMul(re64, mask, re64, 1);
cvMul(im64, mask, im64, 1);


cvFftw(re64,im64,false); //ifft


cvCvtScale(re64,dst ,255.);


cvReleaseImage(&re64);
cvReleaseImage(&im64);
cvReleaseImage(&cinza); 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值