Download: latest (1.8.0)

pymagery — python imagery


1.8.0 documentation / __mul__ plugin

The __mul__ plugin overloads the multiplication operator. It allows the multiplication of two equally-sized images together or the multiplication of a constant to every pixel. If multiplying two RGB images together then each color channel is handled individually. If multiplying two monochrome images together then the result is effectively a logical AND.

The plugin prototype is (although never invoked directly):

def __mul__(other)

When invoking the multiplication operator it should be done with the asterisk (*) sign just like any other multiplication. The following example is how two images should be multiplied:

import pymagery i = pymagery.image('foo.ppm') k = pymagery.image('bar.ppm') m = i * k

Every pixel in i is multiplied with the corresponding pixel in k. If the pixel value exceeds the maximum then it is truncated to the maximum allowed value.

It is also permitted to multiply a constant value to every pixel:

import pymagery i = pymagery.image('foo.ppm') m = i * 20

This multiplies a value of 20 from every pixel. Again, if the value exceeds the maximum value then the value is truncated to the maximum. Note that 2 * i will not work because this would call int.__mul__(image) and the int class does not under what an image is.

Change Log