I have a grayscale image with something written in the front and something at the back. I'd like to filter out the back part of the letters and only have the front. It's only grayscale and not RGB, and I'd rather not have to calculate pixels manually.
Is there any library function I can use to do this? I'm new to python and at the moment, using PIL library, so that's my preference. But if there are other libraries, I'm open to that as well.
CodePudding user response:
Are you looking for a function that automatically strips the background for any given image, or just one that can filter out pixels that meet a certain criteria for this particular image?
The eval function applies the same transformation to every pixel in an image. This works for your image.
with Image.open("jFmbt.jpg") as im:
im = im.convert("L")
out_image = Image.eval(im, lambda x: 256 if x > 175 and x < 250 else x)
CodePudding user response: