我的函数的输出与conv2()的输出不同 [英] My function's output differs from conv2() output

查看:70
本文介绍了我的函数的输出与conv2()的输出不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我编写的使用x方向Sobel蒙版对图像进行卷积的代码.该函数输入灰度图像以及要进行卷积的内核.但是,与从内置conv2()函数获得的结果相比,我得到的结果有所不同.这是为什么?我在做什么错了?

Below is the code I have written to convolve an image with a x-direction Sobel mask. The function inputs a gray-scale image along with a kernel to be convolved with. However, the result I am getting is different compared to the result I get from the built-in conv2() function. Why is that? What am I doing wrong?

这是我函数的输出:

这是conv2()输出:

Here's conv2() output:

推荐答案

您正在计算相关性.2D卷积是内核的180度旋转(翻转两个轴).

You are computing the correlation. The 2D convolution is a 180 degree rotation (flip both axes) of the kernel.

h = rot90(h,2);

您不会注意到使用对称滤波器(例如高斯或平均核)的差异,但是导数将在两个方向上都相反.

You won't notice the difference with a symmetric filter, like a Gaussian or an averaging kernel, but a derivative will be reversed in both directions.

这篇关于我的函数的输出与conv2()的输出不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