[CLPR] 卷积还是相关? - Opencv之filter2D探究
I am doing something about convolving images in Python and for sake of speed I chose opencv 2.4.9.
Opencv offers a way called filter2D to do this and here's its docs:http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=filter2d#filter2d
In docs, it says:
Convolves an image with the kernel.
But I have doubts(caused by something else) so I make some experiments on it:
First, I make a normal 3x3 matrix a using numpy as:
[[ 1., 5., 0.],
[ 7., 2., 9.],
[ 2., 3., 4.]]
Then, I make a 2x2 matrix b as the cornel as:
>>> b
[[ 1., 2.],
[ 3., 4.]]
Finally, in order to make it clear to see difference between convolve and correlate, rotate b by 180 degree and b will look like:
[[ 4., 3.],
[ 2., 1.]]
Now, All pre-work is done. We could begin the experiment.
Step 1. Use scipy.ndimage.convolve: ndconv = ndimage.convolve(a, b, mode = 'constant')
and ndconv is:
[[ 35., 33., 18.],
[ 41., 45., 44.],
[ 17., 24., 16.]]
Convolution op will rotate b by 180 degree and do correlation using b on a. So ndconv[0][0] = 4*1+3*5+2*7+1*2 = 35, and ndconv[2][2] = 4*4+3*0+2*0+1*0 = 16
This result is correct.
Step 2. Use scipy.ndimage.correlate: ndcorr = ndimage.correlate(a, b, mode = 'constant')
and ndcorr is:
[[ 4., 23., 15.],
[ 30., 40., 47.],
[ 22., 29., 45.]]
According to correlation's definition, ndcorr[0][0] = 1*0+2*0+3*0+4*1 = 4 because the border will expand by 0.
(Someone may be confused by the expandation's difference between conv and corr. It seems convolveexpand image in directions right and down while correlate in directions left and up.)
But this is not the point.
Step 3. Use cv2.filter2D: cvfilter = cv2.filter2D(a, -1, b)
and cvfilter is:
[[ 35., 34., 35.],
[ 41., 40., 47.],
[ 33., 29., 45.]]
If we ignore the border cases, we will find that what cv2.filter2D did is actually a correlation other than aconvolution! How could I say that?
because cvfilter[1..2][1..2] == ndcorr[1..2][1..2].
WEIRD, isn't it?
Could anyone be able to tell the real thing that cv2.filter2D do? Thanks a lot.
[CLPR] 卷积还是相关? - Opencv之filter2D探究的更多相关文章
- (原)使用intel的ipp库计算卷积及相关
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5462631.html 参考网址: https://software.intel.com/zh-cn/n ...
- 图像卷积、相关以及在MATLAB中的操作
图像卷积.相关以及在MATLAB中的操作 2016年7月11日 20:34:35, By ChrisZZ 区分卷积和相关 图像处理中常常需要用一个滤波器做空间滤波操作.空间滤波操作有时候也被叫做卷积滤 ...
- [CLPR] 卷积神经网络的结构
本文翻译自: http://www.codeproject.com/Articles/16650/Neural-Network-for-Recognition-of-Handwritten-Digi ...
- 相关与卷积(数字信号处理)的数学原理及 Python 实现
数学原理 在数字信号处理中,相关(correlation)可以分为互相关(cross correlation)和自相关(auto-correlation). 互相关是两个数字序列之间的运算:自相关是单 ...
- opencv:图像卷积
卷积基本概念 C++代码实现卷积 #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; u ...
- 13、OpenCV实现图像的空间滤波——图像平滑
1.空间滤波基础概念 1.空间滤波基础 空间滤波一词中滤波取自数字信号处理,指接受或拒绝一定的频率成分,但是空间滤波学习内容实际上和通过傅里叶变换实现的频域的滤波是等效的,故而也称为滤波.空间滤波主要 ...
- OpenCV图像处理与视频分析详解
1.OpenCV4环境搭建 VS2017新建一个控制台项目 配置包含目录 配置库目录 配置链接器 配置环境变量 重新启动VS2017 2.第一个图像显示程序 main.cpp #include< ...
- opencv笔记4:模板运算和常见滤波操作
time:2015年10月04日 星期日 00时00分27秒 # opencv笔记4:模板运算和常见滤波操作 这一篇主要是学习模板运算,了解各种模板运算的运算过程和分类,理论方面主要参考<图像工 ...
- SSE图像算法优化系列十一:使用FFT变换实现图像卷积。
本文重点主要不在于FFT的SSE优化,而在于使用FFT实现快速卷积的相关技巧和过程. 关于FFT变换,有很多参考的代码,特别是对于长度为2的整数次幂的序列,实现起来也是非常简易的,而对于非2次幂的序列 ...
随机推荐
- 『Python』图像金字塔、滑动窗口和非极大值抑制实现
图像金字塔 1.在从cv2.resize中,传入参数时先列后行的 2.使用了python中的生成器,调用时使用for i in pyramid即可 3.scaleFactor是缩放因子,需要保证缩放后 ...
- arcTo
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- Mysql 中Left/Right join on后面and和where条件查询的差异-Mysql SQL运算符是有优先级
一.Mysql中Left/Right join on后面and和where条件查询的差异 1.建两张测试表,一张商户定义表.一张商户操作状态明细表 1)商户定义表 CREATE TABLE hope. ...
- 为何 Delphi的 Local Variables 突然没有值显示了
可能是上次编译后 code未再修改过. 试试 随便 输入一个空格,然后F9
- python 加密 解密 签名 验证签名 公钥 私钥 非对称加密 RSA
加密与解密,这很重要,我们已经可以用pypcap+npcap简单嗅探到网络中的数据包了.而这个工具其实可以嗅探到更多的数据.如果我们和别人之间传输的数据被别人嗅探到,那么信息泄漏,信息被篡改,将给我们 ...
- ESET免费申请
Eset 免费试用30天申请地址 http://www.comss.info/list.php?c=NOD32 https://secure.eset.ie/msv/evaluate/evaluate ...
- HDU 3998
http://acm.hdu.edu.cn/showproblem.php?pid=3998 求LIS的长度,并且求有多少组互不相交的LIS 求组数用最大流 建图如下: if(dp[i]==1)add ...
- 按照Right-BICEP要求设计四则运算2程序的单元测试用例
Right——结果是否正确? B——是否所有的边界条件都是正确的? I——能查一下反响关联吗? C——能用其它手段交叉检查一下吗? E——你是否可以强制错误条件发生? P——是否满足性能要求? 测试计 ...
- 第三篇 makefile的伪目标
我们来思考一下makefile中的目标究竟是什么?实际上,在默认情况下: 1.make将makefile的目标认为是一个文件: 2.make解释器比较目标文件和依赖文件的新旧关系,决定是否 ...
- vue2.0分页组件,
pagination.vue <!-- 表格分页组件 --> <template> <nav class="boot-nav"> <ul ...