title: Filtering on Fourier image and then taking its Inverse fourier to get the image
body: <pre><code>       // Fourier transform of Image&lt;Bgr,byte&gt; orig object.
         // output is matrix&lt;float&gt; with 2 channels.
  
          private Matrix&lt;float&gt; fourier()
      {
          Image&lt;Gray, float&gt; image = orig.Convert&lt;Gray, float&gt;();
          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&lt;float&gt; dft = new Matrix&lt;float&gt;(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&lt;float&gt; outReal = new Matrix&lt;float&gt;(image.Size);
          //The imaginary part of the Fourier Transform
          Matrix&lt;float&gt; outIm = new Matrix&lt;float&gt;(image.Size);
          CvInvoke.cvSplit(dft, outReal, outIm, IntPtr.Zero, IntPtr.Zero);
          return dft;
      }
  
      // butterworth filter with Do frequency and order n.
      // Filter is returned as matrix&lt;float&gt; with 2 channels. 
  
      private Matrix&lt;float&gt; make_butterworth(int Do, int n)
      {
          Matrix&lt;float&gt; ff = fourier();
          Matrix&lt;float&gt; tmp = new Matrix&lt;float&gt;(ff.Rows, ff.Cols, 2);
  
          Point center=new Point(tmp.Rows/2,tmp.Cols/2);
  
          for (int i=0;i&lt;orig.Rows;i++)
              for (int j = 0; j &lt; orig.Cols; j++)
              {
                    int Duv= (int) (Math.Sqrt( Math.Pow(i-center.X,2) + Math.Pow(j-center.Y,2)));
                    tmp[i, j] = (float) (1 / (1 + Math.Pow((Duv / Do), 2 * n)));
              }
  
          return tmp;
      }
  
  
      // The click event which will trigger fourier() and
         make_butterworth() takes Do and n order input from user
         and applies filter on orig image.
  
      private void lowPassToolStripMenuItem2_Click(object sender, EventArgs e)
      {
          dialog_input d1 = new dialog_input("Enter values of Do and order n seperated by space:\n");
          d1.ShowDialog();
          string[] s = d1.t.Split(new char[] { ' ', ',' });
          int fc = Convert.ToInt32(s[0]);
          int order = Convert.ToInt32(s[1]);
  
          Matrix&lt;float&gt; filter= make_butterworth(fc, order); // 2 channels
          Matrix&lt;float&gt; m = fourier(); // 2 channels
          m._Mul(filter);
          // filter * with fourier image.
          CvInvoke.cvDFT(m,m,CV_DXT.CV_DXT_INVERSE, 0);
  
          IntPtr cmplx = CvInvoke.cvCreateImage(m.Size, IPL_DEPTH.IPL_DEPTH_32F, 2);
          CvInvoke.cvSetZero(cmplx);
          CvInvoke.cvSetImageCOI(cmplx, 0);
          CvInvoke.cvCopy(m, cmplx, IntPtr.Zero);
  
          Bitmap bm = new Bitmap(m.Width, m.Height);
  
          BitmapData bd = bm.LockBits(new Rectangle
              (0, 0, bm.Width, bm.Height),
              ImageLockMode.ReadWrite,
              PixelFormat.Canonical);
  
          bd.Scan0 = cmplx;
  
          bm.UnlockBits(bd);
          pictureBox2.Image = bm;
        }
  </code></pre>
  
  <p>One thing i am taking fourier() as 2 channels instead of only taking real channel. i am not sure if i am wrong in this regard. Also thats why i had to take filter as 2 channels also where 2 channels are used to represent data of Gray and Alpha in both cases.</p>
  
  <p>Problem occurs at bitmapdata object initialization due to pixelFormat.Canonical parameter. The result of multiply of fourier matrix and filter matrix is in matrix float. All i want to do is to take its IDFT and display the filtered image. Not sure about the PixelFormat. Any help would be great.</p>