Python PIL | ImageMath.eval() Method
PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities .The module also provides a number of factory functions, including functions to load images from files, and to create new images.
ImageMath module can be used to evaluate “image expressions”. The module provides a single eval function, which takes an expression string and one or more images.
PIL.ImageMath.eval() Evaluate expression in the given environment.
In the current version, ImageMath only supports single-layer images. To process multi-band images, use the split() method or merge() function.
Syntax: PIL.ImageMath.eval(expression, environment)
expression – A string which uses the standard Python expression syntax. In addition to the standard operators, you can also use the functions described below.
environment – A dictionary that maps image names to Image instances. You can use one or more keyword arguments instead of a dictionary, as shown in the above example. Note that the names must be valid Python identifiers.
Returns type: An image, an integer value, a floating point value, or a pixel tuple, depending on the expression.
Another example:Here we change the inbuilt min() to max().
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course