Discrete Fourier Transform (Discrete Fourier Transform)

Source: Internet
Author: User

Core functions:

Cvdft

Program:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/45/D3/wKiom1PsKPaAobomAAEVHN4ETFs812.jpg "Title =" clipboard.png "alt =" wkiom1pskpaaobomaaevhn4etfs812.jpg "/>

Code:

# Include "CV. H "# include" cxcore. H "# include" highgui. H "# include <iostream> int DFT (INT argc, char ** argv) // Discrete Fourier Transform (discrete Fourier transform, abbreviated as DFT) {iplimage * src = cvloadimage ("E: \ picture \ 4.jpg", 0); iplimage * src32f = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1 ); iplimage * src32f_one = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1); iplimage * dst32f = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1 ); iplimage * dst32f_one = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1); iplimage * dst2_32f = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1 ); iplimage * dst2_32f_one = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1); iplimage * src232f = cvcreateimage (cvgetsize (SRC), ipl_depth_32f, 1 ); iplimage * DST = cvcreateimage (cvgetsize (SRC), 8, 1); iplimage * src2 = cvcreateimage (cvgetsize (SRC), 8, 1); cvzero (src32f); cvzero (dst32f ); // convert uchar to the 32f type for normalization and calculation conversion cvconvertscale (SRC, src32f); // normalization process [0,255] Double minval = 0; double maxval = 0; cvminmaxloc (src32f, & minval, & maxval); double min = minval; double max = maxval; double scale = 255/(maxval-minval); double shift =-minval * scale; cvconvertscale (src32f, src32f_one, scale, shift); cvminmaxloc (src32f_one, & minval, & maxval); STD: cout <minval <maxval <STD: Endl; // Fourier transform cvdft (src32f_one, dst32f, cv_dxt_forward); // normalize the Fourier transform results [0,255] minval = 0; maxval = 0; cvminmaxloc (dst32f, & minval, & maxval); Scale = 255/(maxval-minval); shift =-minval * scale; cvconvertscale (dst32f, dst32f_one, scale, shift ); // convert the normalized Fourier Transformation Result to eight bits to display cvconvertscale (dst32f_one, DST); cvminmaxloc (dst32f_one, & minval, & maxval); STD :: cout <"def result minval:" <minval <"maxval:" <maxval <STD: Endl; // Fourier inverse cvdft (dst32f, dst2_32f, cv_dxt_inverse); // normalized Fourier inverse transformation result [0,255] minval = 0; maxval = 0; cvminmaxloc (dst2_32f, & minval, & maxval ); scale = 255/(maxval-minval); shift =-minval * scale; cvconvertscale (dst2_32f, dst2_32f_one, scale, shift); // restore the source image, inverse normalization scale = (max-min)/255; // normalization is first multiplied and then added, and restoration is first added and then multiplied, so shift must be equal to Min rather than min * scaleshift = min; cvconvertscale (dst2_32f_one, src232f, scale, shift); // convert the restored image to an 8-bit cvconvertscale (src232f, src2); cvnamedwindow ("src "); cvnamedwindow ("DST"); cvnamedwindow ("src2"); cvshowimage ("src", Src); cvshowimage ("DST", DST); cvshowimage ("src2 ", src2); cvwaitkey (0); cvdestroywindow ("src"); cvdestroywindow ("DST"); cvdestroywindow ("src2"); cvreleaseimage (& SRC ); cvreleaseimage (& DST); cvreleaseimage (& src32f); cvreleaseimage (& dst32f); cvreleaseimage (& src2); cvreleaseimage (& src32f_one); cvreleaseimage (& dst32f_one ); cvreleaseimage (& dst2_32f_one); Return 0 ;}


This article is from the "flyclc" blog, please be sure to keep this source http://flyclc.blog.51cto.com/1385758/1539811

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.