FFTW and MelGibson

Printing an image before applying FFTW

Using the FFTW library, we can improve the visualization of the edges of an image. In this case we are going to use Fortran to compile the program fftw1.c using a make file:Now lets run it to have the image indicated in the source codeWorking with Plans to make it better after applying FFTW

Lets create the plan forward and backward

plan_forward = fftw_create_plan(NX,FFTW_FORWARD,FFTW_MEASURE);
plan_backward = fftw_create_plan(NX,FFTW_BACKWARD,FFTW_MEASURE);

Now we are going to perform the plan forward FFT in one dimension

  for(i=0;i<NX;i++)
  {
    for(j=0;j<NY;j++)
    {
      store[i][j].re = data[i][j];
      store[i][j].im = 0.0;
    }
  }
  for (i=0;i<NY;i++)
  {
    for (j=0;j<NX;j++)
    {
      in[j].re = store[i][j].re;
      in[j].im = store[i][j].im;
    }
    fftw_one(plan_forward, in, out);
    for (j=0;j<NX;j++)
    {
      store[i][j].re=out[j].re;
      store[i][j].im=out[j].im;
    }
  }

Let’s perform it in the 2nd dimension

for (j=0;j<NY;j++)
  {
    for (i=0;i<NX;i++)
    {
      in[i].re = store[i][j].re;
      in[i].im = store[i][j].im;
    }
    fftw_one(plan_forward, in, out);
    for (i=0;i<NX;i++)
    {
      store[i][j].re=out[i].re;
      store[i][j].im=out[i].im;
    }
  }

Writing the real and imaginary parts of the image in Fourier space to separate files.

 for (i=0;i<NX;i++)
 {
      for (j=0;j<NX;j++)
      {
      data[i][j] = store[i][j].re;
      }
  }
  pgmwrite("data_real.pgm", data, NX, NY, 1, 2);
  for (i=0;i<NX;i++)
  {
      for (j=0;j<NX;j++)
      {
      data[i][j] = store[i][j].im;
      }
  }
  pgmwrite("data_imag.pgm", data, NX, NY, 1, 2);

Operate on the image in Fourier space; either:

   *  1) cut off high frequencies, or

   *  2) cut off low frequencies

  filter_high_frequencies(store);

  Performing backward FFT in the 1st dimension.

  for (i=0;i<NY;i++)
  {
    for (j=0;j<NX;j++)
    {
      in[j].re = store[i][j].re;
      in[j].im = store[i][j].im;
    }
    fftw_one(plan_backward, in, out);
    for (j=0;j<NX;j++)
    {
      store[i][j].re=out[j].re;
      store[i][j].im=out[j].im;
    }
  }

 Performing backward FFT in the 2nd dimension.

  for (j=0;j<NY;j++)
  {
    for (i=0;i<NX;i++)
    {
      in[i].re = store[i][j].re;
      in[i].im = store[i][j].im;
    }
    fftw_one(plan_backward, in, out);
    for (i=0;i<NX;i++)
    {
      store[i][j].re=out[i].re;
      store[i][j].im=out[i].im;
    }
  }

Storing the final image.

    for (i=0;i<NX;i++)
    {
        for (j=0;j<NX;j++)
        {
            data[i][j]=(store[i][j].re)/(NX*NX);
        }
    }
  pgmwrite("finalFFT.pgm", data, NX, NY, 0, 255);

 Cleaning up the plans:

   fftw_destroy_plan(plan_forward);

   fftw_destroy_plan(plan_backward);

Finally compiling and running and the Mel Gibson image will improve with the functions.

gcc -O2 -L $LIB  -l $PATH-o  fftw1 fftw1.o io.o -lsfftw -lm

./fftw1

About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, Magíster en Computación de Alto Rendimiento de la Universidad de Edimburgo, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. Leader of LinuXatUNI Community, HPC Software Specialist at UKAEA, and reviewer of the Technological Magazine of ESPOL-RTE, and volunteering Linux training for MINSA Peru... a simple mortal, just like you!
This entry was posted in τεχνολογια :: Technology and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s