Discrete Fourier Transform

The Fourier Transform will decompose an image into its sinus and cosines components. It will transform an image from its spatial domain to its frequency domain. Mathematically a two dimensional images Fourier transform is:
F(k,l) = \displaystyle\sum\limits_{i=0}^{N-1}\sum\limits_{j=0}^{N-1} f(i,j)e^{-i2\pi(\frac{ki}{N}+\frac{lj}{N})}

e^{ix} = \cos{x} + i\sin {x}

Here f is the image value in its spatial domain and F in its frequency domain. The result of the transformation is complex numbers.

dft Performs a forward or inverse Discrete Fourier transform of a 1D or 2D floating-point array.

void dft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0)

Parameters:
  • src – input array that could be real or complex.
  • dst – output array whose size and type depends on the flags .
  • flags – transformation flags, representing a combination of the following values:
    • DFT_INVERSE performs an inverse 1D or 2D transform instead of the default forward transform.
    • DFT_SCALE scales the result: divide it by the number of array elements. Normally, it is combined with DFT_INVERSE.
    • DFT_ROWS performs a forward or inverse transform of every individual row of the input matrix; this flag enables you to transform multiple vectors simultaneously and can be used to decrease the overhead (which is sometimes several times larger than the processing itself) to perform 3D and higher-dimensional transformations and so forth.
    • DFT_COMPLEX_OUTPUT performs a forward transformation of 1D or 2D real array; the result, though being a complex array, has complex-conjugate symmetry (CCS, see the function description below for details), and such an array can be packed into a real array of the same size as input, which is the fastest option and which is what the function does by default; however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) - pass the flag to enable the function to produce a full-size complex output array.
    • DFT_REAL_OUTPUT performs an inverse transformation of a 1D or 2D complex array; the result is normally a complex array of the same size, however, if the input array has conjugate-complex symmetry (for example, it is a result of forward transformation with DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not check whether the input is symmetrical or not, you can pass the flag and then the function will assume the symmetry and produce the real output array (note that when the input is packed into a real array and inverse transformation is executed, the function treats the input as a packed complex-conjugate symmetrical array, and the output will also be a real array).
  • nonzeroRows – when the parameter is not zero, the function assumes that only the first nonzeroRows rows of the input array (DFT_INVERSE is not set) or only the first nonzeroRows of the output array (DFT_INVERSE is set) contain non-zeros, thus, the function can handle the rest of the rows more efficiently and save some time; this technique is very useful for calculating array cross-correlation or convolution using DFT.
void idft(InputArray src, OutputArray dst, int flags=0, int nonzeroRows=0)

Parameters:
  • src – input floating-point real or complex array.
  • dst – output array whose size and type depend on the flags.
  • flags – operation flags (same as dft()).
  • nonzeroRows – number of dst rows to process; the rest of the rows have undefined content

Example 1:

------------
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    // Read image from file
    // Make sure that the image is in grayscale
    Mat img = imread("lena.JPG",0);
    
    Mat planes[] = {Mat_<float>(img), Mat::zeros(img.size(), CV_32F)};
    Mat complexI;    //Complex plane to contain the DFT coefficients {[0]-Real,[1]-Img}
    merge(planes, 2, complexI);
    dft(complexI, complexI);  // Applying DFT

    // Reconstructing original imae from the DFT coefficients
    Mat invDFT, invDFTcvt;
    idft(complexI, invDFT, DFT_SCALE | DFT_REAL_OUTPUT ); // Applying IDFT
    invDFT.convertTo(invDFTcvt, CV_8U); 
    imshow("Output", invDFTcvt);

    //show the image
    imshow("Original Image", img);
    
    // Wait until user press some key
    waitKey(0);
    return 0;
}
------------

Example 2:

