Using the Image.point() method in PIL to manipulate pixel data

前端 未结 2 1572
抹茶落季
抹茶落季 2020-12-08 15:28

I am using the Python Imaging Library to colorize a black and white image with a lookup table that defines the color relationships. The lookup table is simply a 256-element

2条回答
  •  离开以前
    2020-12-08 16:16

    I think it might be more typical to point on a band-by-band basis like so (lifted directly from the PIL tutorial):

    # split the image into individual bands
    source = im.split()
    
    R, G, B = 0, 1, 2
    
    # select regions where red is less than 100
    mask = source[R].point(lambda i: i < 100 and 255)
    
    # process the green band
    out = source[G].point(lambda i: i * 0.7)
    
    # paste the processed band back, but only where red was < 100
    source[G].paste(out, None, mask)
    
    # build a new multiband image
    im = Image.merge(im.mode, source)
    

提交回复
热议问题