Ideal Lowpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
int d = (int)System.Math.Sqrt(x * x + y * y);
// filter values outside the range
if ((d > d0))
{
data[i, j].Re = 0;
data[i, j].Im = 0;
}
}
}
Butterworth Lowpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
double d = System.Math.Sqrt(x * x + y * y);
double h = 1.0 / (1.0 + System.Math.Pow(d / d0, 2.0 * n));
data[i, j].Re *= h;
data[i, j].Im *= h;
}
}
Gaussian Lowpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
double d = System.Math.Sqrt(x * x + y * y);
double h = System.Math.Exp(-d * d / 2.0 / d0 / d0);
data[i, j].Re *= h;
data[i, j].Im *= h;
}
}
Ideal Highpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
int d = (int)System.Math.Sqrt(x * x + y * y);
// filter values outside the range
if ((d < d0))
{
data[i, j].Re = 0;
data[i, j].Im = 0;
}
}
}
Butterworth Highpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
double d = System.Math.Sqrt(x * x + y * y);
double h = 1.0 / (1.0 + System.Math.Pow(d0 / d, 2.0 * n));
data[i, j].Re *= h;
data[i, j].Im *= h;
}
}
Gaussian Highpass Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
double d = System.Math.Sqrt(x * x + y * y);
double h = 1.0 - System.Math.Exp(-d * d / 2.0 / d0 / d0);
data[i, j].Re *= h;
data[i, j].Im *= h;
}
}
Homomorphic Filter

Code
for (int i = 0; i < height; i++)
{
int y = i - hh;
for (int j = 0; j < width; j++)
{
int x = j - hw;
double d = System.Math.Sqrt(x * x + y * y);
double h = (γH - γL) * (1.0 - System.Math.Exp(-c * d * d / D0 / D0)) + γL;
data[i, j].Re *= h;
data[i, j].Im *= h;
}
}