Home > Back-end >  Removing pixels below a certain threshold
Removing pixels below a certain threshold

Time:12-22

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.

Here's the image: enter image description here

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:

A very commonly used library for that would be enter image description here

  • Related