代码之家  ›  专栏  ›  技术社区  ›  user366312

在EmguCV.3.1.0.1中,找到图像傅里叶变换的最小代码是什么?

  •  0
  • user366312  · 技术社区  · 7 年前

    我想找到一个图像的傅立叶变换,并在EmguCV.3.1.0.1中显示它的幅度和相位谱。

    public partial class Form1 : Form
    {
        const string path = @"lenagr.png";
        Image<Bgr, float> image;
    
        public Form1()
        {
            InitializeComponent();
    
            image = new Image<Bgr, float>(path);
    
            pictureBox1.Image = image.Bitmap;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {            
            Mat dft = new Mat(image.Size, DepthType.Default, 2);
            CvInvoke.Dft(image, dft, DxtType.Forward, image.Rows);
    
            Mat[] images = dft.Split();
    
            //Show The Data   
            //Image<Bgr, float> im2 = dft.ToImage<Bgr, float>();
            pictureBox2.Image = images[0].Bitmap;
        }
    }
    

    此源代码冻结应用程序。

    那么,在EmguCV.3.1.0.1中,找到图像傅里叶变换的绝对最小代码是什么?

    注: The following source code

    Image<Gray, float> image = new Image<Gray, float>(open.FileName);
    IntPtr complexImage = CvInvoke.cvCreateImage(image.Size, Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_32F, 2);
    
    CvInvoke.cvSetZero(complexImage);  // Initialize all elements to Zero
    CvInvoke.cvSetImageCOI(complexImage, 1);
    CvInvoke.cvCopy(image, complexImage, IntPtr.Zero);
    CvInvoke.cvSetImageCOI(complexImage, 0);
    
    Matrix<float> dft = new Matrix<float>(image.Rows, image.Cols, 2);
    CvInvoke.cvDFT(complexImage, dft, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, 0);
    
    //The Real part of the Fourier Transform
    Matrix<float> outReal = new Matrix<float>(image.Size);
    //The imaginary part of the Fourier Transform
    Matrix<float> outIm = new Matrix<float>(image.Size);
    CvInvoke.cvSplit(dft, outReal, outIm, IntPtr.Zero, IntPtr.Zero);
    
    //Show The Data       
    CvInvoke.cvShowImage("Real", outReal);
    CvInvoke.cvShowImage("Imaginary ", outIm);
    

    现在还不清楚什么声明在做什么。而且,它混淆了 IntPtr , Image<T1, T2> , Matrix<T> ,不利用 Mat

    0 回复  |  直到 7 年前