def print_hcl_hl_colour(): chart = Image.new("RGB", (depth, depth)) for l in range(depth): for h in range(depth): rgb = colourx.hcl_to_rgb((h, 255, l)) chart.putpixel((h, depth-1-l), rgb) chart.convert("RGB").save("assets/hclhlcolour.bmp")
def filter(image, rgb): filtered_image = Image.new("RGB", (image.width, image.height)) for y in range(image.height): for x in range(image.width): pixel = colourx.rgb_to_hcl(image.getpixel((x,y))) new_hue = colourx.rgb_to_hcl(rgb)[0] new_color = (new_hue, pixel[1], pixel[2]) filtered_image.putpixel((x,y), colourx.hcl_to_rgb(new_color)) return filtered_image
def hcl_rainbow(): chart = Image.new("RGB", (depth, 100)) for i in range(100): for h in range(depth): rgb = colourx.hcl_to_rgb((h, 255, 255)) chart.putpixel((h, 99-i), rgb) chart.convert("RGB").save("assets/rainbowhcl.bmp")
def print_hcl_hl_grey(): chart = Image.new("HSV", (depth, depth)) for l in range(depth): for h in range(depth): rgb = colourx.hcl_to_rgb((h, 255, l)) chart.putpixel((h, depth-1-l), (0,0,colourx.get_lum(rgb))) chart.convert("RGB").save("assets/hclhlgrey.bmp")
def dynamic_filter(image, rgb, colour_clamp=False): filtered_image = Image.new("RGB", (image.width, image.height)) for y in range(image.height): for x in range(image.width): opixel = image.getpixel((x,y)) pixel = colourx.rgb_to_hcl(image.getpixel((x,y))) new_hue = colourx.rgb_to_hcl(rgb)[0] new_color = colourx.hcl_to_rgb((new_hue, pixel[1], pixel[2])) opacity = math.sqrt(255**2-opixel[1]**2)/255.0 new_color = colourx.blend_colour( opixel, new_color, opacity) filtered_image.putpixel((x,y), new_color) return filtered_image
theight = sheight*20 segments = [] for x in range(x_segments): for y in range (y_segments): box = (x*swidth, y*sheight, x*swidth+swidth, y*sheight+sheight) new_image = input.crop(box=box) new_image.load() position = (x,y) new_segment = ImageSegment(input.crop(box), position) segments.append(new_segment) palette = Image.new("RGB", (twidth, theight)) for segment in segments: draw = ImageDraw.Draw(palette) rect = [segment.position, (segment.position[0]+swidth, segment.position[1]+sheight)] rgb = colourx.hcl_to_rgb(segment.hcl) draw.rectangle(rect, fill=rgb, outline=rgb) palette.convert("RGB").save("assets/final2.jpg")