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.
import Image, ImageMath
im1 = Image.open("image1.jpg")
im2 = Image.open("image2.jpg")
out = ImageMath.eval("convert(min(a, b), 'L')", a=im1, b=im2)
out.save("result.png")
Evaluate expression in the given environment.
In the current version, ImageMath only supports singlelayer images. To process multiband images, use the split() method or merge() function.
参数: 


返回:  An image, an integer value, a floating point value, or a pixel tuple, depending on the expression. 
Expressions are standard Python expressions, but they’re evaluated in a nonstandard environment. You can use PIL methods as usual, plus the following set of operators and functions:
You can use standard arithmetical operators for addition (+), subtraction (), multiplication (*), and division (/).
The module also supports unary minus (), modulo (%), and power (**) operators.
Note that all operations are done with 32bit integers or 32bit floating point values, as necessary. For example, if you add two 8bit images, the result will be a 32bit integer image. If you add a floating point constant to an 8bit image, the result will be a 32bit floating point image.
You can force conversion using the convert(), float(), and int() functions described below.
The module also provides operations that operate on individual bits. This includes and (&), or (), and exclusive or (^). You can also invert (~) all pixel bits.
Note that the operands are converted to 32bit signed integers before the bitwise operation is applied. This means that you’ll get negative values if you invert an ordinary greyscale image. You can use the and (&) operator to mask off unwanted bits.
Bitwise operators don’t work on floating point images.
Logical operators like and, or, and not work on entire images, rather than individual pixels.
An empty image (all pixels zero) is treated as false. All other images are treated as true.
Note that and and or return the last evaluated operand, while not always returns a boolean value.
These functions are applied to each individual pixel.
Absolute value.
Convert image to the given mode. The mode must be given as a string constant.
Convert image to 32bit floating point. This is equivalent to convert(image, “F”).
Convert image to 32bit integer. This is equivalent to convert(image, “I”).
Note that 1bit and 8bit images are automatically converted to 32bit integers if necessary to get a correct result.
Maximum value.
Minimum value.