Example #1
0
def hsl_colors_to_hex_codes(color_list):
    rgb_colors = hasel.hsl2rgb(color_list.reshape(-1, 1, 3)).reshape(-1, 3)
    rgb_colors = np.clip(rgb_colors, 0, 255)
    hex_codes = get_hex_codes(rgb_colors)
    return hex_codes
            greyscale_image.size, resample=Image.LANCZOS
        )
        colored_image_np = np.array(colored_image)

        # Transfer hue and saturation from the color image to the greyscale image via the
        # selected color space
        if args.via_color_space == "hsl":
            greyscale_image_np_hsl = rgb2hsl(greyscale_image_np)
            colored_image_np_hsl = rgb2hsl(colored_image_np)

            greyscale_image_np_hsl[:, :, 0] = colored_image_np_hsl[:, :, 0]  # hue
            greyscale_image_np_hsl[:, :, 1] = colored_image_np_hsl[
                :, :, 1
            ]  # saturation

            full_res_colored_image = hsl2rgb(greyscale_image_np_hsl)
        else:
            greyscale_image_np_hsv = rgb2hsv(greyscale_image_np)
            colored_image_np_hsv = rgb2hsv(colored_image_np)

            greyscale_image_np_hsv[:, :, 0] = colored_image_np_hsv[:, :, 0]  # hue
            greyscale_image_np_hsv[:, :, 1] = colored_image_np_hsv[
                :, :, 1
            ]  # saturation

            full_res_colored_image = hsv2rgb(greyscale_image_np_hsv)
            full_res_colored_image = (255 * full_res_colored_image).astype(np.uint8)

        Image.fromarray(full_res_colored_image).save(
            os.path.join(output_path, greyscale_file_path.stem + '.jpg'), quality=95
        )
Example #3
0
def hsl2rgb_wrap(hsl_mat):
    rgb_list = []
    for i in range(hsl_mat.shape[0]):
        rgb_list.append(hasel.hsl2rgb(hsl_mat[i]))
    return np.array(rgb_list)
Example #4
0
def hsllist2rl(hsl_color_list):
    rgb_colors = hasel.hsl2rgb(hsl_color_list.reshape(-1, 1, 3)).reshape(-1, 3)
    rl_values = []
    for i in range(rgb_colors.shape[0]):
        rl_values.append(rgb2rl(rgb_colors[i]))
    return np.array(rl_values)
Example #5
0
def hsllist2hex(color_list):
    rgb_colors = hasel.hsl2rgb(color_list.reshape(-1, 1, 3)).reshape(-1, 3)
    rgb_colors = np.clip(rgb_colors, 0, 255)
    hex_codes = rgblist2hex(rgb_colors)
    return hex_codes
Example #6
0
def hsl2rgb(hsl):
    return hasel.hsl2rgb(np.array([hsl]).reshape(-1, 1, 3)).reshape(-1, 3)[0]
Example #7
0
        dataset = "training" if i < split_index else "validation"
        num_examples = 1 if dataset == "training" else 1

        for j in range(num_examples):
            x1, y1, x2, y2 = get_random_coordinates(target_img)

            target_window = target_img[y1:y2, x1:x2, :]
            blurry_window = blurry_img[y1:y2, x1:x2, :]

            img_hsl = rgb2hsl(target_window)
            blurry_img_hsl = rgb2hsl(blurry_window)
            # Input image has original lightness channel, but blurry hue and saturation
            img_hsl[:, :, 0] = blurry_img_hsl[:, :, 0]  # hue
            img_hsl[:, :, 1] = blurry_img_hsl[:, :, 1]  # saturation
            input_window = hsl2rgb(img_hsl)

            if random.random() > 0.5:
                # Apply horizontal flip to 50 % of the images
                input_window = np.fliplr(input_window)
                target_window = np.fliplr(target_window)

            Image.fromarray(input_window).save(
                DATA_DIR
                / "resolution_enhancer_dataset"
                / dataset
                / "input_images"
                / (Path(image_file_paths[i]).stem + "_{}.png".format(j))
            )
            Image.fromarray(target_window).save(
                DATA_DIR