//****************************************************************** //****************************************************************** private void FFT_Click(object sender, EventArgs e) { //check user has loaded an image to edit if (originalImage == null) { MessageBox.Show("Please select a valid image"); return; } Bitmap copy = new Bitmap((Bitmap)this.pBox.Image); try { // create greyscale bitmap var grayScaledImage = ComplexImage.ToGrayscale(copy); var complexIm = ComplexImage.ConvertBitmapImageToComplex(grayScaledImage); Fourier.FFT2D(complexIm, 1); var transformedImage = ComplexImage.ConvertComplexImageToBitmap(complexIm); this.pBox.Image = transformedImage; } catch (Exception ex) { MessageBox.Show($"Error: {0}", ex.Message); } }
public static void FFT2D(Complex[,] complexImage, int direction) { int width = complexImage.GetLength(0); int height = complexImage.GetLength(1); //check data size if ( (!ComplexImage.IsPowerOfTwo(width)) || (!ComplexImage.IsPowerOfTwo(height)) ) { throw new ArgumentException("Incorrect data length."); } //process the rows Complex[] row = new Complex[width]; for (int j = 0; j < height; j++) { // copy row for (int i = 0; i < width; i++) { row[i] = complexImage[i, j]; } // transform it FFT1D(direction, row); // copy back for (int i = 0; i < width; i++) { complexImage[i, j] = row[i]; } } // process the columns Complex[] column = new Complex[height]; for (int i = 0; i < width; i++) { // copy row for (int j = 0; j < height; j++) { column[j] = complexImage[i, j]; } // transform it FFT1D(direction, column); // copy back for (int j = 0; j < height; j++) { complexImage[i, j] = column[j]; } } }