Project

General

Profile

sum up movie frames before drift correction, and best way to visualize a K2 image

Added by Rui Zhang about 11 years ago

Hi,

I have a dataset of k2 movie frames recorded at 0.2 sec per frame, and I feel the 0.2 sec is not long enough to give good signal/contrast for drift correction program.
Can anyone write me a python script to sum every two frames into one frame (so the exposure interval become 0.4 sec)?

And I wonder if Leginon has a build-in program to visualize the power spectrum of a K2 image?

Thanks!

Rui


Replies (2)

RE: sum up movie frames before drift correction, and best way to visualize a K2 image - Added by Anchi Cheng about 11 years ago

For summing every zbin frames in a movie, here is a python script to be used with the libraries comes with Leginon/Appion

from pyami import mrc

# change these for your case
filepath = 'your_mrc_stack_file'
outputpath = 'your_output_mrc_stack_file'
zbin = 2

# read header to find the number of frames
header = mrc.readHeaderFromFile(filepath)
number_frames = header['nz']

for i in range(number_frames/zbin):
    for j in range(zbin):
        zslice = i * zbin + j
        if j == 0:
            # initialize sum at the first one
            # This reads one frame into a numpy array
            sum = mrc.read(filepath,zslice)
        else:
            sum += mrc.read(filepath,zslice)
    if i == 0:
        # initialize the output stack
        mrc.write(sum,outputpath)
    else:
        mrc.append(sum,outputpath)

RE: sum up movie frames before drift correction, and best way to visualize a K2 image - Added by Anchi Cheng about 11 years ago

For viewing K2 image, you can use Leginon's wxPython imageviewer directly (after r17876). This works only for single image, also works for png or jpeg images

your_myami_checkout/leginon/gui/wx/TargetPanel.py your_mrc_file

The power spectrum produced after cropping the image to square can be outputted as an mrc image as well with this python script

from pyami import mrc, imagefun

input_filename = 'your_mrc_file'
output_filename = 'power.mrc'
mask_radius = 10

# read mrc file as numpy array
imarray = mrc.read(input_filename)

imageshape = imarray.shape

# easiest way to get a power spectrum that looks like optical diffraction is to first crop it
new_dim = min(imageshape)

# imarray is overwritten after cropping
imarray = imagefun.crop_at(array, (imageshape[0]/2, imageshape[1]/2), (new_dim_new_dim))
imageshape = imarray.shape

# This is the power spectrum array generation function used in Leginon
pow = imagefun.power(imarray, mask_radius)

# Write the resulting array to an mrc image file
mrc.write(pow, output_filename)
    (1-2/2)