Hi Steven,
You're on the right track.
An EMData object is a representation of a single image/volume, not a set of images. While you could read a set of 2-D images into a single EMData object by literally "stacking" them in 3-D, that isn't a very productive way of working. To process
a stack, you can either:
- read all of the images in at once as a list of EMData objects (assuming not too much RAM is involved, this is much more efficient)
or
- you can find the number of images in the stack, and read/process them one at a time.
To generate the mask, assuming you want to make it programmatically rather than reading it from a file, you would generate an empty volume, then use a Processor to modify it in an appropriate fashion.
Writing images, again, could be handled one at a time, or all at once (again, this is much faster, but requires all of the images to be in RAM)
Example 1:
from EMAN2 import *
particle_stack=EMData.read_images("particle_stack.hdf")
# reads the entire stack as a list of EMData objects
mask=EMData(particle_stack[0]["nx"],particle_stack[0]["ny"],1)
# creates an empty image the same size
mask.to_one()
# all pixels to 1.0
mask.process_inplace("mask.soft",{"outer_radius":60,"width":3})
# applies a soft mask to the 1.0 image, 3 is the Gaussian 1/2 width of the soft edge in pixels
for image in particle_stack:
image.mult(mask)
# in place pixel-wise multiplication
EMData.write_images("output.hdf",particle_stack)
# write the entire stack at once
# or, now preferred
EMData.write_compresed(particle_stack,"output.hdf",0,bits=10,erase=True)
# write the entire stack at once with bit + lossless compression. erase the file first if it exists
Example 2:
from EMAN2 import *
n=EMUtil.get_image_count("particle_stack.hdf")
mask=EMData(particle_stack[0]["nx"],particle_stack[0]["ny"],1)
# creates an empty image the same size
mask.to_one()
# all pixels to 1.0
mask.process_inplace("mask.soft",{"outer_radius":60,"width":3})
# applies a soft mask to the 1.0 image, 3 is the Gaussian 1/2 width of the soft edge in pixels
for i in range(n):
image=EMData("particle_stack.hdf",i)
image.mult(mask)
# in place pixel-wise multiplication
image.write_image("output.hdf",i)
# or
image.write_compressed("output.hdf",i,bits=10,erase=True)
# note only erases when i=0
You can get a list of available processors and parameters with:
e2help.py processors
or a specific type:
e2help.py processors mask
or details:
e2help.py processors mask.soft -v 2
Within interactive python:
from EMAN2 import *
help(EMData)
help(EMUtil.get_image_count)
etc.
--------------------------------------------------------------------------------------
Steven Ludtke, Ph.D. <
slu...@bcm.edu> Baylor College of Medicine
Charles C. Bell Jr., Professor of Structural Biology
Dept. of Biochemistry and Molecular Biology (
www.bcm.edu/biochem)