pymagery — python imagery
1.7.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):
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:
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:
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
- 1.7.0 — added