------------
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main()
{
    // Read image from file
    // Make sure that the image is in grayscale
    Mat img = imread("lena.JPG",0);

    Mat dftInput1, dftImage1, inverseDFT, inverseDFTconverted;
    img.convertTo(dftInput1, CV_32F);
    dft(dftInput1, dftImage1, DFT_COMPLEX_OUTPUT);    // Applying DFT

    // Reconstructing original imae from the DFT coefficients
    idft(dftImage1, inverseDFT, DFT_SCALE | DFT_REAL_OUTPUT ); // Applying IDFT
    inverseDFT.convertTo(inverseDFTconverted, CV_8U);
    imshow("Output", inverseDFTconverted);

    //show the image
    imshow("Original Image", img);
    
    // Wait until user press some key
    waitKey(0);
    return 0;
}
------------

Sources:
http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#void%20dft%28InputArray%20src,%20OutputArray%20dst,%20int%20flags,%20int%20nonzeroRows%29

http://docs.opencv.org/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html

85 comments:

  1. Doesn't work—neither example. Here's the error for example #2:

    2015-04-21 17:46:01.085 OpenCVCam[1289:162608] camera available: YES
    2015-04-21 17:46:02.065 OpenCVCam[1289:162608] [Camera] device connected? YES
    2015-04-21 17:46:02.066 OpenCVCam[1289:162608] [Camera] device position back
    2015-04-21 17:46:02.076 OpenCVCam[1289:162608] WARNING: -[ isVideoMinFrameDurationSupported] is deprecated. Please use AVCaptureDevice activeFormat.videoSupportedFrameRateRanges
    2015-04-21 17:46:02.077 OpenCVCam[1289:162608] WARNING: -[ setVideoMinFrameDuration:] is deprecated. Please use AVCaptureDevice setActiveVideoMinFrameDuration
    2015-04-21 17:46:02.078 OpenCVCam[1289:162608] WARNING: -[ isVideoMaxFrameDurationSupported] is deprecated. Please use AVCaptureDevice activeFormat.videoSupportedFrameRateRanges
    2015-04-21 17:46:02.079 OpenCVCam[1289:162608] WARNING: -[ setVideoMaxFrameDuration:] is deprecated. Please use AVCaptureDevice setActiveVideoMaxFrameDuration
    2015-04-21 17:46:02.082 OpenCVCam[1289:162608] layout preview layer
    2015-04-21 17:46:02.084 OpenCVCam[1289:162608] [Camera] created AVCaptureVideoDataOutput at 30 FPS
    OpenCV Error: Assertion failed (type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2) in dft, file /Users/build/test/opencv/modules/core/src/dxt.cpp, line 2466
    libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/build/test/opencv/modules/core/src/dxt.cpp:2466: error: (-215) type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 in function dft

    ReplyDelete
    Replies
    1. Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download Now

      >>>>> Download Full

      Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download LINK

      >>>>> Download Now

      Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download Full

      >>>>> Download LINK XT

      Delete
  2. Both examples here show idft(DFT_REAL_OUTPUT). I need the phase information of the IDFT. So I used the DFT_COMPLEX_OUTPUT. But the phase information I receive is a lot different than the one I get from MATLAB. Can anyone help please?

    ReplyDelete
  3. What are the drawbacks of DFT when compared with the Feature based detections SIFT/SURF?

    ReplyDelete
  4. Thanks for your helpful post on Fourier Transform. Retail store owners who require an efficient POS software for day to day sales and inventory management operations may checkout TradeMeters retail point of sale software which is suitable for many different types of stores. This retail POS Software can be used as a jewelry store point of sale software as well.

    ReplyDelete
  5. افضل شركة رش مبيدات بالرياض
    الصفرات لرش المبيدات
    شركة الصفرات لرش المبيدات بالرياض

    ReplyDelete
  6. Good Post, I am a big believer in posting comments on sites to let the blog writers know that they ve added something advantageous to the world wide web.
    Block Chain Training in BangaloreBlock Chain Training in tambaram

    Block Chain Training in chennai

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.


    rpa training in Chennai | rpa training in velachery

    rpa training in tambaram | rpa training in sholinganallur


    ReplyDelete
  9. Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!
    Data Science training in kalyan nagar | Data Science training in OMR
    Data Science training in chennai | Data science training in velachery
    Data science training in tambaram | Data science training in jaya nagar

    ReplyDelete
  10. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.
    java training in chennai | java training in bangalore

    java online training | java training in pune

    ReplyDelete
  11. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

    ReplyDelete
  12. This is such a great post, and was thinking much the same myself. Another great update.
    Best Devops Training in pune
    Devops Training in Chennai

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. I am obliged to you for sharing this piece of information here and updating us with your resourceful guidance. Hope this might benefit many learners. Keep sharing this gainful articles and continue updating us.
    Angular 6 training in Chennai
    Angularjs courses in Chennai
    Angular Training in Chennai
    Best Angularjs training in chennai
    DevOps certification course
    DevOps Training institute
    DevOps Training near me

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. I would assume that we use more than the eyes to gauge a person's feelings. Mouth. Body language. Even voice. You could at least have given us a face in this test.
    devops online training

    aws online training

    data science with python online training

    data science online training

    rpa online training

    ReplyDelete
  17. I like your explanation of topic and ability to do work.I really found your post very interesting .
    www.webroot.com/safe |
    Webroot geek squad

    ReplyDelete
  18. Thank you so much for sharing this post, I appreciate your work.
    Avast customer service |Brother printer support

    ReplyDelete

  19. Excellent Post as always and you have a great post and i like it thank you for sharing


    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร Gclub กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> goldenslot
    สนใจร่วมลงทุนกับเรา สมัครเอเย่น Gclub คลิ๊กได้เลย

    ReplyDelete
  20. Brother printers are one of the well known brands all over the world.Brother Printers offers versatility, reliability, fast printing speed, scalability, upgradability and many other features. Though people are facing technical issues. Reach our Brother printer customer support team for Brother printer related issues. Our professional technicians will be available 24/7 for proper support.

    ReplyDelete
  21. Quickbooks enterprise support Phone number
    Get 24-hour support for corporate Quickbooks by contacting the QuickBooks Enterprise support phone number. We are ready to solve the QuickBooks Enterprise problems through a certified QuickBooks Enterprise support group. Call our Quickbooks support team at +1 (833) 400-1001 and contact our certified QuickBooks specialist for help.

    ReplyDelete
  22. Quickbooks enterprise support number
    +1 (833) 400-1001 is available to solve QuickBooks Enterprise problems through QuickBooks Enterprise support. Call our Quickbooks support team at +1 (833) 400-1001 and contact our certified QuickBooks specialist for help.

    ReplyDelete
  23. If you get into any issue related to Brother printers, dial the toll-free number and connects with the team of Brother printer support number. The technicians will always be happy to assist you with best and effective solutions.

    Dell printer support | Epson printer support

    ReplyDelete
  24. A dell printer user needs to update his computer or Laptop duly, but even after updating the system, the user faces the same problem, he needs to install Dell Driver Download suppport just by call on dell printer toll free number. After the installation, the user is able to print the documents perfectly.

    ReplyDelete
  25. I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog.

    norton.com/setup

    norton.com/setup

    norton.com/setup

    office.com/setup

    roadrunner email

    mcafee.com/activate

    aol mail

    ReplyDelete
  26. A majority of users encounters issues which need assistance for resolving it. In this case, dial the toll-free number of Epson printer toll free number and get 24/7 service from the professionals.

    Epson printer support
    Epson printer support number

    ReplyDelete
  27. HP printer support number always available to assist you and help you in delivering printing projects within a specific time. Dial the toll-free number of HP printer customer support and avail benefits from the service team.

    Hp printer toll free number | Hp printer support

    ReplyDelete
  28. HP printer support is active helpline that is available round the clock to resolve Hp printer problems. If you face any problem with your printer like device is not working properly, paper jamming issue, cable wire problem and others then reach experts of HP Printer Support and get instant help.

    ReplyDelete
  29. Brother is one of the highly preferred and top most electronic firms which are highly popularized for the manufacturing of printers. Brother Printer Support is active helpline that is available round the clock to resolve Canon printer problems. If you face any problem with your printer like, Brother Printer not Printing Anything, cable wire problem and others then reach experts of Brother Printer Support and get instant help.

    ReplyDelete
  30. This comment has been removed by the author.

    ReplyDelete
  31. drive
    We are an MRO parts supplier with a very large inventory. We ship parts to all the countries in the world, usually by DHL AIR. You are suggested to make payments online. And we will send you the tracking number once the order is shipped.

    ReplyDelete
  32. Halo,I'm Helena Julio from Ecuador,I want to talk good about Le_Meridian Funding Investors on this topic.Le_Meridian Funding Investors gives me financial support when all bank in my city turned down my request to grant me a loan of 500,000.00 USD, I tried all i could to get a loan from my banks here in Ecuador but they all turned me down because my credit was low but with god grace I came to know about Le_Meridian so I decided to give a try to apply for the loan. with God willing they grant me  loan of 500,000.00 USD the loan request that my banks here in Ecuador has turned me down for, it was really awesome doing business with them and my business is going well now. Here is Le_Meridian Funding Investment Email/WhatsApp Contact if you wish to apply loan from them.Email:lfdsloans@lemeridianfds.com / lfdsloans@outlook.comWhatsApp Contact:+1-989-394-3740.

    ReplyDelete
  33. Due to its hull shape, it is comparatively easy to maneuver in water and perfect for beginners. Despite of its weight of 57 pounds,

    Ocean Kayak Frenzy

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. Webroot is a Powerful, lightweight, integrated protection for PC, Mac and Android, cloud-based Webroot Internet Security Complete with antivirus protects personal information
    by blocking the latest malware, phishing, and cyber-attacks.
    www.webroot.com/secure | webroot.com/secure | Install Webroot With Key Code

    ReplyDelete
  36. شركة الروضه للخدمات العامه هي من افضل الشركات في مجال التنظيف ومنها تنظيف الخزانات والمنازل وغيرها 0550070836
    شركة تنظيف خزانات بالرياض

    ومن اهم خدمات شركة الروضه تنظيف المكيفات الأسبلت والشباك بأفضل الطرق والمعدات
    شركة تنظيف مكيفات بالرياض

    وايضا متخصصين في مجال فك وغرف النوم والمطابخ بالرياض
    شركة تركيب غرف نوم بالرياض

    ومن اهم خدمات شركة الروضه تنظيف المجالس والكنب والفرشات وغيرها
    شركة تنظيف مجالس بالرياض

    وايضا من اهم خدمات شركة الروضه تسليك المجاري وشفط البيارات بأحدث المعدات والأجهزه
    شركة تسليك مجاري بالرياض
    وايضا متخصصين في مجال تنظيف الشقق والفلل والقصور وغيرها
    شركة تنظيف شقق بالرياض
    وايضا لدنيا خدمة فك وتركيب المكيفات
    شركة فك وتركيب مكيفات بالرياض

    ReplyDelete
  37. We develop free teaching aids for parents and educators to teach English to pre-school children. For more info please visit here: English for children

    ReplyDelete



  38. AVG Secure is designed to keep your digital info safe and secure. Learn about its pricing, security features, and more in this review.
    avg.com/retail | AVG Download www.avg.com/activation | Install AVG with license number

    ReplyDelete
  39. The Fourier transform is an image which is consist of many components through which two dimensional images are formed.

    ReplyDelete
  40. During my college days i used these examples to learn programming.office.com/setup

    ReplyDelete
  41. The Discrete Fourier Transform (DFT) is of paramount importance in all areas of digital signal processing. It is used to derive a frequency-domain.Thanks for sharing a informative and useful post.

    ReplyDelete
  42. it’s a unique opportunity to showcase its technology to thousands of event professionals If the company is to be the go to provider of AI powered digital experiences. event marketing and free online registration for events

    ReplyDelete
  43. Hope you guys are well and healthy during this time. Guys if you want to utilise your time to do something interesting then we are here for you. Our institution is offering CS executive classes and free CSEET classes only for you guys. So contact us or visit our website at https://uniqueacademyforcommerce.com/

    ReplyDelete
  44. I was very happy to find this site. I would like to thank you for this special reading. Thank you very much
    wordpress Casino
    ufa88kh.blogspot Casino
    youtube Casino
    បាការ៉ាត់អនឡាញ

    ReplyDelete
  45. AximTrade Review Offers A Safe And Secure Platform To Do Forex Trading And CFDs And Our Customer Support Is Ready To Help You 24/7. You Can Easily Sign Up Your Aximtrade Login Account Here.

    ReplyDelete
  46. Really great article, is a pleasure to read this article. It is very informative for us. Thanks for posting

    I give you a better option in many printers as a canon printer. So how it works and what are the configuration to installing the printer please us below - http//ij.start.canon

    ReplyDelete
  47. Nice blog, informative content. I really enjoyed while reading this blog. I bookmarked your site for further reads. Keep sharing more.
    Data Science Course Training in Hyderabad
    Data Science Certification in Hyderabad

    ReplyDelete
  48. Make deposits to your Doge Wallet using more than 100 cryptocurrency. These will be converted into DOGE immediately.capital One Login
    american express login
    ethereum wallet
    gemini exchange
    blockchain wallet

    ReplyDelete
  49. You can earn DOGE for free via faucets, a special website. You can earn Dogecoins when you play games, completing simple tasks such as watching ads and downloading mobile apps. It is important to note that you will not earn a lot performing these tasks, and the amount you earn will be very tiny. Beware that there are lots of fake websites that could scam you to take your cash or confidential information.robinhood crypto wallet
    ronin wallet
    amazon.com/mytv
    amazon.com/code
    google play redeem code

    ReplyDelete
  50. Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download Now

    >>>>> Download Full

    Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download LINK

    >>>>> Download Now

    Learn Opencv By Examples: Discrete Fourier Transform >>>>> Download Full

    >>>>> Download LINK tM

    ReplyDelete
  51. Error in PayPal login passwordThis happens when you don't enter the correct login credentials at the sign-up page. To reset your password,Password to PayPalGo to https://sites.google.com/view/paypal-loginss/questions/faq1440 to learn how to regain access.

    starbucks gift card balance
    Play.google.com/redeem
    paypal sign in
    amazon.com code
    amazon code
    cash app login

    ReplyDelete
  52. This post is so useful and informative.Keep updating with more information.....
    Python Training In Bangalore
    Python Course In Bangalore

    ReplyDelete
  53. The best graphic design institute in Jaipur is Creative web pixel. Creative web pixel is having the best web designing courses in Jaipur. In a graphic design course, we provide classes from basics to advance level. We are providing the classes of the courses that come under graphic design. You can learn the course according to your interest.

    ReplyDelete
  54. Hii
    We obtained valuable information from this article. Your consistent production of similar articles is highly encouraged. I look forward to reading every piece you write in the future. Thank you for providing insightful content!
    Here is sharing some OTM Training information may be its helpful to you.
    OTM Training

    ReplyDelete
  55. what a blog on Microsoft Azura. Detailed discussion can be seen. Keep it up.

    We also provide various professional software courses.
    https//.sclinbio.com.

    ReplyDelete
  56. Maxx TV offers various Tamil channels in Australia, connecting the Tamil diaspora to their culture with diverse programs, movies, and shows.

    ReplyDelete