Python PIL | ImageMath.eval() Method Last Updated : 19 Jul, 2019 Comments Improve Suggest changes Like Article Like Report 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. The 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) Parameters: 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. Image1 Used: Image2 Used: Python3 1== # Importing Image module from PIL package from PIL import Image, ImageMath # creating a image object im1 = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg").convert('L') im2 = Image.open(r"C:\Users\System-Pc\Desktop\leave.jpg").convert('L') # applying the eval method out = ImageMath.eval("convert(min(a, b), 'L')", a = im1, b = im2) out.save("result.jpg") out.show() Output: Another example:Here we change the inbuilt min() to max(). Python3 1== # Importing Image module from PIL package from PIL import Image, ImageMath # creating a image object im1 = Image.open(r"C:\Users\System-Pc\Desktop\ybear.jpg").convert('L') im2 = Image.open(r"C:\Users\System-Pc\Desktop\leave.jpg").convert('L') # applying the eval method out = ImageMath.eval("convert(max(a, b), 'L')", a = im1, b = im2) out.save("result.jpg") out.show() Output: Comment More infoAdvertise with us Next Article Python PIL | ImageMath.eval() Method S Sunitamamgai Follow Improve Article Tags : Python Python-pil Practice Tags : python Similar Reads Python PIL | Image.draft() 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, 2 min read 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, 2 min read Python PIL | ImageChops.add() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageChops module contains a number of arithmetical image operations, called channel operations (âchopsâ). These can be used for various purposes, including special effects, image composition 2 min read Python PIL | ImagePalette() Method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImagePalette module contains a class of the same name to represent the color palette of palette mapped images. This module was never well-documented. It hasnât changed since 2001, though, so 2 min read Python PIL | Image.crop() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL.Image.crop() method is used to crop a rectangular portion of any image. Syntax: PIL.Image.crop(box = None)Parameters: box - a 4-tuple defining the left, upper, right, and lower pixel coordin 2 min read Like