Discrete Fourier Transform
来源:互联网 发布:管理系统常用算法 编辑:程序博客网 时间:2024/06/05 16:39
#include "opencv2/core/core.hpp"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/highgui/highgui.hpp"#include <iostream>int main(int argc, char ** argv){ const char* filename = argc >=2 ? argv[1] : "lena.jpg"; Mat I = imread(filename, CV_LOAD_IMAGE_GRAYSCALE); if( I.empty()) return -1; Mat padded; //expand input image to optimal size int m = getOptimalDFTSize( I.rows ); int n = getOptimalDFTSize( I.cols ); // on the border add zero values copyMakeBorder(I, padded, 0, m - I.rows, 0, n - I.cols, BORDER_CONSTANT, Scalar::all(0)); Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)}; Mat complexI; merge(planes, 2, complexI); // Add to the expanded another plane with zeros dft(complexI, complexI); // this way the result may fit in the source matrix // compute the magnitude and switch to logarithmic scale // => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2)) split(complexI, planes); // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I)) magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude Mat magI = planes[0]; magI += Scalar::all(1); // switch to logarithmic scale log(magI, magI); // crop the spectrum, if it has an odd number of rows or columns magI = magI(Rect(0, 0, magI.cols & -2, magI.rows & -2)); // rearrange the quadrants of Fourier image so that the origin is at the image center int cx = magI.cols/2; int cy = magI.rows/2; Mat q0(magI, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant Mat q1(magI, Rect(cx, 0, cx, cy)); // Top-Right Mat q2(magI, Rect(0, cy, cx, cy)); // Bottom-Left Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right Mat tmp; // swap quadrants (Top-Left with Bottom-Right) q0.copyTo(tmp); q3.copyTo(q0); tmp.copyTo(q3); q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left) q2.copyTo(q1); tmp.copyTo(q2); normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a // viewable image form (float between values 0 and 1). imshow("Input Image" , I ); // Show the result imshow("spectrum magnitude", magI); waitKey(); return 0;}
阅读全文
0 0
- Discrete Fourier Transform
- Discrete Fourier Transform
- Discrete Fourier Transform
- Explained: The Discrete Fourier Transform
- FFT (Fast Fourier Transform) 与 DFT (Discrete Fourier Transform)
- FFT (Fast Fourier Transform) 与 DFT (Discrete Fourier Transform)
- 离散傅立叶变换(Discrete Fourier Transform)
- 离散傅里叶变换 The Discrete Fourier Transform (DFT)
- Fourier Transform
- Fourier Transform
- Fourier Transform
- Fourier Transform
- 【翻译】Fast Fourier Transform
- Fast Fourier Transform
- Fast Fourier Transform
- XTOJ1250Super Fast Fourier Transform
- 傅立葉轉換(Fourier Transform)
- Short-Time Fourier Transform
- JobControl的使用及获取计数器
- JSP程序的运行机制
- 如何判断一棵树是不是另一棵树的子树
- eclipse-maven3-plugin.7z
- C语言的数组和指针_《C专家编程》读书笔记
- Discrete Fourier Transform
- [SDUT](2116)数据结构实验之链表一:顺序建立链表 ---链式存储(线性表)
- ps:将某个时间点的进程运行情况选…
- 欢迎使用CSDN-markdown编辑器
- linux系统资源的查看free、uname
- JS原型与原型链终极详解
- mongodb 安全防护策略
- 55个Linux系统管理中常用的一些she…
- linux 通过哪个命令可以查看…