Differences between revisions 10 and 11
Revision 10 as of 2009-03-06 17:31:52
Size: 1334
Comment:
Revision 11 as of 2009-03-06 17:34:35
Size: 1396
Comment:
Deletions are marked like this. Additions are marked like this.
Line 14: Line 14:
In [3]: a = test_image(0) In [3]: A = test_image(0)
Line 16: Line 16:
In [4]: b = test_image(1) In [4]: B = test_image(1)
Line 25: Line 25:
In [5]: c = a + b # add two images, the result is stored in c In [5]: C = A + B # add two images, the result is stored in C
Line 27: Line 27:
In [6]: display(c) # observe c In [6]: display(C) # observe C
Line 29: Line 29:
In [7]: c = a * b # multiply the two images component wise, the result is stored in c In [7]: C = A * B # multiply the two images component wise, the result is stored in C
Line 31: Line 31:
In [7]: c = a / b # division In [7]: C = A / B # division
Line 33: Line 33:
In [8]: c = a - b # subtraction In [8]: C = A - B # subtraction
Line 36: Line 36:
== Add/multiply b to/against a and store it in a == == Add/multiply B and A, store result in A ==
Line 39: Line 39:
In [9]: a.add(b) # Add the pixels of b to the pixels of a - result stored in a In [9]: A.add(B) # Add the pixels of A to the pixels of B - result stored in A
Line 41: Line 41:
In [10]: a.mult(b) # Multiple the pixels in a by 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
Line 45: Line 45:
Subtract b from a and store it in a == Subtract B from A and store it in A ==
Line 48: Line 48:
In [11]: c = b*-1 # multiply b by negative one In [11]: C = B*-1 # multiply B by negative one, store it C
Line 50: Line 50:
In [12]: a.add(c) # equivalent to subtracting b from a In [12]: A.add(C) # equivalent to subtracting B from A

In [13]: A.
add(B*-1) # equivalent to line above

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 and A, store result in A

   1 In [9]: A.add(B) # Add the pixels of A to the pixels of B - 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, store it C

In [12]: A.add(C) # equivalent to subtracting B from A

In [13]: A.add(B*-1) # equivalent to line above

EMAN2/Tutorials/AddAndMultiply (last edited 2009-03-06 17:36:06 by DavidWoolford)