Fourier Transform: Image Processing
Fourier Transform: Image Processing
Frequency space offers some attractive advantages for image processing. It makes large linear filtering operations
(equivalent to the application of large neighborhood kernels) much faster, and it collects information together in
different ways that can sometimes separate signal from noise or allow measurements that would be very difficult
in the spatial domain.
4.A. FFT Requirements: The common denominator in all of these operations is the FFT or fast Fourier
transform. The software requires that the image be square with dimension equal to an exact power of two (e.g.,
128, 256, 512, ...). There are several easy ways to select a suitable region from a larger image. One is to copy and
paste the image into a new window of the appropriate size. The step-by-step process is Select | All; Edit |
Copy; File | New (enter the dimensions in pixels); Edit | Paste. If the original image is larger than the new
window you can shift the image within the window to select the region, before de-selecting the region. Note that
you must deselect the pasted region before performing any filter operation, or else the program will attempt to
apply the process to the entire clipboard rather than just to the image area (usually with unexpected and incorrect
results). This can be done in many ways, for instance by choosing Select | All, by clicking in the image with
the ROI/Marquee tool, or by flattening the image (Layer | Flatten Image). If the original image is smaller
than the new window, the surrounding area should ideally be filled with an intermediate grey value (this is called
"padding") to minimize the amplitude of the Fourier terms needed to accommodate the transition to white. This
filling can be done using the paintbucket.
4.B. Applying high and low pass filters. Traditional low-pass filters used for smoothing and high-pass
filters for edge sharpening can be applied by selecting a circular aperture in frequency space and keeping either
the low frequency data inside or the high frequency data outside the circle. Smoothing the edge of the aperture
will reduce ringing, and of course the cutoff frequency itself depends on what you know about the contents of the
image and what you want to keep or eliminate.
To apply a basic circular aperture to the data, create a new, blank image that is the same size as the original (for
example, select Image | Duplicate, Select | All and press Delete to erase the contents). Then choose the
elliptical marquee tool and depress the shift key (which constrains the shape to a circle) and option (Mac) or alt
(Windows) which causes the shape to be drawn from its center, and draw a circle starting from the center of the
power spectrum display. The result is a circular aperture that can be filled with black by selecting Edit | Fill.
The surroundings can be erased by Select | Inverse and pressing Delete.
If the central circular aperture is black and the surroundings white, the filter will keep low frequencies and erase
high frequencies. To apply this filter to the stored Fourier transform and reconstruct a filtered spatial domain
Tutorial Part 4 Page # 2 Fourier methods
image, select Filter | IP•FFT | Filter+Inv. Note: the terms "mask" and "filter" are used interchangeably
here. In some cases the term mask is reserved for operations that remove or keep portions of the power spectrum,
while the term filter is used for the more general case in which some terms may be reduced in magnitude without
being eliminated. Since the filters used in the FFT plug-ins are proportional in value, and a black and white filter
can be used as an ideal mask, the distinction is ignored here. Note that circular masks or filters can also be
produced without manual drawing using the Generate Filters function below (choose annular and set the width
equal to twice the radius).
Instead of using the built-in filter shapes (ideal inverse, Hamming and Butterworth), the user can of course also
construct any desired bandpass filter. The filter is simply a grey scale image, with values that vary between black
(unity) and white (zero), typically with radial symmetry. Tools such as the Photoshop gradient tool can be used to
construct such patterns. There is also a plug-in to assist with this (Filter | IP•FFT | Bandpass). The sliders
are used much as a hi-fi equalizer to set amplitude as a function of frequency (shown in terms of pixel spacing);
the initial default is an ideal inverse filter. The filter can then applied using Filter | IP•FFT | Filter &
Inverse, or by Filter | IP•FFT | Apply Filter followed by Filter | IP•FFT | Inverse.
Thresholding (Image | Adjust | Threshold) the marked image will select just the darkest pixels
corresponding to the marked spots, after which the mask filter can be inverted (Image | Adjust | Invert)
because we want to remove the spots, and smoothed (Filter | Blur | Blur More). Performing the inverse
transform (Filter | IP•FFT | Filter+Inv.) produces the spatial domain image with the periodic noise
removed.
4.C.2. In some cases it is the periodic signal that is important. The procedure is similar. Perform the forward FT
and mark the spots representing periodic information with a black paint circle. If this is done on one-half of the
power spectrum, select Filter | IP•FFT | Symmetry to duplicate the spots for the entire area. Threshold the
spots (Image | Adjust | Threshold) and optionally smooth them (Filter | Blur | Gaussian Blur).
Then select Filter | IP•FFT | Filter+Inv. to produce the filtered spatial domain result.
In the next example, another way to create the filter mask is shown. A circular region of interest is drawn in the
same way described above (set the marquee style to Elliptical, depress the shift and option keys to draw a circle
from the center, and draw the circle so that it fits the circular array of spots that correspond to the periodic spacing
of atom planes in the image). Then convert the circular region of interest outline to a line on the image by
selecting Edit | Stroke and choosing an appropriate width. Then perform the inverse transform using this mask
(Filter | IP•FFT | Filter+Inv.) to produce an image with the periodic atom planes enhanced.
Finally, the Filter | IP•FFT | Gen Filters function will directly generate an annular filter by allowing you
to enter numbers (the fraction of the radius from center to edge of the power spectrum) for the radius and width of
the annular ring. There is likewise a sector mask selection that will generate a mask to select a range of directions,
by angle. In both cases, inverting the mask can be used to remove rather than keep the range of frequencies or
directions, and applying a Gaussian smooth to blur the edges of the mask will reduce ringing.
4.D Measurements on the power spectrum. In order to generate an annular filter, it is useful to be able
to measure the radius of the ring of spots in the Carbon image. This can be done using the Photoshop cursor and
the Info window, by reading the pixel addresses of the spots and calculating the distance to the center.
Another example of measuring spacings using the FT power spectrum is shown next. In this case, the spacing is
not perfectly regular but the average and variation in spacing and direction can still be measured efficiently from
the power spectrum.
Regularly spaced features are much more easily and accurately measured in frequency space than in the spatial
domain image. In the example (Muscle2) the striations are very faint but produce a clear point in the FFT power
spectrum (select Filter | IP•FFT | Forward FT). The location of this point averages all of the repetitive
spacing in the image and can be read from the info window by using the cursor.
Original HRTEM image Fourier power spectrum with two points marked.
Original Muscle3 image (fragment) Power spectrum with one point marked
4.F. Correlation: Fourier space is also used for locating patterns within images. Cross-correlation can be
understood most straightforwardly as an operation in the spatial domain. If the shape of a target is made into a
kernel whose values are multiplied by the pixel values at every location in the image and normalized for the
absolute values of the pixels, the largest response will result when the image contains the same pattern of grey
scale values. However, the operation is more efficiently performed in the Fourier domain by multiplying
(remembering that these are complex numbers) the transforms of the target and the image together and
performing an inverse transformation on the result. With either implementation, the locations in the image that
match the targer are found efficiently even in the presence of noise, shading, or partial obscuration of the target.
4.F.1. Cross-correlation requires two images, which need not be the same size (the program automatically
pads them to the nearest power of two). First copy the target image into memory using Setup 2nd Image.
Then select the image to be matched, and choose Filter | IP•FFT | CrossCorrelate. As shown in the
examples, the program returns the magnitude of the cross-correlation value which marks the location of matching
regions. The first example is an artificial image containing text and the second one a real image of latex spheres.
The cross-correlation technique can also be applied to color images. All of the Fourier processing routines extract
the grey scale brightness from color images to use in calculating the transforms. The example (Trees) also
illustrates the use of a feature within the image as the target. Manually draw a rectangular region of interest
around a single, well defined treetop. Select Filter | IP•2nd Image | Setup to put this region into the
second image buffer. Then remove the selection marquee (Select | Deselect) and perform the cross-correlation
(Filter | IP•FFT | CrossCorrelate). The result is a grey scale image that shows bright spots corresponding
to the tree tops, which can be processed (e.g. with a top-hat) thresholded and counted.
4.F.2. Autocorrelation is similar mathematically to cross-correlation except that the image itself is used as the
target image. This is used to find degrees of self-similarity or repetition within an image. The procedure is the
same as the cross correlation except that the same image is used as the target. Select Filter | IP•2nd Image |
Setup, then Filter | IP•FFT | Cross Correlate.
4.G. Convolution and Deconvolution: Convolution in the Fourier domain is identical in result to that in
the spatial domain, in which a kernel of values (a blur function) is applied to every pixel in the image (Filter |
IP•Process | Convolve). In Fourier space, this simply involves multiplying the transform of the blur function
with the transform of the image, pixel by pixel (select Filter | IP•FFT | Convolution). In many cases it will
be easier to construct the kernel as an image rather than as a set of numerical values.This is particularly true when
the kernel is not symmetrical. Sometimes the blur function can be measured directly by acquiring an image of a
point (e.g., a star in astronomical images). Some examples of such convolutions are shown applied to the Bug
image below.
In the examples shown, the Bug image has first been convolved with three different types of blur or “point spread
functions” (using Filter | IP•FFT | Convolution) , and then Filter | IP•FFT | Deconvolution used to
recover the original image. The first example is a symmetrical blur as might be produced by out-of-focus optics,
the second is motion blur which corresponds to a straight line (whose direction and distance must be known), and
the third example is a “positive-negative” point spread that corresponds to oblique illumination or DIC
microscopy.
Bug image blurred with symmetrical point spread function (center) and deconvolved
Bug image blurred with line (motion) function (center) and deconvolved
4.H. Half tone and moiré removal: Removal of half-tone patterns from photographs is often an important
problem to address, and processing in frequency space is a much better solution than processing such as blurring
that can hide the dots but also reduces edge sharpness. The resolution of the scanner used to input the image also
affects the high frequency noise pattern in the acquired image and can produce additional moiré patterns. This
artefact is also characteristic of grey scale images obtained from single-chip video cameras. The best method for
removing such regular patterns utilizes Fourier transforms and works in frequency space instead of the original
array of pixels in the image.
The example shows an example of an image scanned in from a newspaper; the halftone dots are very evident.
This is actually a small portion of the original image, enlarged to show the dots. In the power spectrum from a
Fourier transform, produced using Filter | IP•FFT | Forward FT, the magnitude of low frequency
information (gradually varying grey scale with position in the image) is plotted in the center of the array and high
frequency information (rapidly varying grey scale with position) is plotted at increasing radii outwards. The dark
spots ("spikes") in the power spectrum far away from the center are the indication of periodic noise in the image.
They align with the repetitive pattern of printed dots, and their darkness indicates how much of various
frequencies are present. Removing them is equivalent to removing the periodic noise. A mask was produced to
remove these spikes. This could have been done manually with the paint brush, but instead the top hat filter
discussed above was used. A small Gaussian blur was applied to the mask so that the pixels on the edges of the
holes in the mask are set to grey, which improves the results as shown before.
Mask to remove the periodic noise spikes Image with periodic noise removed
The result of applying this mask as a filter to remove the spikes (select Filter | IP•FFT | Filter+Inverse)
shows that the periodic noise has been removed without affecting any of the other information present. There is
still some pixel-to-pixel variation because the image has been scanned at a higher magnification than it was
printed. A second filter was employed to remove the remaining pixel noise. This is a Butterworth second-order
high-frequency cut-off filter (Filter | IP•FFT | Gen Filters), which keeps low frequencies (gradual
variations in grey scale) while progressively cutting off higher ones (the more rapid variations associated with
pixel noise). In this case the mid-point of the cutoff was set to the spacing of the half-tone dots in the original
image.
Tutorial Part 4 Page # 27 Fourier methods
Butterworth filter Power spectrum with both filters applied
4.H.1. The desirability of processing in frequency space is especially true for color images, in which the half-
tone patterns used for the different color planes have different orientations in order to avoid visible patterns in the
printed image. In this case, the image can be separated into RGB planes and each one subjected to an FFT,
removal of the noise peaks, and then recombining the resulting planes to form the final image. In the example
shown, the three FFT power spectra are shown as color planes as well to emphasize the different locations of the
noise peaks in each. Depending on the origin of theimage, it may be necessary to separate the image into CMY
planes.
4.I. JPEG Compression, one of the major compression techniques used in multimedia imaging, is based on
a frequency transform - the discrete cosine transform is closely related to the FFT. The power spectrum or
frequency transform is scanned and small terms are eliminated, which results in compression. For visual
reproduction, the amount of information in the few terms kept may be enough, and image storage requirements
may be reduced by a factor of 10 or more, but note that edge contrast is distorted, small details are lost, and other
artefacts appear that would seriously compromise image measurements. Photoshop supports opening and saving
JPEG images, so you can experiment with compressing images by various amounts and then re-opening them for
visual comparison. The FT power spectrum of the compressed image will show that some information has been
removed but not where. The JPEG compression method transforms separately each 8x8 pixel square in the
Tutorial Part 4 Page # 29 Fourier methods
original image and eliminates terms that have small magnitudes, but the specific terms are not the same for all
regions depending on the presence of detail there.
The loss of information in JPEG compression can also be seen by subtracting the original image from one after
compression. In the example shown the difference has been contrast expanded to emphasize these effects. Note
that edges have been displaced, features altered in texture and dimension, colors shifted, and that the brightness
offsets between adjacent 8x8 pixel blocks can be seen. In this case the compression reduced the original file size
The images shown in this tutorial have all been JPEG compressed from the original versions. This is done by
Adobe Acrobat® in order to compress the size of the “pdf” files. Many of them are also shown reduced in size.
But the original versions are on the CD-ROM and may be examined before and after processing.
4.J. The Linear Hough Transform. There are many transforms besides the familiar Fourier transform
that map the image from the spatial domain of pixels into some other space where particular kinds of information
can be extracted or processing performed. One that is quite powerful is the Hough transform. The implementation
provided as in this set of plug-ins is the Linear Hough Transform, which is useful for finding linear alignments of
points in an image. The transform uses a space with polar coordinates of angle (the slope of the line, represented
on the horizontal axis from 0 to 180 degrees) and distance (how far the line passes from the origin of the image,
which is located at the upper left hand corner of the original image, and represented on the vertical axis with a
range of ± the diagonal dimension of the image.
To execute the forward Hough transform, which maps every black (pixel value zero) point in an image into the
Hough space, first store the image of interest as the "second" image (either the Filter | IP•2nd Image |
Setup). Then create a new image (File | New) to use as the Hough space. This image does not need to be the
Tutorial Part 4 Page # 31 Fourier methods
same size as the original spatial domain, in fact it will often be much larger to provide better resolution of the ρ,θ
values for the line(s). Then select File | IP•Lines+Points | Hough(Fwd) to calculate the Hough
transform.
Single marked point in a spatial image. The forward Hough transform represents it as a sine curve.
Each pixel in the original spatial image that is black (non-black pixels are ignored) will generate a portion of a
sine curve in Hough space, corresponding to the slope and intercept values of all of the possible lines that would
pass through the original pixel location in the spatial domain image. You may experiment by marking single
points or a few points using the pencil or paintbrush tool and calculating the transforms to understand this better.
Likewise, each point in Hough space corresponds to a line in the spatial domain. The inverse Hough transform
uses the ρ,θ values of any black pixel (non-black pixels are ignored) to draw the corresponding straight lines in
the spatial domain image. To use the inverse transform, store the Hough transform image as the second image
(Filter | IP•2nd Image | Setup), select the original spatial domain image as the foreground image, and
choose Filter | IP•Lines+Points | Hough(Inv). The program will draw the lines in the current
foreground or pen color on top of the original image.
The key to the usefulness of Hough space is that when two (or more) points are present in the spatial image, their
sine curves cross each other and the locations of the crossing points identify the slope and intercept of the line that
would pass through the original points. In the example shown, there are several points (actually small circles
marked with the paint brush) that more-or-less lie on a straight line. In the Hough transform this produces a
crossover point, and the Hough space adds together all of the sine waves so the maximum value is easily found.
This is the set of ρ,θ values that identifies the line that is the "best fit" to the points.
Many points in the spatial domain. The forward Hough transform (note crossover at left).
Such alignments are sometimes easy to recognize visually, because human vision is sensitive to such things (it is
one reason that we see constellations in the night sky). But the Hough transform provides a tool to fit lines to the
data and determine the best-fit angle and position. In the Sat-1 image, for example (only a portion of the image is
shown), there is a straight feature that might be a road or fault. Processing this with a Sobel operator highlights
the disconnected pixels along the edges of the feature. Selecting a region around this feature (the Lasso tool was
used to select the region, the Select | Inverse was used to reverse the selection and the Delete key used to
erase the surrounding region) and thresholding (Image | Adjust | Threshold) to make just the pixels with a
large gradient value produced a suitable set of points for the transform. Finding the maximum value in the
transform image and using the inverse Hough transform to draw the image back onto the original Sat-1 image
shows the alignment found.
4.J.1. Hough space is also useful for measurements. The Linewidt image was processed using a horizontal
derivative, thresholded, and the Hough transform applied. In ths resulting image the four crossover points that
correspond to the vertical lines along the sides of the vertical structures in the SEM picture are clearly marked.
Even though the original image is noisy so that a continuous delineation of the edges would be difficult, the data
from many points are combined in the Hough transform space so that the separation distance between the lines
can be easily and accurately measured (the vertical spacing between the crossover maximum points). The Hough
transform image can be made as large as needed to provide the desired measurement resolution.
The Hough transform can also be used to measure orientation. In the example shown (IC image), the edges of the
device are oriented at a slight angle. Applying an edge-enhancement operator (Filter | IP•Process |
SobelMag) followed by thresholding produces an image of pixels along the edges. Making this the second
image (Filter | IP•2nd Image | Setup) and then creating a new image (File | New) whose width is 720
pixels (providing enough precision to measure the orientation accurately), followed by calculating the Hough
transform (Filter | IP•Lines+Points | Hough(Fwd), produces an image in which the bright spots that
mark the lines are found at two angles, as shown on the image. These are about 3.25 degrees less than 90 and 180
degrees, and so a rotation of the image by that amount produces good alignment. The rotation was accomplished
by duplicating the image in a layer (Layer | Duplicate Layer) and then selecting numerical rotation (Layer
| Transform | Numeric) and entering in the desired rotation value.