Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

explanation of Correlate

I am a beginner in using Mathematica, know little about optics. However, I would like to know how to understand the function ImageCorrelate, since the introduction in Mathematica Book is too brief and not quite informative. I've read a solution here, How can I extract data points from a black and white image? But can not understand this

code

share|improve this question

closed as off-topic by m_goldberg, Sjoerd C. de Vries, bobthechemist, Szabolcs, rasher Mar 20 at 0:47

  • The question does not concern the technical computing software Mathematica by Wolfram Research. Please see the help center to find out about the topics that can be asked here.
If this question can be reworded to fit the rules in the help center, please edit the question.

1  
Do you know what is convolution? Try to understand ListCorrelate and ListConvolve first. Read what they do under the details section of their doc pages and experiment with 1D lists. Finally think about how they're related to the dot product to understand what the third argument of ImageCorrelate does. –  Szabolcs Mar 19 at 16:17
1  
As Szabolcs said, this really has nothing to do with Mathematica or the implementation of ImageCorrelate... the terms and concepts are related to convolution/correlation and the linked wiki article will be helpful. –  rm -rf Mar 19 at 16:21
4  
This question appears to be off-topic because it is not really about Mathematica, but concerns certain mathematical or physical concepts that must be mastered to properly use the Mathematica built-in functions mentioned in the question. –  m_goldberg Mar 19 at 19:36
    
But I have to know how the Function ImageCorrelate works in Mathematica. If not, I can not use this Function which is so important in Mathematica... This is thus not completely off-topic.... –  Tough Kid Mar 20 at 7:38

1 Answer 1

up vote 9 down vote accepted

Reading a bit about convolutions and correlations will help.

The correlation of functions $f(x)$ and $g(x)$ is defined as $$c(t) = \int_{-\infty}^{\infty} f(t+x) g(x) \; dx$$

ImageCorrelate and ListCorrelate do the same thing for lists of numbers. For example,

ListCorrelate[{a, b, c}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]

returns a list whose first element is 1*a + 2*b +3*c. Notice that this is just Dot[{a,b,c}, {1,2,3}], i.e. the dot product of the kernel {a,b,c} with elements 1..3 of list {1,2,...,10}. The second element of the correlation will use elements 2..4, the third will use elements 3..5, etc., always shifting by one. The result is

{  a + 2 b + 3 c, 2 a + 3 b + 4 c, 3 a + 4 b + 5 c, 4 a + 5 b + 6 c, 
 5 a + 6 b + 7 c, 6 a + 7 b + 8 c, 7 a + 8 b + 9 c, 8 a + 9 b + 10 c}

Generally, ListCorrelate[k, x] will compute $$c_j = \sum_{i=1}^{\text{Length[$k$]}} k_i x_{i+j}$$

ImageCorrelate does the same thing, but it uses images---2D arrays---instead of 1D lists. Imagine placing a small image, the kernel, centred on top of each pixel of a larger image and computing the dot product of the overlapping regions.

You'll find many lecture notes online explaining this concept, for example this one.

In practical applications of correlations an important property that is usually exploited is this: if two arrays are similar, their dot product tends to be large. Thus the correlated image will have bright pixels where the kernel is similar to the image. See for example the face detection example in the documentation.

This is only a short summary that will get you started. To learn more, you can read about correlations independently of Mathematica.

share|improve this answer
    
Excellent explanation !!! Quite helpful :-). I've found a video which visualized the Graphical convolution.youtube.com/watch?v=zoRJZDiPGds –  Tough Kid Mar 20 at 10:08

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