예제 #1
0
        private void valueChangeEvent()
        {
            bitmapResult = BitmapOrigin.Clone() as Bitmap;
            x            = bitmapResult.Width;
            y            = bitmapResult.Height;
            Complex32[] matrix = new Complex32[x * y];
            for (int i = 0; i < x; i++)
            {
                for (int j = 0; j < y; j++)
                {
                    matrix[i * x + j] = bitmapResult.GetPixel(i, j).R;
                }
            }
            var ms = matrix.Clone();

            Fourier.Forward2D(matrix, x, y);

            //for (int i = 0; i < x; i++)
            //{
            //    for (int j = 0; j < y; j++)
            //    {
            //        var gray =  (byte)matrix[i * x + j].r
            //        bitmapResult.SetPixel(i, j, Color.FromArgb(matrix[i * x + j], matrix[i * x + j], matrix[i * x + j]));
            //    }
            //}
        }
예제 #2
0
        /// <summary>
        /// Performs a 2D-Fourier transform on data in the passed Matrix/image.
        /// </summary>
        /// <param name="M"></param>
        /// <returns></returns>
        public static double[,] FFT2Dimensional(double[,] M)
        {
            // Step 1: convert matrix to complex array
            //double[] sampleData = Matrix2PaddedVector(M);

            // AT 20180202: updated call to support newer MathNet API
            var sampleData = Matrix2ComplexVector(M);

            int rowCount = M.GetLength(0);
            int colCount = M.GetLength(1);

            // Step 2: do 2d fft
            Fourier.Forward2D(sampleData, rowCount, colCount, FourierOptions.Matlab);

            // Step 3: Convert complex output array to array of real magnitude values
            var magnitudeMatrix = Fft2DOutputToMatrixOfMagnitude(rowCount, colCount, sampleData);

            // Step 3: do the shift for array of magnitude values.
            // var outputData = magnitudeMatrix; // no shifting
            var outputData = fftShift(magnitudeMatrix);

            return(outputData);
        }
예제 #3
0
        private void NBodyFFT()
        {
            //Compute the values v_{m, n} at the equispaced nodes, multiply the kernel matrix with the coefficients w
            int n_fft_coeffs = 2 * n_interpolation_points_1d;

            for (int d = 0; d < n_terms; d += 2)
            {
                Array.Clear(fft, 0, fft.Length);
                for (int i = 0; i < n_interpolation_points_1d; i++)
                {
                    for (int j = 0; j < n_interpolation_points_1d; j++)
                    {
                        fft[i * n_fft_coeffs + j] = new Complex(tilde_values[(i * n_interpolation_points_1d + j) * n_terms + d], tilde_values[(i * n_interpolation_points_1d + j) * n_terms + d + 1]);
                    }
                }

                Fourier.Forward2D(fft, n_fft_coeffs, n_fft_coeffs);

                // Take the Hadamard product of two complex vectors
                for (int i = kernel_tilde.Length - 1; i >= 0; i--)
                {
                    fft[i] *= kernel_tilde[i];
                }

                // Invert the computed values at the interpolated nodes
                Fourier.Inverse2D(fft, n_fft_coeffs, n_fft_coeffs);

                for (int i = 0; i < n_interpolation_points_1d; i++)
                {
                    for (int j = 0; j < n_interpolation_points_1d; j++)
                    {
                        tilde_values[(i * n_interpolation_points_1d + j) * n_terms + d]     = fft[(n_interpolation_points_1d + i) * n_fft_coeffs + n_interpolation_points_1d + j].Real;
                        tilde_values[(i * n_interpolation_points_1d + j) * n_terms + d + 1] = fft[(n_interpolation_points_1d + i) * n_fft_coeffs + n_interpolation_points_1d + j].Imaginary;
                    }
                }
            }
        }
예제 #4
0
        private void ComputeKernelTilde()
        {
            //Evaluate the kernel at the interpolation nodes and form the embedded generating kernel vector for a circulant matrix
            int n_fft_coeffs = 2 * n_interpolation_points_1d;

            for (int i = 0; i < n_interpolation_points_1d; i++)
            {
                for (int j = 0; j < n_interpolation_points_1d; j++)
                {
                    fft[(n_interpolation_points_1d + i) * n_fft_coeffs + n_interpolation_points_1d + j]
                              = fft[(n_interpolation_points_1d - i) * n_fft_coeffs + n_interpolation_points_1d + j]
                              = fft[(n_interpolation_points_1d + i) * n_fft_coeffs + n_interpolation_points_1d - j]
                              = fft[(n_interpolation_points_1d - i) * n_fft_coeffs + n_interpolation_points_1d - j]
                              = SquaredCauchy(tilde[0], tilde[i], tilde[j]);
                }
            }

            // Precompute the FFT of the kernel generating matrix
            Fourier.Forward2D(fft, n_fft_coeffs, n_fft_coeffs, FourierOptions.NoScaling);
            for (int i = fft.Length - 1; i >= 0; i--)
            {
                kernel_tilde[i] = fft[i].Real;
            }
        }