Skip to content

Lightness inversion preserving colors #7314

Answered by homm
mara004 asked this question in Q&A
Discussion options

You must be logged in to vote

Here is the full example using HLS color space:

import colorsys
from PIL import Image, ImageFilter


def invert_colors(r, g, b):
    h, l, s = colorsys.rgb_to_hls(r, g, b)
    l = 1.0 - l
    return colorsys.hls_to_rgb(h, l, s)


invert_filter = ImageFilter.Color3DLUT.generate(17, invert_colors)
Image.open('257923775.png').filter(invert_filter).save('257923775.out.png')

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
4 replies
@mara004
Comment options

@mara004
Comment options

@mara004
Comment options

@radarhere
Comment options

Comment options

You must be logged in to vote
4 replies
@mara004
Comment options

@mara004
Comment options

@homm
Comment options

homm Aug 5, 2023
Collaborator

@mara004
Comment options

Answer selected by mara004
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants