ImageCorrelation provides several general function that can be used to replace the default Dot function. For example, in the documentation of ImageCorrelation, there is an example using CosineDistance as a general function:

enter image description here

ImageCorrelate[p, kr, CosineDistance ]; // AbsoluteTiming
(* {0.006005, Null} *)

We can see that the example runs very fast, and it's almost as fast as the default Dot version

ImageCorrelate[p, kr ]; // AbsoluteTiming
(* {0.004939, Null} *)

ImageCorrelate supports several general correlation functions such as SquaredEuclideanDistance, ManhattanDistance etc, and all of them have the about the same performance as the default one.

So I'm trying to do the similar thing to my data using ListCorrelation.

pData = ImageData[p];
krData = ImageData[kr];

(* {200, 150} *)
(* {50, 30} *)

ListCorrelate[krData, pData, {1, -1}, {}, (#1 - #2)^2 &, Plus]; // AbsoluteTiming
(* {38.7298, Null} *)

We can see that ListCorrelate is much slower, and it is orders of magnitudes slower than the default Dot function

ListCorrelate[krData, pData]; // AbsoluteTiming
(* {0.001633, Null} *)

So is there a way to speedup ListCorrelate to the same level of ImageCorrelate, for commonly used general functions in ImageCorrelate such as SquaredEuclideanDistance, CosineDistance etc?

  • $\begingroup$ The generalised version of ListCorrelate was always a real lot slower than the default (which is a shame because it opens up some nice usage possibilities). So unless some rewriting of the function too place recently you are not likely to match or get close the speed of the other function. $\endgroup$ – Mike Honeychurch Dec 23 '15 at 23:06
  • $\begingroup$ Might get modest improvement by using Compile on theoptional function. $\endgroup$ – Daniel Lichtblau Dec 24 '15 at 20:07

... 3 years later at least for 2D problems:

ImageCorrelate[pData//Image, krData, CosineDistance]//ImageData

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.