def avg_screen_color(initial_color): monitor = config["AverageColor"]["DefaultMonitor"] if monitor == "all": im = getScreenAsImage() else: im = getRectAsImage(eval(monitor)) color = im.resize((1, 1), Image.HAMMING).getpixel((0, 0)) color_hsbk = utils.RGBtoHSBK(color, temperature=initial_color[3]) # return tuple((val1+val2)/2 for (val1, val2) in zip(initial_color, color_hsbk)) return utils.RGBtoHSBK(color, temperature=initial_color[3])
def mode_screen_color(initial_color): """ Probably a more accurate way to get screen color, but is incredibly slow. """ im = getRectAsImage(getDisplayRects()[1]).resize((500, 500)) color = mode( im.load()[x, y] for x in range(im.width) for y in range(im.height) if im.load()[x, y] != (255, 255, 255) and im.load()[x, y] != (0, 0, 0)) return utils.RGBtoHSBK(color, temperature=initial_color[3])
def dominant_screen_color(initial_color, func_bounds=lambda: None): """ Gets the dominant color of the screen defined by func_bounds https://stackoverflow.com/questions/50899692/most-dominant-color-in-rgb-image-opencv-numpy-python """ monitor = get_monitor_bounds(func_bounds) if "full" in monitor: screenshot = get_screen_as_image() else: screenshot = get_rect_as_image(str2list(monitor, int)) downscale_width, downscale_height = screenshot.width // 4, screenshot.height // 4 screenshot = screenshot.resize((downscale_width, downscale_height), Image.HAMMING) a = np.array(screenshot) a2D = a.reshape(-1, a.shape[-1]) col_range = (256, 256, 256) # generically : a2D.max(0)+1 eval_params = { "a0": a2D[:, 0], "a1": a2D[:, 1], "a2": a2D[:, 2], "s0": col_range[0], "s1": col_range[1], } a1D = ne.evaluate("a0*s0*s1+a1*s0+a2", eval_params) color = np.unravel_index(np.bincount(a1D).argmax(), col_range) return list(utils.RGBtoHSBK(color, temperature=initial_color[3]))
def dominant_screen_color(initial_color, func_bounds=lambda: None): """ https://stackoverflow.com/questions/50899692/most-dominant-color-in-rgb-image-opencv-numpy-python """ monitor = get_monitor_bounds(func_bounds) if "full" in monitor: screenshot = getScreenAsImage() else: screenshot = getRectAsImage(str2list(monitor, int)) downscale_width, downscale_height = screenshot.width // 4, screenshot.height // 4 screenshot = screenshot.resize((downscale_width, downscale_height), Image.HAMMING) a = np.array(screenshot) a2D = a.reshape(-1, a.shape[-1]) col_range = (256, 256, 256) # generically : a2D.max(0)+1 eval_params = { 'a0': a2D[:, 0], 'a1': a2D[:, 1], 'a2': a2D[:, 2], 's0': col_range[0], 's1': col_range[1] } a1D = ne.evaluate('a0*s0*s1+a1*s0+a2', eval_params) color = np.unravel_index(np.bincount(a1D).argmax(), col_range) color_hsbk = list(utils.RGBtoHSBK(color, temperature=initial_color[3])) # color_hsbk[2] = initial_color[2] # TODO Decide this return color_hsbk
def avg_screen_color(initial_color, func_bounds=lambda: None): """ Capture an image of the monitor defined by func_bounds, then get the average color of the image in HSBK """ monitor = get_monitor_bounds(func_bounds) if "full" in monitor: screenshot = get_screen_as_image() else: screenshot = get_rect_as_image(str2list(monitor, int)) # Resizing the image to 1x1 pixel will give us the average for the whole image (via HAMMING interpolation) color = screenshot.resize((1, 1), Image.HAMMING).getpixel((0, 0)) return list(utils.RGBtoHSBK(color, temperature=initial_color[3]))