conv2() vs filter2()
filter2做的是相关correlation,conv2做的是卷积convolution,卷积是会将模板翻转,而相关不会,具体看下面的例子
a = magic(5)a =17 24 1 8 1523 5 7 14 164 6 13 20 2210 12 19 21 311 18 25 2 9g = [0 0; 0 1];filter2(g,a,'full')ans =17 24 1 8 15 023 5 7 14 16 04 6 13 20 22 010 12 19 21 3 011 18 25 2 9 00 0 0 0 0 0filter2(g,a,'valid')ans =5 7 14 166 13 20 2212 19 21 318 25 2 9f = [1 0; 0 0]; %翻转后的模板filter2(f,a,'full')ans =0 0 0 0 0 00 17 24 1 8 150 23 5 7 14 160 4 6 13 20 220 10 12 19 21 30 11 18 25 2 9filter2(f,a,'valid')ans =17 24 1 823 5 7 144 6 13 2010 12 19 21