Skip to main content

programming - How to understand the process of ListCorrelate when it in two-dimensional condition?



Toady,I learn a function ListCorrelate,and I can understand process of execution his result in one-dimensional. However,the documentation gives a two-dimensional correlation example(shown as below)


ListCorrelate[{{1, 1}, {1, 1}}, {{a, b, c}, {d, e, f}, {g, h, i}}]


{{a + b + d + e, b + c + e + f}, {d + e + g + h, e + f + h + i}}



To understand it,I replace {{1,1},{1,1}} to {{u,v},{x,y}}.


ListCorrelate[{{u, v}, {x, y}}, {{a, b, c}, {d, e, f}, {g, h, i}}]



{{a u + b v + d x + e y, b u + c v + e x + f y}, {d u + e v + g x + h y, e u + f v + h x + i y}}



My trail to figure out how his result be generate:



I think two-dimensional correlation is the composition of two one-dimensional correlations, but,unfortunately, from the results that Mathematica executes it is not what I think.



ListCorrelate[{{u, v}}, {{a, b, c}, {d, e, f}, {g, h, i}}]


{{a u + b v, b u + c v}, {d u + e v, e u + f v}, {g u + h v, h u + i v}}




ListCorrelate[{{x, y}}, {{a, b, c}, {d, e, f}, {g, h, i}}]


{{a x + b y, b x + c y}, {d x + e y, e x + f y}, {g x + h y, h x + i y}}



Question:


How to understand the process of ListCorrelate when it in two-dimensional condition?



Answer



The intuitive way to understand ListCorrelate is that the kernel is "moved" to every position in the array, and the sum of the products between the kernel values and the array values at that position is stored in the output array:



enter image description here


(if the kernel is separable, i.e. if there are two 1d kernels so that Transpose[{k1}] . {k2} == k2d, then ListCorrelate can be understood as the composition of two 1d correlations. But not every kernel is separable.)


Comments