# Convolution and Cross Correlation Blackbox

Suppose I was handed a blackbox that I know is either a Convolution filter or Cross-Correlation filter, and my job is to find out which it is.

My idea is to pretend that it's Cross-Correlation and attempt to do Template Matching using an image and a crop of the same image. If the output has a peak where a successful template match would be, it's Cross-Correlation. Otherwise, it's Convolution.

Is this a reliable test? Is it possible to also arrive at the same expected output if the blackbox was actually Convolution?

Method#1: Feed input arguments that are asymmetrical:

>> conv(1:3,1:3)

ans =
1     4    10    12     9
>> xcorr(1:3,1:3)

ans =
3.0000    8.0000   14.0000    8.0000    3.0000


Method#2: Swap inputs and see if the output changes

>> xcorr(1:3,[1 1 1])
ans =
1.0000    3.0000    6.0000    5.0000    3.0000
>> xcorr([1 1 1], 1:3)
ans =
3.0000    5.0000    6.0000    3.0000    1.0000

• great answer. If I could check it, I would. – mark leeds Sep 1 '20 at 1:51
• For images that tend to be real-valued and visual "objects"/templates that tends to be symmetrical, the only functional difference might be a possible flip of the image. – Knut Inge Sep 1 '20 at 7:55