Friday, December 27, 2024
Google search engine
HomeLanguagesPython PIL | eval() method

Python PIL | eval() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.

PIL.Image.eval() Applies the function (which should take one argument) to each pixel in the given image. If the image has more than one band, the same function is applied to each band. Note that the function is evaluated once for each possible pixel value, so you cannot use random components or other generators.

Syntax: PIL.Image.eval(image, *args)

Parameters:
image – The input image.
function – A function object, taking one integer argument.

Returns type: An image.

Image Used:




   
  
# Importing Image module from PIL package 
from PIL import Image 
  
# creating a image object
im2 = Image.open(r"C:\Users\System-Pc\Desktop\lion.PNG")
  
# applying the eval method
im3 = Image.eval(im2, (lambda x: 254 - x * 15))
  
im3.show() 


Output:

Another example: Here we change the argument value for another image.

Image Used –




# Importing Image module from PIL package 
from PIL import Image 
  
# creating a image object
im2 = Image.open(r"C:\Users\System-Pc\Desktop\eval2image.PNG")
  
# applying the eval method
im3 = Image.eval(im2, (lambda x: 240 - x * 12))
  
im3.show()


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments