以下代码将彩色图像转换为灰度,然后计算其 FFT:
private void button1_Click(object sender, EventArgs e)
{
Bitmap source = pictureBox1.Image as Bitmap;
Bitmap gray = Grayscale.ToGrayscale(source);
Complex[,] cpxImage = ImageDataConverter.ToComplex(gray);
Complex[,] fftCpxImage = FourierTransform.ForwardFFT(cpxImage);
Complex[,] shiftedFftCpxImage = FourierShifter.ShiftFft(fftCpxImage);
Bitmap mag = FourierPlot.FftMagnitudePlot(shiftedFftCpxImage, PixelFormat.Format8bppIndexed);
Bitmap phase = FourierPlot.FftPhasePlot(shiftedFftCpxImage, PixelFormat.Format8bppIndexed);
pictureBox2.Image = gray;
pictureBox3.Image = mag;
pictureBox4.Image = phase;
}
以下代码将彩色图像分成三个通道,计算它们的 FFT 并将它们合并在一起以形成 FFT 的 RGB 图像。
private void button2_Click(object sender, EventArgs e)
{
Bitmap source = pictureBox1.Image as Bitmap;
int [,,] array3d = ImageDataConverter.ToInteger3d(source);
int[,] red = ArrayTools<int>.Split(array3d, 0);
int[,] green = ArrayTools<int>.Split(array3d, 1);
int[,] blue = ArrayTools<int>.Split(array3d, 2);
Complex [,] cpxRed = ImageDataConverter.ToComplex(red);
Complex [,] cpxGreen = ImageDataConverter.ToComplex(green);
Complex [,] cpxBlue = ImageDataConverter.ToComplex(blue);
Complex[,] fftCpxRed = FourierTransform.ForwardFFT(cpxRed);
Complex[,] fftCpxGreen = FourierTransform.ForwardFFT(cpxGreen);
Complex[,] fftCpxBlue = FourierTransform.ForwardFFT(cpxBlue);
Complex[,] shiftedFftCpxRed = FourierShifter.ShiftFft(fftCpxRed);
Complex[,] shiftedFftCpxGreen = FourierShifter.ShiftFft(fftCpxGreen);
Complex[,] shiftedFftCpxBlue = FourierShifter.ShiftFft(fftCpxBlue);
}
输出
在第一种情况下,结果非常好,正如预期的那样。在第二种情况下,输出是全黑的。
天涯尽头无女友
相关分类