daviddoria said:
if one of them is constant (say a vector of all 5's, which has standard deviation=0), then the correlation is infinity, but in fact the correlation should be zero right?
In that case, the expression for correlation takes the form 0/0, so you can't say it is infinity.
You raise an interesting question. It is important in practical applications of image processing. It's also a question about pure mathematics, but in that that respect it's more of a nitpicking detail.
In pure mathematics, perhaps some statistics texts define a value for the correlation in this case, but unless a special definition is given, all you can say about the mathematical expression is that it is undefined.
(If anyone wishes to delve into this technicality, we should begin by making a distinction among three distinct topics: covariance of two random variables, sample covariance, and estimator(s) of covariance. Things that are properties of samples (e.g. their variance) have somewhat arbitrary definitions (e.g. do we compute variance by dividing by N or N-1? ) and different books define them differently. Things that are properties of random variables and estimators of parameters have standard definitions, but I don't know if they are standardized in dealing with all the exceptional situations.)
As a practical concern, I think you are worried that if you have image patch A and are trying to match it to other image patches in a photo, that it may have a large correlation to a nearly constant patch B, which it does not resemble. As far as I know, that might happen. Expressions that approach 0/0 can take large or small values depending on how they approach it.
I'm sure your next question is whether there is some modification of the correlation formula that would produce a function that would avoid this problem. Off hand, I don't know of one. I'll have to think about it.