opencv 笔记08Core_DFT
来源:互联网 发布:java自带的md5加密 编辑:程序博客网 时间:2024/06/09 16:47
任一函数都可以表示成无数个正弦和余弦函数的和的形式。傅立叶变换就是一个用来将函数分解的工具。 2维图像的傅立叶变换可以用以下数学公式表达:
操作过程:
将图像延扩到最佳尺寸. 离散傅立叶变换的运行速度与图片的尺寸息息相关。当图像的尺寸是2, 3,5的整数倍时,计算速度最快。 因此,为了达到快速计算的目的,经常通过添凑新的边缘像素的方法获取最佳图像尺寸。函数 getOptimalDFTSize() 返回最佳尺寸,而函数 copyMakeBorder() 填充边缘像素:
添加的像素初始化为0.
C++: void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() )
Parameters: - src – Source image.
- dst – Destination image of the same type as src and the size Size(src.cols+left+right,src.rows+top+bottom) .
- top –
- bottom –
- left –
- right – Parameter specifying how many pixels in each direction from the source image rectangle to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built.
- borderType – Border type. See borderInterpolate() for details.
- value – Border value if borderType==BORDER_CONSTANT .
为傅立叶变换的结果(实部和虚部)分配存储空间. 傅立叶变换的结果是复数,这就是说对于每个原图像值,结果是两个图像值。 此外,频域值范围远远超过空间值范围, 因此至少要将频域储存在 float 格式中。 结果我们将输入图像转换成浮点类型,并多加一个额外通道来储存复数部分:
- C++: void merge(const Mat* mv, size_t count, OutputArray dst)
- C++: void merge(InputArrayOfArrays mv, OutputArray dst
Parameters: - mv – input array or vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
- count – number of input matrices when mv is a plain C array; it must be greater than zero.
- dst – output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.
进行离散傅立叶变换. 支持图像原地计算 (输入输出为同一图像):
将复数转换为幅度.复数包含实数部分(Re)和复数部分 (imaginary - Im)。 离散傅立叶变换的结果是复数,对应的幅度可以表示为:
转化为OpenCV代码:
对数尺度(logarithmic scale)缩放. 傅立叶变换的幅度值范围大到不适合在屏幕上显示。高值在屏幕上显示为白点,而低值为黑点,高低值的变化无法有效分辨。为了在屏幕上凸显出高低变化的连续性,我们可以用对数尺度来替换线性尺度:
转化为OpenCV代码:
剪切和重分布幅度图象限. 还记得我们在第一步时延扩了图像吗? 那现在是时候将新添加的像素剔除了。为了方便显示,我们也可以重新分布幅度图象限位置(注:将第五步得到的幅度图从中间划开得到四张1/4子图像,将每张子图像看成幅度图的一个象限,重新分布即将四个角点重叠到图片中心)。 这样的话原点(0,0)就位移到图像中心。
归一化. 这一步的目的仍然是为了显示。 现在我们有了重分布后的幅度图,但是幅度值仍然超过可显示范围[0,1] 。我们使用 normalize() 函数将幅度归一化到可显示范围。
C++: void normalize(InputArray src, OutputArray dst, double alpha=1, double beta=0, int norm_type=NORM_L2, int dtype=-1, InputArray mask=noArray() )
- src – input array.
- dst – output array of the same size as src .
- alpha – norm value to normalize to or the lower range boundary in case of the range normalization.
- beta – upper range boundary in case of the range normalization; it is not used for the norm normalization.
- normType – normalization type (see the details below).
- dtype – when negative, the output array has the same type as src; otherwise, it has the same number of channels as src and the depth =CV_MAT_DEPTH(dtype).
- mask – optional operation mask.
The functions normalize scale and shift the input array elements so that
(where p=Inf, 1 or 2) when normType=NORM_INF, NORM_L1, or NORM_L2, respectively; or so that
- opencv 笔记08Core_DFT
- OpenCV笔记
- openCV笔记
- OpenCV笔记
- OpenCV笔记
- opencv笔记
- Opencv笔记
- opencv 笔记
- opencv笔记
- opencv笔记
- opencv笔记
- OpenCV--笔记
- opencv笔记
- OpenCV笔记
- OpenCV笔记
- OpenCV笔记
- OpenCV学习笔记08--细说HighGUI
- OpenCV学习笔记
- LightOJ 1245 求(n/1+n/2+...+n/n)
- 中国人和美国人在求偶标准上的根本不同....
- 王寒:12岁儿童,该怎样开始iOS开发?
- 黑马程序员java高新技术篇----小知识点总结
- 创建和使用分区的表
- opencv 笔记08Core_DFT
- IOS 委托小例
- spring MVC控制层跳转到另一个目录下的页面
- IBM.Rational.Rose.Enterprise.v7.0 下载
- 几个iPhone开发网站、论坛、博客
- 推荐 15 款很棒的文本编辑器
- Oracle数据库的空间管理技巧
- python爬虫
- Oracle数据转储时字符集的转换规律