Пример #1
0
def histogramCompressedFill(pix, targetBins, floor, ceiling, colorMax, mode="RGB"):
    blankPlot = ColorPlots.blankPlot(targetBins)
    inputRange = float(ceiling - floor)
    alpha = targetBins/inputRange    
    for i in range(1300):
        for j in range(1300):
            [R, G, B] = [pix[i,j][0], pix[i,j][1], pix[i,j][2]]
            if mode == "LAB":
                [L,A,B] = Utils.RGBToLAB([R, G, B], colorMax)
                if L < floor or L > ceiling:
                    continue
                x = int(((A+128)/256.) * targetBins)
                y = int(((B+128)/256.) * targetBins)
                blankPlot[x][y] += 1
            elif mode == "HSV":
                [hue, sat, val] = Utils.RGBToHSV([R, G, B], colorMax)
                if val < floor or val > ceiling:
                    continue
                y = int(((val - floor) / inputRange) * targetBins)
                coneWidthAtY = int(targetBins * (val/100.))
                xMin = (targetBins/2.) - (coneWidthAtY/2)
                x = int(((hue/360.)*coneWidthAtY) + xMin)
                polarData = [[(val/100.)*(targetBins/2.3), (hue/360.)*2*math.pi, 0]]
                coords = Utils.polarToBins(polarData, targetBins)
                x = coords[0][0]
                y = coords[0][1]
                blankPlot[x][y] = Utils.HSVToRGB(hue*2*math.pi/360., sat, val)
            elif mode == "RGB":
                if math.sqrt(R**2 + G**2 + B**2) < floor:
                    continue
                if math.sqrt(R**2 + G**2 + B**2) > ceiling:
                    continue
                x = int(((R - floor) / inputBins) * targetBins)
                y = int(((G - floor) / inputBins) * targetBins)
                z = int(((B - floor) / inputBins) * targetBins)
                blankHistogram[x][y][z] += 1
    histogram = blankPlot
    return histogram