Avoid saturated pixels in cross-correlation computation I am doing template maching using Normalized Cross-Correlation for measuring similarity between template and image.

However, some images from my dataset contain saturated pixels (overshoot) which should be avoided in the measurement.

How to update the cross-correlation computation to avoid saturated pixels?
I have finally found an aswer in a technical report "Image Alignment and Stitching: A Tutorial" from Richard Szeliski.

A weighted SSD (Sum of Suqared Differences) function is presented on page 13:

$$E_{WSSD}(u)=\sum_{i}w_{0}(x)w_{1}(x_{i}+u)\left[I_{1}(x_{i}+u)-I_{0}(x_{i})\right]^{2}$$

where $w_{0},w_{1}$ are spatially-varying weight functions (for template and the image). $u$ is a template offset.

The result may be divided by the overlap area to avoid bias towards smaller overlap.

This however works for SSD metric, not NCC. But it may suffice once images are normalized beforehand (using contrast/brightness adjustment computed using linear regression over corresponding pixel intensities).