

@property
def average(self):
    from .quantize import get_color_index
    if (self._avg is None):
        total = 0
        mult = (1 << (8 - SIGBITS))
        r_sum = 0
        g_sum = 0
        b_sum = 0
        for i in range(self.r1, (self.r2 + 1)):
            for j in range(self.g1, (self.g2 + 1)):
                for k in range(self.b1, (self.b2 + 1)):
                    index = get_color_index(i, j, k)
                    hval = self.histo[index]
                    total += hval
                    r_sum += ((hval * (i + 0.5)) * mult)
                    g_sum += ((hval * (j + 0.5)) * mult)
                    b_sum += ((hval * (k + 0.5)) * mult)
        if total:
            r_avg = (~ (~ int((r_sum / total))))
            g_avg = (~ (~ int((g_sum / total))))
            b_avg = (~ (~ int((b_sum / total))))
        else:
            r_avg = (~ (~ int(((mult * ((self.r1 + self.r2) + 1)) / 2))))
            g_avg = (~ (~ int(((mult * ((self.g1 + self.g2) + 1)) / 2))))
            b_avg = (~ (~ int(((mult * ((self.b1 + self.b2) + 1)) / 2))))
        self._avg = (r_avg, g_avg, b_avg)
    return self._avg

dataset/ETHPy150Open admire93/mmcq.py/mmcq/region.py Vbox.average/original