DFT
发布日期:2021-11-07 18:53:25 浏览次数:2 分类:技术文章

本文共 1228 字,大约阅读时间需要 4 分钟。

#include 
#include
#include
using namespace std;using namespace cv;int main(){ string filename = "C:/Users/Administrator/Desktop/标准测试图片/dota/big432000.jpg"; Mat img = imread(filename, IMREAD_GRAYSCALE); if (img.empty()) { return -1; } int cols = getOptimalDFTSize(img.cols); int rows = getOptimalDFTSize(img.rows); //复制制作边界 Mat padded; copyMakeBorder(img, padded, 0, rows - img.rows, 0, cols - img.cols, BORDER_CONSTANT, Scalar::all(0)); Mat planes[] = { Mat_
(padded), Mat::zeros(padded.size(), CV_32F) }; //进行傅里叶变换 Mat ComplexImg; merge(planes,2, ComplexImg); dft(ComplexImg, ComplexImg); //log(x+1) 进行变换 split(ComplexImg, planes); magnitude(planes[0], planes[1], planes[0]); Mat mag = planes[0]; mag += Scalar::all(1); log(mag, mag); mag = mag(Rect(0, 0, mag.cols&-2, mag.rows&-2)); int cx = mag.cols / 2; int cy = mag.rows / 2; Mat temp; Mat q1 = mag(Rect(0, 0, cx, cy)); Mat q2 = mag(Rect(cx, 0, cx, cy)); Mat q3 = mag(Rect(0, cy, cx, cy)); Mat q4 = mag(Rect(cx, cy, cx, cy)); q1.copyTo(temp); q4.copyTo(q1); temp.copyTo(q4); q2.copyTo(temp); q3.copyTo(q2); temp.copyTo(q3); //归一化结果 normalize(mag,mag, 0, 1, NORM_MINMAX); //现在可以看看变换之后的结果 imshow("DFT", mag); waitKey(0); return 0;}

转载地址:https://blog.csdn.net/zhanggusheng/article/details/70207771 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:HOG+SVM
下一篇:opencv 的几种边界

发表评论

最新留言

很好
[***.229.124.182]2024年04月08日 03时18分34秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章