The following example shows various ways of adding, subtracting, multiplying and dividing images. The given example uses 2D images but the functionality generalizes for 3D images.
====== Adding and multiplying images ======
First I make different two example images that have the same dimensions
[someone@localhost] e2.py
Welcome to EMAN2
Prompt provided by IPython
Enter '?' for ipython help
In [3]: A = test_image(0)
In [4]: B = test_image(1)
//or try a = test_image_3d(2), a = test_image(0) etc - see the [[EMAN2:Galleries/Testimages|test image gallery]].//
===== Add/multiply/subtract/divide images and store the result in a new image =====
In [5]: C = A + B # add two images, the result is stored in C
In [6]: display(C) # observe C
In [7]: C = A * B # multiply the two images component wise, the result is stored in C
In [7]: C = A / B # division
In [8]: C = A - B # subtraction
===== Add/multiply B and A, store result in A =====
In [9]: A.add(B) # Add the pixels of A to the pixels of B - result stored in A
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, store it C
In [12]: A.add(C) # equivalent to subtracting B from A
In [13]: A.add(B*-1) # equivalent to line above