def extract(path, tolerance=DEFAULT_TOLERANCE, limit=None): pixels = load(path) counter = count_colors(pixels) tmp = dict() for color, count in counter.items(): tmp[colorutil.rgb_lab(color)] = count counter = compress(tmp, tolerance) counter = sorted(counter.items(), key=lambda x: x[1], reverse=True) if limit: counter = counter[:min(int(limit), len(counter))] counter = [(colorutil.lab_rgb(c[0]), c[1]) for c in counter] return counter, len(pixels)
def extract(path, tolerance=DEFAULT_TOLERANCE, limit=None): pixels = load(path) rgb_colors = count_colors(pixels) if tolerance > 0: lab_colors = dict() for color, count in rgb_colors.items(): lab_colors[colorutil.rgb_lab(color)] = count lab_colors = compress(lab_colors, tolerance) rgb_colors = dict() for color, count in lab_colors.items(): rgb_colors[colorutil.lab_rgb(color)] = count rgb_colors = sorted(rgb_colors.items(), key=lambda x: x[1], reverse=True) rgb_colors = [(to_int(c[0]), c[1]) for c in rgb_colors] if limit: rgb_colors = rgb_colors[:min(int(limit), len(rgb_colors))] return rgb_colors, len(pixels)