Size: 1272
Comment:
|
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
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
Add/multiply b to/against a and store it 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