using MyImageProcessingLibrary;
using System.Collections.Generic;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MyImageProcessingLibrary
public static double tx(double centerX, double theta)
return centerX * Math.Cos(theta);
public static double ty(double centerY, double theta)
return centerY * Math.Sin(theta);
public static double u_star(double u, double centerX, double centerY, double theta)
return Math.Cos(theta) * (u + tx(centerX, theta))
+ Math.Sin(theta) * (u + ty(centerY, theta));
public 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);
return 1 / (1 + 0.414 * Math.Pow(Math.Sqrt((u_star / Dh) + (v_star / Dv)), 2 * N));
namespace MyImageProcessingLibrary
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; }
public int [,] Apply(Complex [,] image)
int imageWidth = image.GetLength(0);
int imageHeight = image.GetLength(1);
int [,] array2D = new int[imageWidth, imageHeight];
for(int i=0 ; i<imageWidth ; i++)
for (int j = 0; j < imageHeight; j++)
array2D[i, j] = (int)KassWitkin.ApplyFilterOnOneCoord(image[i, j].Real, image[i, j].Imaginary, Dh, Dv, CenterX, CenterY, Theta, N);
public partial class KassWitkinBandpassFilterTestForm : Form
string path = @"E:\___MSc in Computer Systems & Network\EMSC1,2,3\baboon.png";
public KassWitkinBandpassFilterTestForm()
private void LoadImageButton_Click(object sender, EventArgs e)
sourceImagePictureBox.Image = (Image)Bitmap.FromFile(path);
KassWitkinBandpassFilter kwbf = new KassWitkinBandpassFilter();
private void ApplyFilterButton_Click(object sender, EventArgs e)
Complex[,] comp = FastFourierTransform.Shift(FastFourierTransform.ForwardFFT(MyConverter.BitmapToArray2D((Bitmap)sourceImagePictureBox.Image)));
fftPictureBox.Image = MyConverter.Array2DToBitmap(FastFourierTransform.FrequencyPlot(comp));
kwbf.Dh = (int) DhNumericUpDown.Value;
kwbf.Dv = (int)DhNumericUpDown.Value;
kwbf.CenterX = (int)fftPictureBox.Image.Width / 2;
kwbf.CenterY = (int)fftPictureBox.Image.Height / 2;
kwbf.Theta = (int) thetaNumericUpDown.Value/180*Math.PI;
kassWitkinFilterPictureBox.Image = MyConverter.Array2DToBitmap(kwbf.Apply(comp));
private void nNumericUpDown_ValueChanged(object sender, EventArgs e)
ApplyFilterButton_Click(sender, e);