documentation indexreference manualfunction index

im.matrix

Function: im.matrix (matrix):

Constructs an im.matrix object from the given matrix. im.matrix objects represent 5x5 matrices, and support a number of mathematical operations. The operations supported are matrix multiplication, scalar multiplication, element-wise addition, and element-wise subtraction. These operations are invoked using the standard mathematical operators (*, *, +, and -), respectively. If two im.matrix objects are multiplied, matrix multiplication is performed, otherwise scalar multiplication is used.

matrix is a 20 or 25 element list. If the list is 20 elements long, it is padded with [0, 0, 0, 0, 1 ] to make a 5x5 matrix, suitable for multiplication.

Example

# This matrix raises the brightness by 10%.
$ brightness = im.matrix([ 1, 0, 0, 0, .1,
                           0, 1, 0, 0, .1,
                           0, 0, 1, 0, .1,
                           0, 0, 0, 1, 0 ])

# This matrix halves the opacity.
$ opacity = im.matrix([ 1, 0, 0, 0, 0,
                        0, 1, 0, 0, 0,
                        0, 0, 1, 0, 0,
                        0, 0, 0, .5, 0 ])

# We can multiply them together, to get a matrix that modifies brightness and opacity.
$ brightness_opacity = brightness * opacity

# And supply that to im.MatrixColor.
image eileen altered = im.MatrixColor("eileen_happy.png", brightness_opacity)



documentation indexreference manualfunction index