I'm trying to adjust my Image's shadows, midtones, and highlights separately with PIL. I'm currently selecting these based on a division of 255 total by 3 (e.g. if(i<85) for shadows, if(i >= 85 and i < 170) for midtones, etc.).
The result is currently very aliased.
Here are the Photoshop Levels Settings for the Desired Output:
I've tried resizing the individual channels by twice the size, then resizing again with resample=Image.ANTIALIAS
, but that didn't produce a good effect.
self.shadows
,self.midtones
, self.highlights
, and self.alpha
are a float property value to control the adjustment.
pil_image.convert('RGBA')
# Split into 4 channels
r, g, b, a = pil_image.split()
shadow_r = r.point(lambda i: i * self.shadows if(i < 85) else 0)
shadow_g = g.point(lambda i: i * self.shadows if(i < 85) else 0)
shadow_b = b.point(lambda i: i * self.shadows if(i < 85) else 0)
shadow_a = a.point(lambda i: i * self.alpha if(i < 85) else 0)
mid_r = r.point(lambda i: i * self.midtones if(i >= 85 and i < 170) else 0)
mid_g = g.point(lambda i: i * self.midtones if(i >= 85 and i < 170) else 0)
mid_b = b.point(lambda i: i * self.midtones if(i >= 85 and i < 170) else 0)
mid_a = a.point(lambda i: i * self.alpha if(i >= 85 and i < 170) else 0)
highlight_r = r.point(lambda i: i * self.highlights if(i >= 170) else 0)
highlight_g = g.point(lambda i: i * self.highlights if(i >= 170) else 0)
highlight_b = b.point(lambda i: i * self.highlights if(i >= 170) else 0)
highlight_a = a.point(lambda i: i * self.alpha if(i >= 170) else 0)
# Recombine back to RGB image
shadow_img = Image.merge('RGBA', (shadow_r, shadow_g, shadow_b, shadow_a))
mid_img = Image.merge('RGBA', (mid_r, mid_g, mid_b, mid_a))
highlight_img = Image.merge('RGBA', (highlight_r, highlight_g, highlight_b, highlight_a))
pil_image2 = ImageChops.add(shadow_img,mid_img)
pil_image = ImageChops.add(pil_image2,highlight_img)
Can anyone please guide me on how to adjust the channels with a better falloff for the selection? Thank you!