Exercises

A set of guided exercises for classroom or self-study use. Each one introduces a different aspect of the Fourier transform and the relevant tools in the app. Try to predict the outcome before clicking Compute or Apply.

Exercise 0 — Build a chessboard from Fourier-space pixels

Create an empty image (top toolbar → New). With the paint brush in panel 2, place pixels in Fourier space. Can you create a chessboard pattern in real space?

Exercise 1 — High-, low-, band-pass and directional filters

Load an image. Apply high-pass, low-pass and band-pass filters, as well as directional and line filters from the panel-2 tool column. Try to first predict the effect of each filter on the real-space image before clicking Apply.

Exercise 2 — Restore an image with the Fourier eraser

Load the restauration_512.png image. Inspect it in Fourier space (panel 2). Use the eraser tool to remove suspicious peaks there and observe how the real-space image changes.

Exercise 3 — Intact vs anisotropic EM images

Load intact and anisotropic electron microscopy images. Inspect them both in real space (panel 1) and in Fourier space (panel 2). What distinguishes the two in each domain?

Exercise 4 — Lattice filtering of crystals and periodic scenes

Load the 2d_protein_crystal and Polyhead_virus images. Use the Lattice filter to obtain the protein maps.

Then load the Biozentrum_Basel_Eyes image. In Fourier space, use the lattice filter to either keep only the periodic content, or to delete the periodic content (toggle Erase outside lattice). Compare the two results.

Exercise 5 — Denoise a noisy apple with the lattice filter

Load a noisy apple image. Are you able to use the lattice filter to remove the noise? This requires precision in positioning the basis vectors.

Exercise 6 — Convolution theorem with Andreas

Load andreas_1024.png (-> g). Use a lattice filter with vectors (4, 0) and (0, 4), and a 1-pixel mask radius. Explain the effect using the convolution theorem.

Then create an empty image with the "New image" function (1024 size -> h). Use the paint brush to manually place a few pixels into it (pixel value 1, diameters 1). Convolute that newly created image with Andreas (Math calculation: i = g * h). Inspect the result. Correlate the result with Andreas (Math calculation: j = i × g). High-pass flatten the cross-correlation map j (Band pass filter in Fourier space, inner diameter 50, erase pixels outside of band). Run a peak search on the high-pass filtered cross-correlation map and create a list of peaks. Inspect the peaks in real space and Fourier space. Do they correspond to the pixels you placed in the image? Can you use the peak list to extract particles (128-pixel size) from the convoluted map i into a new slot? Do the extracted particles look like Andreas? Use in Fourier space the lattice filter (smooth edge: 0, diameter 1, lattice vectors (4,0) and (0,4)) to obtain the average particle from the extracted particles. Does it look like Andreas?

Exercise 7 — Phase ramp and the shift theorem

Load an image. Create a phase ramp in a different slot (panel-2 tool column). Look at it in Fourier space in the "Amplitude and Phase" mode.

Multiply this phase ramp with the Fourier transform of the image using Math calculation. What do you observe to happen with the image?

Exercise 8 — Real-space convolution vs Fourier multiplication

Load Fourier_text and Fourier_word and use the Math calculation function to convolute them in real space. Adjust the histogram to visualise the highest peaks.

Alternatively, multiply their Fourier transforms in Fourier space. Compare the results — they should match up to a constant factor.

Exercise 9 — Cross-correlation, picking and lattice averaging

Load a single particle protein image (a) and a particle template (b). Cross-correlate them with c = a × b using Math calculation. Apply a high-pass to the cross-correlation map c with inner radius 100.

Run peak search on the cross-correlation map c. Inspect the picked particles on a. Extract 64-pixel particles from a into slot d.

Use a lattice filter with exactly (16, 0) and (0, 16) on d to obtain the average particle (not rotationally aligned).

Advanced Exercise 10 — Helix synthesis

Load an image of a fibril cross-section into a buffer (a) and use the Amyloid function template to create a fibril projection image with that cross-section.

Alternatively, draw a cross-section with the paint brush and create a fibril from that.

Can you create a synthetic fibril image that in Fourier space resembles the Fourier transform of a real fibril image, especially concerning the reflection line at 4.75 Å?

Advanced Exercise 11 — Image alignment

This exercise uses the Exercise_11-Alignment data set: several electron micrographs of bacteriophages, each a bright angular head with a thin tail. Phage1, Phage2 and Phage3b show different particles, each sitting at its own place in the frame and pointing its own way. The b and c variants are the same particles, but artificial background was added around the viruses.

Start with a control. Load Phage1 and Phage1b into two buffers and use Align to reference to align one onto the other. Every button should report essentially nothing to do — zero shift, zero rotation — because the two images differ only in their redundant background. Note the correlation value that Rotation align reports; it is your yardstick for a good match.

Now the real task. Load Phage1 and Phage2, and align one onto the other with Shift align followed by Rotation align. The result disappoints, and the reason is the point of the exercise. Shift align locks onto the head, by far the strongest feature, and lays one head on the other — but both then sit away from the middle of the frame. Rotation align turns the image about the image centre, so an off-centre head does not spin on the spot: it swings around the centre on a wide arc, undoing the shift that was just found.

So, first center the head of one particle with the Shift image tool. Then run Shift align to bring another virus to the same position, and then Rotation align to rotate the viruses into the same orientation. You can cyclically repeat Shift align and Rotation align until the aligned virus does not move any longer. Does it work better now? What does that tell you about where a feature has to lie before a rotation search can find it?

Now go back to the untouched Phage1 and Phage2 and press Full align instead. It takes a moment longer than the other buttons, because it tries the best shift at each of the 720 orientations rather than one shift for all of them, and it should land the second phage on the first in a single step — no centring beforehand, no alternating, and this time the particle really does end up turned the same way as the reference. Compare its reported correlation with the best you reached by hand. Then look at the angle curve in the diagnostics panel and compare it with the one Rotation align drew: the same 720 angles, but each scored where it fits best rather than where it happens to lie. Which of the two curves has a peak you would trust?

With two or three phages aligned, sum them with Math calculation (d = a + b, then e = d + c). The display rescales to the data range, so a sum reads as an average. Which parts sharpen and which blur? Only what was genuinely aligned survives the averaging — which makes the average itself a verdict on your alignment.

Advanced Exercise 12 — CTF FIT: measuring defocus and astigmatism

This exercise uses the Exercise_12-CTF data set: twelve simulated cryo-EM micrographs (Example_….mrc) available from the example-image loader. Each is 1024 × 1024 pixels at 2 Å/pixel, imaged at 300 kV with Cs = 2.7 mm, and each was generated with a known defocus and astigmatism (the ground truth is listed in ctf_ground_truth.csv, and the file names encode the mean defocus and the astigmatism, e.g. Example_325nm_50nm.mrc). The goal is to recover those values with the CTF FIT tool and check how close the fit gets.

Load one of the examples into a buffer and press the up-arrow to compute its Fourier transform — you should see Thon rings in panel 2. Confirm the pixel size shown under panel 1 reads 2 Å (double-click it to edit if needed); the fit relies on it for the frequency scale.

Activate CTF FIT (the CTF / FIT icon in panel 2). Enter 300 kV and 2.7 mm, select the input buffer, set the resolution band (start with a lower limit of about 30 Å and an upper limit of about 4 Å), and press Execute. Read the fitted defocus and astigmatism reported in the window and compare them with the ground-truth value for that image.

Inspect the composite that appears on the Fourier side of the buffer: the right half is the fitted CTF, the top-left quarter the original transform, and the bottom-left quarter its astigmatism-aware radial average. In a good fit the rings line up continuously across the vertical midline, and the elliptical rings of the radial average match the raw rings above it.

Now experiment:

Advanced Exercise 13 — CTF SIM: generation with amplitude contrast and beam tilt

Choose an empty image buffer.
Use the CTF SIM tool (the CTF / SIM icon in panel 2) to create a CTF with different defocus settings. How does the defocus affect the CTF in Fourier space and the PSF in real space? Then, try to generate CTFs with different values of energy spread (try 3eV for LaB6, 0.7 for FEG, 0.3 for coldFEG, 0.1 for monochromator electron sources). Try different opening angles (0.1 mrad, 0.5 mrad, 1 mrad), which correspond to how parallel the beam is in illuminating the sample. How do the energy spread and opening angle affect the CTF in Fourier space and the PSF in real space? How do these parameters affect the Thon rings in Fourier space, or the coherence of the PSF in real space?

Finally, try different values of amplitude contrast and beam tilt. Inspect the resulting CTF in Fourier space, and in real space. How do the amplitude contrast and beam tilt affect the CTF? The real-space correspondent of the CTF is a point spread function (PSF). How do the amplitude contrast and beam tilt affect the PSF?

Try to generate a CTF with these parameters: 300 kV, 500 nm underfocus, 67 nm astigmatism, 5 mrad beam tilt. You will see a CTF with near perfect Thon rings, but the real-space PSF will be very anisotropic. This anisotropy in real space is called the "coma" and is a direct consequence of the beam tilt. If you have beam tilt in your microscope and correct it by setting (wrong) astigmatism parameters in the CTF, you will see that the Thon rings become round but now your microscope is misaligned and the PSF becomes distorted. In such cases, the correct solution is a Zemlin Tableaux acquisition and correction of the beam tilt, not a CTF astigmatism correction.

Advanced Exercise 14 — Hough transform to find lines

Load the Polyhead_virus image (the 512-pixel one, from the same folder as Exercise 4). It is a negative-stain electron micrograph of polyhead tubes: long, straight-sided objects lying across the field at two or three different orientations. Their edges are exactly what a Hough transform is built to find — and, unlike a Fourier transform, it will tell you where each edge is, not only which directions are present. If you have not read it yet, Advanced: What is a Hough transform? in the main manual explains the machinery.

1. Transform. Open Hough transform in the Filter group of panel 1. Set Input buffer to the buffer holding the micrograph and Output buffer to a free one, so that you can flip between the picture and its transform. Leave Geometric element on Lines and press Compute.

2. Read the accumulator. What you get is not a picture of the specimen: the horizontal axis is now the angle θ of a line (0° at the left edge, 180° at the right) and the vertical axis its distance ρ from the centre of the image. You should see a dense weave of sinusoids — one per edge pixel — with a handful of bright knots where many of them cross. Each knot is one straight edge in the micrograph. Adjust the display contrast by dragging across the histogram under panel 1; the peaks tower over the background, so the weave only becomes visible once you stretch the low end.

3. Read the tube widths off the peaks. This is the part worth doing slowly. Hover the peaks, or run Peak search on the accumulator with a generous exclusion radius, and note where they sit. You will find that the strong peaks come in pairs sharing the same θ: about θ ≈ 126° for one family of tubes and about 53° for the other. That is exactly what a tube should give — two parallel edges, same orientation, different distance from the centre. Now take the difference in ρ within a pair. Both pairs come out at roughly 55 pixels, which is the width of the tubes; and the fact that the two families agree tells you the polyheads all have the same diameter. Note also that a peak's θ is the angle of the edge's normal, so the tubes themselves run at θ − 90°, i.e. near 36° and 143°. Check that against the picture with the Measure tool.

4. Keep only the peaks. With the accumulator displayed, drag across the panel-1 histogram to select just its bright upper end, open Threshold histogram in the Edit group, set Mode to Select histogram and press Compute. Everything but the peaks drops to black. Keeping roughly the top 40–45% of the value range leaves on the order of fifty cells standing — a good starting point. Keep more and you will carry noise along; keep less and you will lose the weaker edges.

5. Transform back. Open Hough transform again, point Input buffer at the filtered accumulator and Output buffer at another free buffer, tick Inverse Hough transformation and press Compute. Every surviving cell draws its line back into image coordinates, so what you get is a clean drawing of the tube edges — the straight lines that were found, with the stain, the noise and the curved features all left behind. Put it beside the original and check that the lines land on the tubes.

Things to try. Vary how much of the histogram you keep in step 4 and watch lines appear and disappear in the back-transform, in order of how much evidence there was for them. Erase part of a tube with the panel-1 eraser and transform again: the peak gets shorter but does not move, because the remaining pixels still vote for the same line — this robustness to gaps is the whole reason for the method, and it is what tracing pixels cannot give you. Then run Circles, one radius at 20 px on the same micrograph and see that it finds nothing much: there are no circles of that size in it, and the transform says so honestly.

Compare with Fourier space. Exercise 4 used this same image with the lattice filter. Compute its Fourier transform as well and put the two side by side. The Fourier transform tells you which periodicities and directions the image contains, spread over the whole field; the Hough transform tells you which individual straight edges it contains and exactly where each one lies. Two different questions, two different transforms — and both are peak-finding problems once you are in the right space.

Advanced Exercise 15 — Hough transform to find circles

Load apoartcns_006 from the Exercise_09-Artemin-Protein / size_1024_rescaled_cropped folder — the same negative-stain Artemin data used in Exercise 9. It is a 1024-pixel micrograph holding of the order of a hundred small ring-shaped Artemin protein particles, roughly 20 pixels across, on a very noisy background. Exercise 9 found them by cross-correlating against a template. Here you will find them with no template at all — only a statement of how big they are.

1. Try it the naive way first. Open Hough transform (Filter group, panel 1), point Input buffer at the micrograph and Output buffer at a free buffer, choose Circles, one radius, set the radius slider to about 14 pixels and press Compute. The result is disappointing: a dense mess with no clear particles in it. Run Peak search on it and you will get well over a thousand peaks — far more than there are particles.

Why? Because the transform votes from edges, and in a raw negative-stain image the noise has edges everywhere. Every noise speck casts votes just as a particle rim does, and there are vastly more noise specks than particles. This is the single most important practical lesson about the Hough transform: it is only as good as the edge map it is given.

2. Low-pass filter the image, then transform. Undo, and use the Bandpass filter in Fourier space to create a blurred image, where the ring particles are visible, but the noise is strongly reduced.

Now run the Hough transform again on the smoothed image. If you do not want to guess the size, choose Circles, find radius automatically and let the tool sweep every radius from 5 to 60 pixels: it reports the one it settled on in the parameter window, around 14 pixels for this micrograph, which is a measurement of the particles in its own right. Switch back to Circles, one radius with the slider at that value for the rest of the exercise. This time the accumulator is transformed: a field of sharp, well-separated points on a dark background. Because the parameter space of a fixed-radius circle is the space of centres, the accumulator stays in register with the image — click back and forth between the two buffers and you will see each peak sitting exactly on its particle. A peak search now returns of the order of 120 particles, which is about what you count by eye.

3. Get the radius wrong on purpose. Repeat on the smoothed image with the radius slider pushed up to 40 px. Instead of points you get rings — one around each particle. The reason is worth working out: every rim pixel of a 14-pixel particle votes 40 pixels away from itself, so the votes agree on a circle of radius 40 about the particle rather than on its centre. Nothing is centred, so nothing peaks. Drag the slider slowly from 5 up to 60 and recompute as you go: the peaks sharpen as you approach the true radius and dissolve into rings as you pass it. The number of spurious peaks rises several-fold at the same time. Choosing the radius is choosing which objects you are asking about, and the transform answers honestly when the answer is "none of that size".

4. When you do not know the size. Compare the two multi-radius options on the smoothed image. Circles, radii 5,10,20,30,40,50,60 sums that fixed ladder, so everything circular contributes and the particles sit on a raised background of wrong-radius rings — useful on a specimen holding a mixture of sizes, wasteful here where they are all alike. Circles, find radius automatically instead tries all 56 radii, scores each, and applies only the winner, so the result is as clean as the hand-tuned single radius while costing you no guessing. It is the slowest option in the tool; the progress bar shows the sweep running.

5. Turn the peaks into particles. Run Peak search on the accumulator, with an exclusion radius of about 16 pixels — a little more than the particle radius, so that one particle cannot be picked twice — and commit the list. That returns of the order of 95 particles. Push the exclusion radius on up to 28 and the count falls to under 90, because touching pairs start being merged into a single pick; that is the trade-off the setting controls, and the slider runs from 5 to 200 so you can see both ends of it. Because the accumulator is in register with the image, those coordinates are the particle coordinates. Now set Extract particles to read from the original micrograph — not from the accumulator — and write a montage into a free buffer, then average it with Average image tiles at the same box size. You have gone from a noisy field to an averaged particle without ever supplying a reference.

Two details worth knowing here. The montage is always 1024 pixels square, so at a 64-pixel box it holds 256 tiles; with only about 120 particles picked, half of its tiles stay empty and the tile average is correspondingly diluted by that flat half. The particle is still perfectly visible, but if you want a clean average either pick from several micrographs until the montage fills, or use the lattice-filter route from Exercise 9, which averages the montage in Fourier space and is not troubled by the empty tiles. Note also that the particles are not rotationally aligned by any of this — the Hough transform locates them, it says nothing about their orientation.

Compare with Exercise 9. That exercise picked the same particles by cross-correlating against a template. Both end in a peak search, but what they need is different: cross-correlation needs a picture of what you are looking for and finds whatever resembles it, including its orientation; the Hough transform needs only a shape and a size, and is indifferent to how the particle actually looks inside its rim. Try both on this micrograph and compare the peak lists. Which one is more forgiving of particles that are partly overlapping, or clipped by the edge of the field?