Opencv 例程讲解7 ---- DFT图像傅立叶变换

本文介绍了OpenCV中DFT(离散傅立叶变换)的使用,阐述了如何通过DFT将图像转换到频域进行高通和低通滤波。还提及了opencv的idft函数用于逆变换,并讨论了dft和idft的函数原型。文章通过实例展示了傅立叶变换在确定图像旋转角度的应用,以及如何通过阈值处理增强观察效果。
摘要由CSDN通过智能技术生成

     这次介绍下opencv中DFT的使用,对应的例程是(EXAMPLE) dft。在图像处理领域,通过DFT可以将图像转换到频域,实现高通和低通滤波;还可以利用矩阵的卷积运算等同于其在频域的乘法运算从而优化算法降低运算量, 即先将图像转换到频域,然后做完乘法运算后,再转换到图像域,opencv中的模板匹配就利用了这一特性降低运算量。

下面是dft例程的源码

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <stdio.h>

using namespace cv;
using namespace std;

static void help()
{
    printf("\nThis program demonstrated the use of the discrete Fourier transform (dft)\n"
           "The dft of an image is taken and it's power spectrum is displayed.\n"
           "Usage:\n"
            "./dft [image_name -- default lena.jpg]\n");
}

const char* keys =
{
    "{1| |lena.jpg|input image file}"
};

int main(int argc, const char ** argv)
{
    help();
    CommandLineParser parser(argc, argv, keys);        // opencv中用来处理命令行参数的类
    string filename = parser.get<string>("1");

    Mat img = imread(filename.c_str(), CV_LOAD_IMAGE_GRAYSCALE);    //以灰度图像读入
    if( img.empty() )
    {
        help();
        printf("Cannot read image file: %s\n", filename.c_str());
        return -1;
    }
    int M = getOptimalDFTSize( img.rows );                               // 获得最佳DFT尺寸,为2的次方
    i
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值