Creating a normalized histogram
Question: I am working on a research paper published on Hair recognition from human
face, in the research paper I am stuck at the following part:

> We downsample each of Y,Cb and Cr channels into 64 levels.Then we can
> construct a three-dimensional color histogram in which each dimension has 64
> bins. **We normalize the color histogram in order to approximate** **the
> hair color likelihood distribution.**

As far as I have understood this statement, I am given 3 different histograms
and I have to create a new compiled histogram, Since I am not using MATLAB in
my project so I need to find a way to normalize 3 different histograms into 1,
I googled a lot but found nothing, Can somebody please help me on this. I need
the formula or something like that to implement this, Preferable languages are
:

> python, C++


Answer: I doubt it is 3 histograms. It sounds more like you have a 3 dimensional array
of 64x64x64 values of Y,Cb,Cr, where by each bucket (in that 3D array of
buckets) is a count of how many people had that particular hair color.
Normalizing is simply a matter of dividing each bucket by the total count (how
many people you got color samples from). With that assumption the following
code would work (I used 16 instead of 64):

    
    
    # Initialize 3D array to random counts
    import random
    cbucket = {}
    for y in range(0,16):
        for cb in range(0,16):
            for cr in range(0,16):
                cbucket[ y,cb,cr ] = float(round(random.uniform(0,10)))
    
    # Find total count
    tcount = 0
    for y in range(0,16):
        for cb in range(0,16):
            for cr in range(0,16):
                tcount += cbucket[ y,cb,cr ]
    
    print("tcount: %6.2f " % tcount)
    
    # now normalize
    for y in range(0,16):
        for cb in range(0,16):
            for cr in range(0,16):
                cbucket[ y,cb,cr ] = cbucket[ y,cb,cr ]/tcount
    

