LitDev.Engines.FIP.iDFT C# (CSharp) Method

iDFT() public method

Inverse Discrete Fourier Transform
public iDFT ( Complex Spectrum ) : Bitmap
Spectrum Complex Image spectrum
return System.Drawing.Bitmap
        public Bitmap iDFT(Complex[,] Spectrum)
        {
            Bitmap img = new Bitmap(Spectrum.GetLength(0), Spectrum.GetLength(1));

            for (int i = 0; i < Spectrum.GetLength(0); i++)
            {
                for (int j = 0; j < Spectrum.GetLength(1); j++)
                {

                    Double I = Convert.ToDouble(i);
                    Double J = Convert.ToDouble(j);

                    Complex im = new Complex(0, 1);

                    Complex sum = 0;

                    for (int k = 0; k < Spectrum.GetLength(0); k++)
                    {
                        for (int l = 0; l < Spectrum.GetLength(1); l++)
                        {

                            Double K = Convert.ToDouble(k);
                            Double L = Convert.ToDouble(l);

                            Double G = (K * I) / Convert.ToDouble(Spectrum.GetLength(0)) + (L * J) / Convert.ToDouble(Spectrum.GetLength(1));

                            Complex exp = Complex.Exp(im * 2 * Math.PI * G);

                            sum += Spectrum[k, l] * exp;

                        }
                    }

                    int value = (int)(sum.Magnitude / Math.Sqrt(Convert.ToDouble(Spectrum.GetLength(0)) * Convert.ToDouble(Spectrum.GetLength(1))));

                    if (value > 255) value = 255;

                    img.SetPixel(i, j, Color.FromArgb(255, value, value, value));

                }
            }

            return img;
        }