The following example shows various ways of adding and multiplying images. The given example uses 3D images but the functionality generalizes for 2D images.

Adding and multiplying images

First I make different two example images that have the same dimensions

   1 [someone@localhost] e2.py
   2 
   3 Welcome to EMAN2
   4 Prompt provided by IPython
   5 Enter '?' for ipython help
   6 
   7 In [3]:  a = test_image(0)
   8 
   9 In [4]:  b = test_image(1)

or try a = test_image_3d(2), a = test_image(0) etc - see the test image gallery.

Add/multiply/subtract/divide images and store the result in a new image

   1 In [5]: c = a + b # add two images, the result is stored in c
   2 
   3 In [6]: display(c) # observe c
   4 
   5 In [7]: c = a * b # multiply the two images component wise, the result is stored in c
   6 
   7 In [7]: c = a / b # division
   8 
   9 In [8]: c = a - b # subtraction

Add/multiply b to/against a and store it in a

   1 In [9]: a.add(b) # Add the pixels of b to the pixels of a - result stored in a
   2 
   3 In [10]: a.mult(b) # Multiple the pixels in a by the pixels of b - result stored in a

Subtract b from a and store it in a

In [11]: c = b*-1 # multiply b by negative one

In [12]: a.add(c) # equivalent to subtracting b from a