Differences between revisions 4 and 10 (spanning 6 versions)
Revision 4 as of 2008-02-03 17:50:49
Size: 561
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 1: Line 1:
{{{
[someone@localhost]$ e2.py
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

{{{#!python
[someone@localhost] e2.py
Line 8: Line 14:
In [3]: e = EMData() In [3]: a = test_image(0)
Line 10: Line 16:
In [4]: e.set_size(32,32,32) In [4]: b = test_image(1)
}}}
Line 12: Line 19:
In [5]: f = e.copy() ''or try a = test_image_3d(2), a = test_image(0) etc - see the [[EMAN2/Galleries/Testimages|test image gallery]].''
Line 14: Line 21:
In [5]: e.process_inplace('testimage.axes')
== Add/multiply/subtract/divide images and store the result in a new image ==

{{{#!python
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
Line 16: Line 35:
''or try e.process_inplace('testimage.scurve') or e.process_inplace('testimage.gradient')''
{{{
In [6]: t = Transform3D(90,30,90)
Line 20: Line 36:
In [7]: t.set_posttrans(1,-2,5) == Add/multiply b to/against a and store it in a ==
Line 22: Line 38:
In [8]: t.set_pretrans(2,10,-20) {{{#!python
In [9]: a.add(b) # Add the pixels of b to the pixels of a - result stored in a
Line 24: Line 41:
In [9]: e.rotate_translate(t)

In [10]: e.mult(10)

In [11]: g = f + e

In [12]: display(g)
In [10]: a.mult(b) # Multiple the pixels in a by the pixels of b - result stored in a
Line 33: Line 44:

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

}}}

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)