In an attempt to compare histograms of two segments, we'll employ a number of different techniques.

Some Considerations

Some things to keep in mind, though, is that the information close to the center of the histogram (128) is more reliable than the information close to the edge (0, 255). Overexposure and underexposure could be the culprit, and everything matches when everything is black! One way to possibly combat this is to weight the center of the histogram more than the edge. A sine curve could work. As would a normal curve. This might need some exploration to find the appropriate weighting function.

For the examples below, let's assume that an ideal weighting function has been discovered; call it w(i). At the center of the histogram (128), it returns a number close to 1. At the ends, it returns a number close to 0.

Another part is changes in light. If an object comes under a shadow, the histogram will retain a similar shape, but lessen in strength. Normalizing the histogram will help.

Reflections could also cause potential problems.

It would be ideal to have a function that can compare the color qualities of two segments, disregarding the brightness.

Simple Summing for Quantified Similarity and Dissimilarity

For the following equationsZ

  • Let h1 and h2 be discrete functions over the closed interval 0-255 returning a real number normally between 0 and 1. The first parameter indicates the index for an array of floats of a normalized (0-1) histogram channel. Note: the value returned could be outside the 0-1 range.
  • Let c be some really small constant (to avoid division by zero)
\begin{align} \text{Quantified Dissimilarity} = \sum_{i=0}^{255} w(i) (h_1(i) - h_2(i))^2 \end{align}
\begin{align} \text{Quantified Similarity, Squared} = \sum_{i=0}^{255} \frac{1}{w(i) (h_1(i) - h_2(i))^2 + c} \end{align}
\begin{align} \text{Quantified Similarity, Absolute} = \sum_{i=0}^{255} \frac{1}{w(i) |\ h_1(i) - h_2(i)\ | + c} \end{align}

Comparing the Slopes (Discrete Derivative)

This needs some more thought, but I think it has some promise. (see Discrete Calculus for more information).

\begin{align} v_1(i) = \Delta_{i}h_1(i) = \left[\begin{array}{11} 1 \\ h_1(i + 1) - h_1(i) \end{array}\right] \end{align}
\begin{align} v_2(i) = \Delta_{i}h_2(i) = \left[\begin{array}{11} 1 \\ h_2(i + 1) - h_2(i) \end{array}\right] \end{align}
\begin{align} \text{Quantified Discrete Derivative Dissimilarity} = \sum_{i=0}^{254} w(i) (v_1(i) \cdot v_2(i)) \end{align}

Comparing Max

  • let X1 be index of the global max for hist1, X2 be the index of the global max for hist2
  • need to weight the difference by closeness to center, because if the global max sits at either end, that could be matching black (under exposed) and white (over exposed)… which could be bad
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License