惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
DataBreaches.Net
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
F
Full Disclosure
V2EX - 技术
V2EX - 技术
N
News and Events Feed by Topic
Help Net Security
Help Net Security
L
LangChain Blog
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
Google Online Security Blog
Google Online Security Blog
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
B
Blog RSS Feed
N
Netflix TechBlog - Medium
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Vulnerabilities – Threatpost
B
Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
I
Intezer
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园_首页
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
AI
AI
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cyberwarzone
Cyberwarzone
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
G
GRAHAM CLULEY
Vercel News
Vercel News
罗磊的独立博客
MyScale Blog
MyScale Blog
Last Week in AI
Last Week in AI
博客园 - 司徒正美
C
CERT Recently Published Vulnerability Notes
GbyAI
GbyAI
Scott Helme
Scott Helme
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
A
About on SuperTechFans
P
Privacy International News Feed

博客园 - 凤凰_1

多边形近似:最小周长多边形算法MPP 多阈值otsu的opencv实现 在Opencv中自定义了一个相位函数,获取复数矩阵的相位 cvIsInf与cvIsNan函数 Mandelbrot set 以parallel_for_实现 opencv的并行操作parallel_for_的问题 CV_WRAP和CV_EXPORTS_W opencv超级像素示例 opencv中自定义的双线性二次插值的图像旋转及缩放 在Qt中,如何在sheets末端添加新的sheet opencv4.x 中的plot函数绘制二维Mat C++版DNN最简主体框架 C++版全连接神经网络 C++版加载MNIST图像集合 C++版的神经网络训练用的图像集合加载 c\c++宏定义,四个参数求最大值 - 凤凰_1 - 博客园 自定义c++二维动态数组 用Cmake 编译OpenCV常见的错误 C++仿Matlab的bsxfun函数
Opencv中的dft()和idft()示例
凤凰_1 · 2021-06-05 · via 博客园 - 凤凰_1

傅里叶变换的公式,大家脑部,本实例是先将一副图像做傅里叶变换,再对傅里叶阵列做逆变换,代码如下:

#include <iostream>
#include<opencv2/opencv.hpp>

using namespace cv;
using namespace std;

void dftshift(Mat& ds)
{
    int cx=ds.cols/2;//图像的中心点x坐标
    int cy=ds.rows/2;//图像的中心点y坐标
    Mat q0=ds(Rect(0,0,cx,cy));//左上
    Mat q1=ds(Rect(cx,0,cx,cy));//右上
    Mat q2=ds(Rect(0,cy,cx,cy));//左下
    Mat q3=ds(Rect(cx,cy,cx,cy));//右下

    Mat tmp;
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);

    q1.copyTo(tmp);
    q2.copyTo(q1);
    tmp.copyTo(q2);
}

void myimshow(const Mat& complexImg)
{
    Mat mag;
    //对复数图像计算幅值
    Mat planes[2];
    split(complexImg,planes);
    magnitude(planes[0],planes[1],mag);
    //对幅值去对数log
    Mat mag_log;
    mag +=Scalar::all(1);
    cv::log(mag,mag_log);
    //对幅值图像做归一化处理
    Mat mag_norm;
    cv::normalize(mag_log,mag_norm,0,1,CV_MINMAX);
    imshow("dft magnitud",mag_norm);
}
void myimshow2(const Mat& complexImg)
{
    Mat mag;
    //对复数图像计算幅值
    Mat planes[2];
    split(complexImg,planes);
    magnitude(planes[0],planes[1],mag);
    normalize(mag,mag,1,0,CV_MINMAX);
    imshow("inverce dft magnitud",mag);
}
int main()
{
    //1.读入灰度图像,不要读入彩色图像
    //  Mat img=imread("D:/Qt/MyImage/baboon.jpg",0);
    Mat img=Mat::zeros(300,300,CV_32F);//定义输入图像的实部300×300的0矩阵,
    //单通道。也可以从外部读入一灰度图像。
    //下面一行语句,在图像中央6×6Rect区域赋值为1
    img(Rect(img.cols/2-3,img.rows/2-3,6,6))=Scalar::all(1);

    imshow("original image",img);
    //2.将单通道图像转换成双通道图像
    Mat img2;
    img.convertTo(img2,CV_32FC2);
    //3.调用dft函数实现傅里叶变换
    Mat img_dft;
    dft(img2,img_dft,DFT_COMPLEX_OUTPUT);
    //4.显示傅里叶频谱图
    dftshift(img_dft);//傅里叶普的中心化
    myimshow(img_dft);
    //5.调用idft()函数,执行逆傅里叶变换
    Mat iimg;
    idft(img_dft,iimg);
    myimshow2(iimg);
    waitKey();
    return 0;
}

运行结果如下,左图是原图像,中间是频谱图,右边是经逆傅里叶变换得到复原图像: