Fourier Peak Filtering and Correlation Averaging in Iplt

The goal of this exercise is to Fourier peak filter an image of a negatively stained crystal and to further improve the average by correlation averaging. For this the image processing program iplt is used.

Starting Iplt and Loading the Image

First we have to start iplt using an additional initalization script providing us with some basic functions and algorithms which will be used in the following exercise. We will use the graphical version of iplt named giplt. As soon as giplt is started it will provide us with a command line prompt, where subsequent commands can be entered.

1. To start processing execute giplt with the init.py script as first parameter :

giplt init.py

2. Load the image raw.tif and center it:

raw=LoadImage('raw.tif')
raw.CenterSpatialOrigin()

Now we have to tell giplt how big a single pixel of the image is, because this information is needed later for the filtering. The image we just loaded has a pixel sampling of8 A/px.

3. Set the pixel sampling:

raw.SetPixelSampling(8*Units.A)

4. Display the image:

Viewer(raw)

You should now see a Data Viewer displaying our raw image.

5. Calculate the Fourier Transform of raw and display it:

fft=raw.Apply(FFT())
vfft=Viewer(fft)

In the Fourier transform you will just see the central pixel, as its intensity is much higher compared to the other pixels. To get a better display of the Fourier transform select an area not containing the center with the mouse and press <R> to renormalize the image.

Lattice Indexing

In the Fourier transform you see peaks corresponding to two crystal lattices. We will now fit one of the two lattices manually.

1. Add a lattice overlay to the viewer to manually index the lattice:

lattice=Lattice(Vec2(100,0),Vec2(0,100)) 
ov=LatticeOverlay(lattice)
vfft.AddOverlay(ov)

2. Modify the Lattice Overlay (Press <Control> and use the mouse) to fit as well as possible one of the lattices you see in the Fourier Transform:

<Control>+Left Mouse Button Move Lattice Point
<Control>+Center Mouse Button Rotate Lattice
<Control>+Right Mouse Button Shift Origin
<Control>+<1> Set first anchor
<Control>+<2> Set second anchor
<Control>+<f> fix new lattice
<Control>+<r> reject new lattice

Fourier Peak Filtering

As we now know the position of the crystal lattice we can generate a mask to filter out the areas not contributing to the crystal data.

1. Get the lattice information from the overlay and generate a lattice filter. The radius of the mask is 5 pixels:

lattice=ov.GetLattice() 
lattice_filter=LatticeFilter(lattice,5) 

2. Apply the lattice filter to the Fourier transform:

filtered_fft=fft.Apply(lattice_filter)

3. Backtransform and display the resulting image:

filtered=filtered_fft.Apply(FFT()) 
vfiltered=Viewer(filtered)

Some parts of the filterd image will have a higher backround than others. To get rid of these variations we can filter our image with a high pass filter removing the very low frequencies.

4. Create a high pass filter which filters all the frequencies out below 20 nm an apply it to the image:

hpfilter=HighPassFilter(20*Units.nm)
filtered.ApplyIP(hpfilter)

On the filtered image you should be able to see indiviual proteins. You can try to improve the result by modifying the lattice overlay to better fit the lattice, and then to repeat steps 1-3 of the Fourier peak filtering. You can also play around with the mask radius to see the influcence on the filtered image.

5. Save the filtered image:

SaveImage(filtered,'filtered.png')

Next we want to know how big the unit cell of the crystal is. For this we use the information we have of the lattice and the pixel sampling of the image to generate a reciprocal space unit cell. In the second step we convert the unit cell to real space.

6. Generate a reciprocal unit cell using the lattice and the pixel sampling:

reciprocal_unitcell=ReciprocalUnitCell(lattice,fft.GetPixelSampling())

7. Generate a spatial unit cell from the reciprocal unit cell:

spatial_unitcell=SpatialUnitCell(reciprocal_unitcell)

8. Print the unit cell information:

print spatial_unitcell

We can also display the unit cell as an overlay ontop of the filtered image.

9. Generate a UnitCellOverlay? and add it to the viewer:

uc_overlay=UnitCellOverlay(spatial_unitcell)
vfiltered.AddOverlay(uc_overlay)

You can move the overlay around with <Ctrl>+Right Mouse.

Correlation Averaging

The Correlation Averaging technique combines Fourier filtering and averaging. In the previous step, we created a Fourier filtered image which will serve us now as a reference for a cross-correlation with the original image: In combination with a peak search this will give us the locations of the unit cells of the lattice.

1. Select an area the size of ca. 2x2 unit cells of the filtered image in the viewer to use it as reference:

2. Extract the reference patch, center it and calculate how much the reference patch was shifted from the center:

selection_small=filtered.Extract(vfiltered.GetSelection())
origin=selection_small.GetSpatialOrigin()
selection_small.CenterSpatialOrigin()
shift=origin-selection_small.GetSpatialOrigin()

3. Paste the reference patch into an image the size of the original image:

selection=CreateImage(raw.GetExtent())
selection.CenterSpatialOrigin()
selection.Paste(selection_small)

4. Display the selection and check if it is OK. If not: repeat steps 1-3:

Viewer(selection)

5. Cross correlate the Fourier filtered image with the chosen reference:

cc=CrossCorrelate(raw,selection)
vcc=Viewer(cc)

In the cross correlation image the intensity of the pixel show how well this part of the original image correlates to the reference, the higher the pixel value the better the correlation. In the next step we search the positions of highest correlation with a peak search algorithm to use these in the subsequent averaging.

6. Generate real space lattice and correct it for the shift of the selection:

real_lattice=CreateLatticeFromUnitCell(spatial_unitcell,raw.GetSpatialSampling())
real_lattice.SetOffset(shift.ToVec2())

7. Display real space lattice on top of cross correlation image:

rs_ov=LatticeOverlay(real_lattice)
vcc.AddOverlay(rs_ov)

8. Open the Overlay Manager GUI (Windows->Open Overlay Manager GUI) of the Data Viewer showing the cross correlation image, change the lattice to display circles (Lattice->Circles) and decrease the symbol size to 2 (Lattice->Set Symbol Size).

As you can see the lattice coincides only with part of the cross correlation maxima. The reason for this are bends in the crystal lattice. With a peaksearch we can never the less find the correct position of every unit cell and use this position information to average the unit cells.

9. Perform a Peak Search and Display the found peaks. The minimum distance between two found peaks is 8 pixels, the peak search sensitivity is 1 and the maximal size of a peak is 3 pixels. You can also try to change the parameters. If you lower the sensitivity you will also pick up weaker peaks and if you higher the sensitivity you will only find the very strong spots:

peaksearch=PeakSearch(8,1,3)
cc.Apply(peaksearch)
peaklist=peaksearch.GetPeakList()
ShowPeaks(vcc,peaklist)

10. Extract images of size 64x64 at the peak positions from the original image and average them:

correlation_average=CorrelationAverage(raw,peaklist,64,64)

11. Display the correlation image together with the unit cell:

vca=Viewer(correlation_average)
uc_overlay2=UnitCellOverlay(spatial_unitcell)
vca.AddOverlay(uc_overlay2)

The obtained correlation average should be of better quality than the Fourier filtered image. It would be possible to use the correlation average as a new reference and with this improved reference to repeat the correlaton averaging procedure to get an even better result.

12. Save the correlation average:

SaveImage(correlation_average,'correlation_average.png')

Back to Tutorials

Attachments