opencv快速傅里叶变换实例
来源:互联网 发布:滨州行知中学 编辑:程序博客网 时间:2024/05/16 15:32
opencv快速傅里叶变换实例
int main(){ Mat I = imread("ted_cruz.jpg", CV_LOAD_IMAGE_GRAYSCALE); if (I.empty()) return -1; cout << I.size() << endl; 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)); cout << padded.size() << endl; 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;}
1 0
- opencv快速傅里叶变换实例
- opencv傅里叶变换实例
- opencv 中 快速傅里叶变换 FFT
- 快速傅里叶变换-快速傅里叶变换
- openCV-傅里叶变换
- opencv:傅里叶变换
- OpenCV傅里叶变换
- 【OpenCV】傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- 快速傅里叶变换
- Android 导入下载的Project缺少gradle文件处理办法
- PTAA-1043-Is It a Binary Search Tree (25)
- 【11月】Hey!English
- ECMA5Script执行环境和作用域
- LUA学习路线汇总
- opencv快速傅里叶变换实例
- 2016年12月9日学习笔记
- 动力节点——面向对象思想概述(五)
- A. Broken Clock
- VR系列——Oculus Audio sdk文档:六、FMOD Oculus Spatializer集成指南(1)——概述
- Android在64位系统上app如何导入32位库
- AndroidStudio 新手常遇到的错误以及解决办法
- log4j区分不同客户端产生的日志
- 解决VS2010在程序根目录生成ipch文件夹和.sdf格式文件问题以及右键查看变量申明和定义按钮变灰