Download: latest (1.8.0)

pymagery — python imagery


1.8.0 documentation / __eq__ plugin

The __eq__ plugin overloads the equality operator. It allows the equality comparison of two equally-sized images or the equality comparison of a constant with every pixel. If equality comparing two RGB images together then each color channel is handled individually. If equality comparing two monochrome images together then the result is effectively a logical XNOR.

This should not be confused with the image.sameas() function which fully compares the equality of dimensions, mode, and pixels of two images and returns a boolean value. Prior to 1.7.0 the __eq__ operator did behave as image.sameas() does in 1.7.0 and onward.

The plugin prototype is (although never invoked directly):

def __eq__(other)

When invoking the equality comparison operator it should be done with the double-equal sign (==) just like any other equality comparison. The following example is how two images should be equality compared:

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

Every pixel in i is equality compared to the corresponding pixel in k.

It is also permitted to equality compare a constant value with every pixel:

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

This equality compares a value of 20 with every pixel. Note that 2 == i will not work because this would call int.__eq__(image) and the int class does not under what an image is.

Change Log