Solved – Bhattacharyya distance for three histograms

bhattacharyyadistancedistance-functionshistogram

There is a paper “Auto White Balance Based on the Similarity of Chromaticity Histograms” mention about automatic white balance. One of the key point of this algorithm is how to measure the similarity between three histograms (r, g, b channels). They choose Bhattacharrya distance to measure it.

Equation of Bhattacharrya distance for two histograms (1)
$$d(H_1, H_2) = \sqrt{1 – p(H_1, H_2)}$$
$$p(H_1, H_2) = H_1(0) * H_2(0) + H_1(1) * H_2(1) + … + H_1(255) * H_2(255)$$

However, no matter how hard I try, I can't find a way to apply Bhattacharrya distance on three histograms.

Could I just alter the second equation to
$$p(H1, H2, H3) = H_1(0) * H_2(0) * H_3(0) + H_1(1) * H_2(1) * H_3(1) + … + H_1(255) * H_2(255) * H_3(255)$$

Best Answer

Find similarity between RGB values separately, like I did.

float CTracker::calculate_similarity_colour (BlobPast* prev_blob, PositionArrays* curr_blob, int k)
{
    float total_red = 0;
    float total_blue = 0;
    float total_green = 0;
    float similarity = 0;
    float S_D_R = 0;
    float S_D_G = 0;
    float S_D_B = 0;

    for (int i = 0; i < 256; i++)
    {
        if ((prev_blob->colour_red[i] != NULL ) &&  (curr_blob->colours[i].colour_red != NULL))
        {
            S_D_R = sqrt (abs(  (prev_blob->colour_red[i]) *  (curr_blob->colours[k].colour_red[i])));
            total_red       = total_red + S_D_R;

            S_D_G = sqrt( abs (  ( prev_blob->colour_green[i]) *  (curr_blob->colours[k].colour_green[i])));
            total_green     = total_green + S_D_G;

            S_D_B  = sqrt( abs(  (prev_blob->colour_blue[i]) *   (curr_blob->colours[k].colour_blue[i])));
            total_blue = total_blue + S_D_B;
        }
    }

    similarity = (0.4 * total_red) + (0.3 * total_green) + (0.3 * total_blue);
    return similarity;
}

//Note the reason my similarity would be between 0-1 is I divided each each histograms each value by total number of pixels (i.e., normalizing)
Related Question