OpenCV of Basic Learning Notes (15): Discrete Fourier transform

Source: Internet
Author: User
Tags arrays
OpenCV of Basic Learning Notes (15): Discrete Fourier transform

This paper mainly introduces how to use OPENCV to carry on the Fourier transform of the image, its core function is the DFT (OPENCV). The technique of DFT is to map the spatial domain to the frequency domain, which plays an important role in image processing. Here we just get the result of its transformation and see what the poor-domain graph has.

Development environment: opencv2.4.2+qt4.8.2+ubuntu12.04+qtcreator2.5

  experimental function:

Click the Open Image button to manually choose to open a picture, regardless of whether it is a color picture, where it is uniformly converted to grayscale image display, because the need to speed up the DfT operation.

Move the mouse to the picture display area, click the picture, then the DfT intermediate result graph is displayed, that is, the point of the low-frequency field is not moved to the center of the image. The displayed picture has a text hint.

Continuing to click on the image, the result graph of the DfT is displayed after the last re-layout, and there are also corresponding text hints.

When you continue to click on the picture, the original, DFT is not adjusted, the DfT adjustment Chart 3 pictures will be rotated display.

If you click in the picture display area without opening the picture, the appropriate hint text appears in the picture display area, prompting you to open the picture first.

  Experiment Description:

The DfT transformation formula for 1-dimensional discrete sequences is:

The DfT transformation formula for 2-D discrete matrices is:

Qtextbrowser How to do the mouse click event in the corresponding.

Use Qtextbrowser to display the picture (without displaying the text), and then click the picture to go to an image processing function (this is the discrete Fourier transform) when the picture is displayed, but in Qtextbrowser singal/ The corresponding mouse-click signal is not found in the slot. So you can only write the signal function, but corresponding to capture the mouse click on the library should have, then how to write it. There is a good article on the Internet: http://www.embedu.org/Column/Column421.htm

In the above article, I re-write a class Mytextbrowser, inherited from the base class Qtextbrowser, and then rewrite the mousepressevent function of the class, in fact, similar functions are provided by the system, a bit like the message response mechanism in MFC, A signal is sent in the function. When the mouse is pressed, a clicked () signal is emitted, and the slot function corresponding to the signal in the main interface is OK.

When you want to use the new Mytextbrowser class instead of the original qtextbrowser, just open the. UI design file, find the corresponding object in the object bar, and then right-click to enter promoted Widgets, Add a mytextbrwoser.

int getoptimaldftsize (int vecsize)

This function is designed to obtain the optimal size for DFT calculations. Because in the DFT, if need to calculate the number sequence length vecsize to 2 of the N power, then it runs very fast. If it is not the n power of 2, but can be decomposed into the product of 2,3,5, the operation speed is also very fast. The Getoptimaldftsize () function here is to obtain the smallest integer size that satisfies the decomposition into 2,3,5. Obviously, if a multi-dimensional matrix requires a DFT, then each dimension uses this function alone to obtain the best DFT size.

void Copymakeborder (Inuptarray src, outputarray dst, int top, int bottom, int left, int. right, int bordertype, const Scal ar& value=scalar ())

The function is used to extend the bounds of an image, the 3rd to 6th parameter is the number of pixels of each expanded pixel of the original image, the 7th parameter represents the type of the boundary, and if it is border_constant, the expanded boundary pixel value is initialized with the 8th parameter. The result of extending the SRC image to the boundary is saved in the DST image.

The merge () function is to concatenate multiple but channel arrays into 1 multi-channel arrays, while the split () function, in contrast, decomposes 1 multi-channel functions into multiple but channel functions.

Void magnitude (Inputarray x, Inputarray y, Outputarray magnitude)

The function is to calculate the square sum of squares of each pixel that the input matrix X and y pairs should have, after which the open root is saved in the output matrix magnitude.

The function log (Inputarray src, Outputarray DST) is a log for each pixel in the input matrix src, stored in the corresponding position of the output matrix DST.

Because the picture is displayed in Qt, if the image type is a luminance image, that is, its pixel value is between 0~1, then the image that is full black is displayed. So in order to appear normal in the picture, it must be enlarged by 255, so that it is between 0~255. Of course, if it is OpenCV's own imshow () function, for such a value between the 0~1 image it will automatically recognize, and there is a term called the luminance image.

  Experimental Results:

Open a picture and display it in grayscale as follows:

  

DFT Intermediate result graph, not rearranged effect:

  

The results of the DfT final arrangement:

  

  

If you do not have the picture open, click the picture display area, as follows:

  

The main part of the experiment Code and its comments (appendix has the Project code download link address):

MainWindo.cpp:

 #include" mainwindow.h "#include" ui_mainwindow.h "#include

<iostream> #include <QFileDialog> using namespace std;
    Mainwindow::mainwindow (Qwidget *parent): Qmainwindow (parent), UI (new Ui::mainwindow) {ui->setupui (this);

    Ui->textbrowser->setfont (Qfont ("Times New Roman", 30));
    Display_num = 0;
Qobject::connect (Ui->textbrowser, SIGNAL (clicked ()), this, SLOT (on_mytextbrowser_clicked ()));

} mainwindow::~mainwindow () {Delete UI;}  void mainwindow::on_openbutton_clicked () {/* reads the picture and displays it and reads it in grayscale */QString Img_name = Qfiledialog::getopenfilename ( This, "Open Image", ".. /dft ", tr (" Image Files (*.png *.jpg *.bmp *.jpeg) "

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.