Python ImageMath Module



The ImageMath module is used to evaluate 'image expressions'.
The module provides a single eval function, which takes an expression string and one or more images.

BitmapImage class
Creates photo image that is compatible with Tkinter which can be used everywhere Tkinter expects an image object.

function
ImageMath.eval(expression, environment)

Evaluate expression in the given 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: An image, an integer value, a floating point value, or a pixel tuple, depending on the expression.


Note:ImageMath only supports single-layer images. To process multi-band images, use the split() method or merge() function.

PhotoImage class
Creates photo image that is compatible with Tkinter which can be used everywhere Tkinter expects an image object.

Built-in Functions
These functions can be applied to each individual pixel.
function name Description
abs(image) Absolute value.
convert(image, mode) Convert image to the given mode. The mode must be given as a string constant.
float(image) Convert image to 32-bit floating point. This is equivalent to convert(image, F).
int(image) Convert image to 32-bit integer. This is equivalent to convert(image, I).
max(image1, image2) Maximum value.
min(image1, image2) Minimum value.
Advertisements