为了账号安全,请及时绑定邮箱和手机立即绑定

灰度与颜色 FFT

灰度与颜色 FFT

C#
海绵宝宝撒 2021-09-19 15:35:32
以下代码将彩色图像转换为灰度,然后计算其 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);    }输出在第一种情况下,结果非常好,正如预期的那样。在第二种情况下,输出是全黑的。
查看完整描述

1 回答

?
天涯尽头无女友

TA贡献1831条经验 获得超9个赞

//img1.sycdn.imooc.com//6146e8810001646606750050.jpg

这个评论解决了我的问题。


    private void button2_Click(object sender, EventArgs e)

    {

        Bitmap source = (Bitmap)(pictureBox1.Image as Bitmap).Clone();


        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);


        int[,] normRed = FourierNormalizer.Normalize(shiftedFftCpxRed, NormalizeType.Magnitude);

        int[,] normGreen = FourierNormalizer.Normalize(shiftedFftCpxGreen, NormalizeType.Magnitude);

        int[,] normBlue = FourierNormalizer.Normalize(shiftedFftCpxBlue, NormalizeType.Magnitude);


        Bitmap mag = ImageDataConverter.ToBitmap3d(normRed, normGreen, normBlue, PixelFormat.Format8bppIndexed);

        //Grayscale.SetPalette(mag);

        //Bitmap mag = FourierPlot.FftMagnitudePlot(shiftedFftCpxRed, PixelFormat.Format8bppIndexed);

        Bitmap phase = FourierPlot.FftPhasePlot(shiftedFftCpxRed, PixelFormat.Format8bppIndexed);


        pictureBox2.Image = mag;

        pictureBox3.Image = mag;

        pictureBox4.Image = phase;

    }



查看完整回答
反对 回复 2021-09-19
  • 1 回答
  • 0 关注
  • 215 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信