Routine to calculate correlation between two images