灰度与颜色 FFT

以下代码将彩色图像转换为灰度,然后计算其 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);


    }

输出


http://img4.mukewang.com/6146e86800015b5602980315.jpghttp://img2.mukewang.com/6146e8700001e59902960313.jpg

在第一种情况下,结果非常好,正如预期的那样。在第二种情况下,输出是全黑的。



海绵宝宝撒
浏览 216回答 1
1回答

天涯尽头无女友

这个评论解决了我的问题。&nbsp; &nbsp; private void button2_Click(object sender, EventArgs e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; Bitmap source = (Bitmap)(pictureBox1.Image as Bitmap).Clone();&nbsp; &nbsp; &nbsp; &nbsp; int[, ,] array3d = ImageDataConverter.ToInteger3d(source);&nbsp; &nbsp; &nbsp; &nbsp; int[,] red = ArrayTools<int>.Split(array3d, 0);&nbsp; &nbsp; &nbsp; &nbsp; int[,] green = ArrayTools<int>.Split(array3d, 1);&nbsp; &nbsp; &nbsp; &nbsp; int[,] blue = ArrayTools<int>.Split(array3d, 2);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] cpxRed = ImageDataConverter.ToComplex(red);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] cpxGreen = ImageDataConverter.ToComplex(green);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] cpxBlue = ImageDataConverter.ToComplex(blue);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] fftCpxRed = FourierTransform.ForwardFFT(cpxRed);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] fftCpxGreen = FourierTransform.ForwardFFT(cpxGreen);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] fftCpxBlue = FourierTransform.ForwardFFT(cpxBlue);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] shiftedFftCpxRed = FourierShifter.ShiftFft(fftCpxRed);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] shiftedFftCpxGreen = FourierShifter.ShiftFft(fftCpxGreen);&nbsp; &nbsp; &nbsp; &nbsp; Complex[,] shiftedFftCpxBlue = FourierShifter.ShiftFft(fftCpxBlue);&nbsp; &nbsp; &nbsp; &nbsp; int[,] normRed = FourierNormalizer.Normalize(shiftedFftCpxRed, NormalizeType.Magnitude);&nbsp; &nbsp; &nbsp; &nbsp; int[,] normGreen = FourierNormalizer.Normalize(shiftedFftCpxGreen, NormalizeType.Magnitude);&nbsp; &nbsp; &nbsp; &nbsp; int[,] normBlue = FourierNormalizer.Normalize(shiftedFftCpxBlue, NormalizeType.Magnitude);&nbsp; &nbsp; &nbsp; &nbsp; Bitmap mag = ImageDataConverter.ToBitmap3d(normRed, normGreen, normBlue, PixelFormat.Format8bppIndexed);&nbsp; &nbsp; &nbsp; &nbsp; //Grayscale.SetPalette(mag);&nbsp; &nbsp; &nbsp; &nbsp; //Bitmap mag = FourierPlot.FftMagnitudePlot(shiftedFftCpxRed, PixelFormat.Format8bppIndexed);&nbsp; &nbsp; &nbsp; &nbsp; Bitmap phase = FourierPlot.FftPhasePlot(shiftedFftCpxRed, PixelFormat.Format8bppIndexed);&nbsp; &nbsp; &nbsp; &nbsp; pictureBox2.Image = mag;&nbsp; &nbsp; &nbsp; &nbsp; pictureBox3.Image = mag;&nbsp; &nbsp; &nbsp; &nbsp; pictureBox4.Image = phase;&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP