Results 1 to 5 of 5

Thread: FFTW inQt

  1. #1
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default FFTW inQt

    Hi all! I am very noob in Qt and I'd like to get the fft of an image to do some edge detection with a high pass filter. I'm using Qt Creator 3 on Windows 8, and the code I'm posting crashes with this output:

    Starting C:\Users\Appretince\Documents\NWU\4de Jaar\1ste Sem\EERI315(413)- Seinteorie II\Prak1\Qt\build-Part2_Image-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\Part2_Image.exe...

    The program has unexpectedly finished.

    C:\Users\Appretince\Documents\NWU\4de Jaar\1ste Sem\EERI315(413)- Seinteorie II\Prak1\Qt\build-Part2_Image-Desktop_Qt_5_2_0_MinGW_32bit-Debug\debug\Part2_Image.exe crashed

    It bombs out on the in and out declaration, I think it might be that I'm using the fftw_malloc wrong. This is my code:

    QImage gray_image(ui->dspGrayscale->pixmap()->toImage());
    ui->dspFourierMag->setPixmap(QPixmap::fromImage(gray_image));
    ui->dspFourierPhs->setPixmap(QPixmap::fromImage(gray_image));

    fftw_complex *in, *out;
    fftw_plan p;
    width=gray_image.width();
    height=gray_image.height();
    QImage fmag_image(gray_image.size(),QImage::Format_RGB32) ;
    QImage fphs_image(gray_image.size(),QImage::Format_RGB32) ;
    in=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*width*height);
    out=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*width*height);

    p=fftw_plan_dft_2d(width,height,in,out,FFTW_FORWAR D,FFTW_MEASURE);
    k=0;

    for(x=0;x<width;x++)
    {
    for(y=0;y<height;y++)
    {
    in[k][0]=gray_image.pixel(x,y); //Real part of input
    in[k++][1]=0; //Imaginary part of input
    }
    }

    fftw_execute(p);
    k=0;

    for(x=0;x<width;x++)
    {
    for(y=0;y<height;y++)
    {
    fpixel=out[k][0];
    fmag_image.setPixel(x,y,fpixel);

    fpixel=out[k++][1];
    fphs_image.setPixel(x,y,fpixel);
    }
    }

    fftw_destroy_plan(p);
    ui->dspFourierMag->setPixmap(QPixmap::fromImage(fmag_image));
    ui->dspFourierPhs->setPixmap(QPixmap::fromImage(fphs_image));

    Any help would be much appreciated. Thank you.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: FFTW inQt

    My guess is that the value of k goes out of bounds. Run your program in a debugger and inspect the backtrace and values actually in variables at the time of the crash.

    BTW There is a fftw_malloc_complex() convenience function you could use.

  3. #3
    Join Date
    May 2015
    Posts
    3
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: FFTW inQt

    If I comment out the k loop it still doesn't work. It crashes whenever I run these commands:

    in=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*width*height);
    out=(fftw_complex *)fftw_malloc(sizeof(fftw_complex)*width*height);

    I've tried lowering the size but it still crashes. Thanks for the help though.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: FFTW inQt

    Are you certain it is the allocations and not the subsequent accesses?
    See the notes about indexing: http://www.fftw.org/doc/Dynamic-Arra...ic-Arrays-in-C
    and look at what you are doing in your nested loops.

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: FFTW inQt

    Run your program in a debugger and inspect the backtrace and values actually in variables at the time of the crash.
    Have you done what ChrisW67 suggested, and debug to see what the values actually are when the crash occurs? Random guesses about what might be going wrong might get you to something that works, but you'll have no idea why. Your code will remain fragile and ready to crash again at the next unhappy combination of parameters.

Similar Threads

  1. how to delete a QToolButton inQt
    By Soumya Somasekhar Ram in forum Qt Programming
    Replies: 7
    Last Post: 23rd September 2013, 13:45
  2. Linking fftw, etc with qt
    By metanoya in forum Newbie
    Replies: 2
    Last Post: 15th June 2008, 20:13
  3. linking fftw 3.0.1
    By Yacob in forum General Programming
    Replies: 4
    Last Post: 18th January 2007, 15:14
  4. fftw help
    By superutsav in forum General Programming
    Replies: 3
    Last Post: 10th April 2006, 13:51
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.