import math


def rgb_bin(rgba, binsize):
    """
    Compute the RGB index for the hash table.  We do not need a bin for every
    RGB value, and do not have enough training images to support that anyway.
    So, lump together the adjacent R, G, and B values in bins of size binsize.
    """
    rgb = rgba[0:3]
    if binsize != 1:
        r,g,b = rgb
        # math.round returns a float
        r = int(math.floor(r/binsize) * binsize)
        g = int(math.floor(g/binsize) * binsize)
        b = int(math.floor(b/binsize) * binsize)
        rgb = (r,g,b)
    return rgb