15,745,433 members
1.00/5 (1 vote)
See more: , +
In this research paper,

Multidirectional Scratch Detection and Restoration in Digitized Old Images | SpringerLink[^]

in the Section 4.1(Preprocessing), an equation of a Bandpass filter is given:

https://qph.ec.quoracdn.net/main-qimg-acdd986df7a8871b6f0cc0a89893be50?convert_to_webp=true

Where,

https://qph.ec.quoracdn.net/main-qimg-a35b53df0146418f4864693e32b6c130?convert_to_webp=true[^]

Now, I have implemented this like the following:

he function, ApplyFilterToOneCoordinate is actually returning NaN,

Home | .NET Fiddle[^]
Home | .NET Fiddle[^]

But, this code produces nothing:

https://qph.ec.quoracdn.net/main-qimg-a65ec9502571e5303b898d6a5f6a06ee?convert_to_webp=true[^]

https://qph.ec.quoracdn.net/main-qimg-e3f4aa9a2da5cb00167a3681c5d5d1a3?convert_to_webp=true[^]

https://qph.ec.quoracdn.net/main-qimg-0f0f86a58efa78611fc907d7a8e2231b?convert_to_webp=true[^]

What I have tried:

C#
```public class KassWitkin
{
private static double tx(double centerX, double theta)
{
return centerX * Math.Cos(theta);
}

private static double ty(double centerY, double theta)
{
return centerY * Math.Sin(theta);
}

private static double u_star(double u, double centerX, double centerY, double theta)
{
double txx = tx(centerX, theta);
double tyy = ty(centerY, theta);

double cost = Math.Cos(theta);
double sint = Math.Sin(theta);

double costutxx = cost * (u + txx);
double sintutyy = sint * (u + tyy);
return costutxx + sintutyy;
}

private static double v_star(double u, double centerX, double centerY, double theta)
{
return (-1) * Math.Sin(theta) * (u + tx(centerX, theta))
+ Math.Cos(theta) * (u + ty(centerY, theta));
}

public static double ApplyFilterOnOneCoord(double u, double v, double Dh, double Dv, double CenterX, double CenterY, double Theta, int N)
{
double u_star = KassWitkin.u_star(u, CenterX, CenterY, Theta);
double v_star = KassWitkin.v_star(u, CenterX, CenterY, Theta);

double uStarDh = (u_star / Dh);
double vStarDh = (v_star / Dv);
double sqrts = Math.Sqrt(uStarDh + vStarDh);
double power = Math.Pow(sqrts, 2 * N);
double divvy = (1 + 0.414 * power);
double returns = 1 / divvy;

return returns;
}
}

public class KassWitkinBandpassFilter
{
public readonly int N = 4;
public double Dh { get; set; }
public double Dv { get; set; }
public double CenterX { get; set; }
public double CenterY { get; set; }
public double Theta { get; set; }

///http://stackoverflow.com/questions/37769350/how-can-i-create-a-bank-of-oriented-band-pass-filters
private double[,] GetKernel(int width, int height)
{
double[,] kernel2d = new double[width, height];

for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
kernel2d[i, j] = (double)KassWitkin.ApplyFilterOnOneCoord(i, j, Dh, Dv, CenterX, CenterY, Theta, N);
}
}

return kernel2d;
}

public Complex [,] ApplyFilter(Complex [,] input)
{
int width = input.GetLength(0);
int height = input.GetLength(1);

double[,] kernel = GetKernel(width, height);

Complex[,] output = new Complex[width, height];

for (int i = 0; i < width; i++ )
{
for (int j = 0; j < height; j++)
{
output[i,j] = input[i,j] * kernel[i,j];
}
}

return output;
}
}```
Posted
Updated 15-Jul-16 8:08am
v4