One straightforward way of doing this is to consider arbitrarily-sized patches of the image. For example, let's say we are interested in all 9*9 regions of pixels that can be taken from the image. Extract each of these image patches, and transform each image patch to a row vector. Consider the entire set of image patches (8464 row vectors for a 100*100 pixel image) as a matrix M.
Compute the correlation (or covariance, corr(M) and cov(M) in Matlab) between each of the columns in M. For your specific question, look at the three columns of the correlation/covariance matrix corresponding to the central pixel in the image. Reshape these back to the size of the image patch, and plot these. For natural images, you should find that the central pixel is highly correlated with adjacent pixels, and that the correlation decreases as distance from the central pixel increases across each of the three color channels.
The two most common methods (in my experience) for comparing signals are the correlation and the mean squared error. Informally, if you imagine your signal as a point in some N-dimensional space (this tends to be easier if you imagine them as 3D points) then the correlation measures whether the points are in the same direction (from the "origin") and the mean squared error measures whether the points are in the same place (independent of the origin as long as both signals have the same origin). Which works better depends somewhat on the types of signal and noise in your system.
The MSE appears to be roughly equivalent to your example:
mse = 0;
for( int i=0; i<N; ++i )
mse += (x[i]-y[i])*(x[i]-y[i]);
mse /= N;
note however that this isn't really Pearson correlation, which would be more like
xx = 0;
xy = 0;
yy = 0;
for( int i=0; i<N; ++i )
{
xx += (x[i]-x_mean)*(x[i]-x_mean);
xy += (x[i]-x_mean)*(y[i]-y_mean);
yy += (y[i]-y_mean)*(y[i]-y_mean);
}
ppmcc = xy/std::sqrt(xx*yy);
given the signal means x_mean and y_mean. This is fairly close to the pure correlation:
corr = 0;
for( int i=0; i<N; ++i )
corr += x[i]*y[i];
however, I think the Pearson correlation will be more robust when the signals have a strong DC component (because the mean is subtracted) and are normalised, so a scaling in one of the signals will not cause a proportional increase in the correlation.
Finally, if the particular example in your question is a problem then you could also consider the mean absolute error (L1 norm):
mae = 0;
for( int i=0; i<N; ++i )
mae += std::abs(x[i]-y[i]);
mae /= N;
I'm aware of all three approaches being used in various signal and image processing applications, without knowing more about your particular application I couldn't say what would be likely to work best. I would note that the MAE and the MSE are less sensitive to exactly how the data is presented to them, but if the mean error is not really the metric you're interested in then they won't give you the results you're looking for. The correlation approaches can be better if you're more interested in the "direction" of your signal than the actual values involved, however it is more sensitive to how the data are presented and almost certainly requires some centring and normalisation to give the results you expect.
You might want to look up Phase Correlation, Cross Correlation, Normalised Correlation and Matched Filters. Most of these are used to match some sub-signal in a larger signal with some unknown time lag, but in your case you could just use the value they give for zero time lag if you know there is no lag between the two signals.
Best Answer
Most simplest way how to solve this in two images is extract the values from both rasters and do correlation. I am not sure if this solution will fit to your spacific case. In what "format" do you have the images? (greyscale, RGB, size, resolution...). Please give more specific details.
Two rasters in R for demonstration:
Values for picture A:
Values for picture B:
Creation of arrays -> conversion of arrays into rasters
Setting color palette and plotting...
...and here is the correlation
Maybe there is more specialized solution to this but I think that this solution is pretty robust, simple and straightforward.
Link worth of interest: (for
ImageJ
) http://imagej.nih.gov/ij/plugins/intracell/index.html