第1关:理想_低通滤波
#include "BMP.h"
IplImage* Ideal_LowPassFilter(IplImage* im)
{
int i,j;
IplImage *Ideal_LowPass = cvCreateImage(cvGetSize(im),IPL_DEPTH_8U,1);//˫ͨµÀ
cvZero(Ideal_LowPass); //Çå¿ÕÕâ¸öͼÏñµÄÄÚÈÝ
//******************ÀíÏëµÍͨÂ˲¨Æ÷******************//
//Ä£°åÀàÐÍÊÇ8λÎÞ·ûºÅÊý£¬Òò´ËPPTÖÐ1Ôڴ˶ÔÓ¦µÄÊÇ255£¬Ð轫0-1À©Õ¹µ½0-255Ö®¼ä
for(i=0;i<im->height;i++)
{
for(j=0;j<im->width;j++)
{
int x,y;
double D,D0;
x=i-im->height/2;
y=j-im->width/2;
D=sqrt(pow(x,2)+pow(y,2));
D0=20;
if(D<=D0)
{
/********* Begin *********/
Ideal_LowPass->imageData[i*im->width+j] = 265;
/********* End *********/
}
}
}
return Ideal_LowPass;
}
第2关:巴特沃斯低通滤波
#include "BMP.h"
IplImage* ButterWorth_LowPassFilter(IplImage* im)
{
int i,j;
IplImage *ButterWorth_LowPass = cvCreateImage(cvGetSize(im),IPL_DEPTH_8U,1);
cvZero(ButterWorth_LowPass); //Çå¿ÕÕâ¸öͼÏñµÄÄÚÈÝ
//******************°ÍÌØÎÖ˹µÍͨÂ˲¨Æ÷******************//
//Ä£°åÀàÐÍÊÇ8λÎÞ·ûºÅÊý£¬Òò´ËPPTÖÐ1Ôڴ˶ÔÓ¦µÄÊÇ255£¬Ð轫0-1À©Õ¹µ½0-255Ö®¼ä
for(i=0;i<im->height;i++)
{
for(j=0;j<im->width;j++)
{
int x,y,n;
double D,D0;
x=i-im->height/2;
y=j-im->width/2;
D=sqrt(pow(x,2)+pow(y,2));
D0=20;
n=2;
/********* Begin *********/
ButterWorth_LowPass->imageData[i*im->width+j] = 255/(1+pow(D/D0,2*n));
/********* End *********/
}
}
return ButterWorth_LowPass;
}
第3关:高斯低通滤波
#include "BMP.h"
IplImage* Gauss_LowPassFilter(IplImage* im)
{
int i,j;
IplImage *Gauss_LowPass = cvCreateImage(cvGetSize(im),IPL_DEPTH_8U,1);
cvZero(Gauss_LowPass); //Çå¿ÕÕâ¸öͼÏñµÄÄÚÈÝ
//******************¸ß˹µÍͨÂ˲¨Æ÷******************//
//Ä£°åÀàÐÍÊÇ8λÎÞ·ûºÅÊý£¬Òò´ËPPTÖÐ1Ôڴ˶ÔÓ¦µÄÊÇ255£¬Ð轫0-1À©Õ¹µ½0-255Ö®¼ä
for(i=0;i<im->height;i++)
{
for(j=0;j<im->width;j++)
{
int x,y,n;
double D,D0;
x=i-im->height/2;
y=j-im->width/2;
D=sqrt(pow(x,2)+pow(y,2));
D0=20;
n=2;
/********* Begin *********/
Gauss_LowPass->imageData[i*im->width+j] = 255*exp(-0.5*pow(D,2)/pow(D0,2));
/********* End *********/
}
}
return Gauss_LowPass;
}