Why do we need to flip the kernel in 2D convolution?

Why do we need to flip the kernel in 2D convolution in the first place? What's the benefit of this? So, why can't we leave it unflipped? What kind of terrible thing can happen if you don't flip it?
SEE: "First, flip the kernel, which is the shaded box, in both horizontal and vertical direction"

 採用された回答

Matt J
Matt J 2013 年 5 月 2 日
編集済み: Matt J 2013 年 5 月 2 日

1 投票

It's not meant to be a "benefit" or to avoid disastrous consequences. It's meant to be a definition. If you don't flip, then you violate the agreed upon definition of convolution. Convolution without the flip has a name of its own: correlation.
What motivated people to define convolution with a flip? Well in 1D, it means, for example that the convolution of causal signals will also be causal. Also, when you flip, then the convolution with an impulse response function of a system gives you the response of that system. If you don't flip, the response comes out backwards.
Why do the same in 2D? Using a different definition in 2D would make it inconsistent with 1D.

5 件のコメント

jon
jon 2013 年 5 月 2 日
編集済み: jon 2013 年 5 月 2 日
"when you flip, then the convolution with an impulse response function of a system gives you the response of that system. If you don't flip, the response comes out backwards." <- I can't image the response coming out backwards as a result of this...
"convolution of causal signals will also be causal" <- yeah, so, why is that important???
And btw. didn't 'the flip' had something to do with the Fourier transforms?
@IA: Wouldn't flipping symmetric kernels simply take more calculations, e.g. those here: http://en.wikipedia.org/wiki/Kernel_(image_processing)
Image Analyst
Image Analyst 2013 年 5 月 2 日
The time to flip in so miniscule it's inconsequential. If you go through the theory (linear systems theory) you'll understand. If you want to understand the causality, imagine a filter that's a right triangle, with the small pointy end on the left and the steep edge on the right. Now shift that past a delta function. If you don't flip and just start shifting your filter past it will hit the tall steep edge first and then ramp down. So then your response is opposite to your filter, but they must be the same if it's a delta function. Basically it's because time goes along the x axis with the small time values on the left and the big (later) time values on the right. So if you start shifting in, you're having the big time values hit your signal first, which is not right (causal). So you have to flip it to make the small time values shift in first. Not sure if that's such a great explanation but it's what I offer just off the top of my head.
Matt J
Matt J 2013 年 5 月 2 日
I can't image the response coming out backwards as a result of this...
Try it (with an asymmetric impulse response).
"convolution of causal signals will also be causal" <- yeah, so, why is that important???
It's just consistent with other things in linear systems theory. We know that the response of a causal system to a causal signal is supposed to be causal (by definition of a causal system). We also know that the response is supposed to be the convolution of the impulse response with that signal. For both to be true simultaneously, convolution must preserve causality.
And btw. didn't 'the flip' had something to do with the Fourier transforms?
That's another good way to make sense of the flip. If you multiply two spectra together and then apply an inverse Fourier transform, you will get the convolution (defined with flip) of the IFTs of the respective spectra.
taa199
taa199 2015 年 8 月 20 日
very good explaination
Vibhav Inna Kedege
Vibhav Inna Kedege 2020 年 5 月 11 日
very good explanation!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2013 年 5 月 2 日
編集済み: Image Analyst 2013 年 5 月 2 日

1 投票

It doesn't need to be flipped, at least not by you. You pass in the array and the flipping is done internally, automatically, because that's the definition of convolution. If it didn't flip, it would be correlation, not convolution. If you flipped it before passing it into conv2(), then you'd be doing a correlation instead of a convolution because the internal flip in counteracted by your advance manual flip. If you want, you can use imfilter() or xcorr2() which do no flip internally.

3 件のコメント

Adnan  Khan
Adnan Khan 2017 年 9 月 18 日
How flipping is done internally? though it is clear from the formula that it is done but how can we explain this in simple and concise words...
Image Analyst
Image Analyst 2017 年 9 月 18 日
Flip it left to right using fliplr(), then flip it top to bottom with flipud().
Webi Dabuse
Webi Dabuse 2020 年 9 月 29 日
Or you can just rotate it by 180 degrees. rot90(image,2)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSignal Processing Toolbox についてさらに検索

質問済み:

jon
2013 年 5 月 1 日

コメント済み:

2020 年 9 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by