Python PIL Image.point() method

Python PIL Image.point() Method

PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The Image module provides a class of the same name that represents a PIL Image. The module also provides factory functions, including functions for loading images from files and creating new images.

Image.point() maps the image through a lookup table or function.

Syntax: Maps the image through a lookup table or function.

Parameters:

lut – A lookup table containing 256 (or 65336 if self.mode == “I” and mode == “L”) values for each band in the image. A function can be used instead, which should accept only one argument. The function is called once for each possible pixel value, and the resulting table is applied to all bands in the image.

mode – Output mode (defaults to the same as the input). Currently, this mode is only used when the source image mode is “L” or “P” and the output mode is “1,” or when the source image mode is “I” and the output mode is “L.”

Returns: An image object.

Images used:
Python PIL Image.point() method

# importing Image class from PIL package
from PIL import Image
  
#creating an object
im = Image.open(r"C:UsersSystem-PcDesktophome.png")
  
# using point function
threshold = 191
im = im.point(lambda p: p >value threshold and 255)
im.show()

Output:
Python PIL Image.point() method

Another example: Here, the threshold is changed.

Images used:
Python PIL Image.point() method

# importing Image class from PIL package
from PIL import Image
  
#creating an object
im = Image.open(r"C:UsersSystem-PcDesktophome.png")
  
# using point function
threshold = 120
im = im.point(lambda p: p > threshold and 255)
im.show()

Output:
Python PIL Image.point() method

Leave a Reply

Your email address will not be published. Required fields are marked *