Differences between revisions 9 and 10
Revision 9 as of 2009-03-06 17:22:45
Size: 1272
Comment:
Revision 10 as of 2009-03-06 17:31:52
Size: 1334
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
= Set up 2 identical images = = Adding and multiplying images =

First I make different two example images that have the same dimensions
Line 11: Line 14:
In [3]: e = EMData() In [3]: a = test_image(0)
Line 13: Line 16:
In [4]: e.set_size(32,32,32) In [4]: b = test_image(1)
}}}
Line 15: Line 19:
In [5]: e.process_inplace('testimage.axes')

In [6]: f = e.copy() # f is precise replica of e
}}}
Line 21: Line 21:
= Make e different to f =
== Add/multiply/subtract/divide images and store the result in a new image ==
Line 24: Line 25:
In [7]: t = Transform({"type":"eman","alt":45,"phi":20,"az":11}) In [5]: c = a + b # add two images, the result is stored in c
Line 26: Line 27:
In [8]: t.set_trans(1,-2,5) In [6]: display(c) # observe c
Line 28: Line 29:
In [9]: t.set_mirror(True) In [7]: c = a * b # multiply the two images component wise, the result is stored in c
Line 30: Line 31:
In [10]: e.transform(t) In [7]: c = a / b # division
Line 32: Line 33:
In [11]: e.mult(2.5) # multiply all pixel values by 2.5

In [12]: e.add(13) # Adds 13 to all pixels
In [8]: c = a - b # subtraction
Line 37: Line 36:
= Add and multiply images = == Add/multiply b to/against a and store it in a ==
Line 40: Line 39:
In [13]: g = f + e # add two images, the result is stored in g In [9]: a.add(b) # Add the pixels of b to the pixels of a - result stored in a
Line 42: Line 41:
In [14]: display(g) # observe g In [10]: a.mult(b) # Multiple the pixels in a by the pixels of b - result stored in a
Line 44: Line 43:
In [15]: f.add(e) # Add the pixels of e into f directly }}}
Line 46: Line 45:
In [16]: f.mult(e) # Multiple the pixels in f by the pixels in e Subtract b from a and store it in a
Line 48: Line 47:
In [17]: g = f * e # Multiple the pixels in f by the pixels in e and store the result in g {{{
In [11]: c = b*-1 # multiply b by negative one

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

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

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