Skip to content

Phase-only filter

Fact Value
Also called Phase-only reconstruction, Phase only image
Status Implemented and tested
Family Frequency-domain filters
Engine Browser
Type Nonlinear, frequency, phase normalization
Output Image
Operator shown as algorithm (exact)
Support radius global
Code web/src/core/filters/frequency/shaping.ts, phaseOnlyFilter
Operator code web/src/core/filters/frequency/shaping.ts, phaseOnlyValues
Channels Brightness only, RGB

Overview

The phase-only filter keeps the phase of every frequency and gives them all the same magnitude. What remains are the edges and lines of the image. It shows that the phase of a spectrum carries much of what makes an image recognizable, a classic result of Oppenheim and Lim.

Four panels: disks, their phase-only result with bright outlines, a Siemens star, and its phase-only result with the spokes outlined. Four panels: disks, their phase-only result with bright outlines, a Siemens star, and its phase-only result with the spokes outlined.
The phase-only filter keeps the edges of the disks and the spokes of the star.

How it works

  1. Transform the image with the FFT.
  2. Set the magnitude of every frequency to the mean magnitude, and keep its phase.
  3. Transform back. Edges and lines remain.

Mathematical foundation

\[ P(f) = M \frac{F(f)}{|F(f)|},\quad g = \operatorname{Re} \mathcal{F}^{-1}\{P\} \]

The formula shows the default parameter values.

where

  • \(F\): The spectrum of the extended image
  • \(M\): The mean magnitude of F
  • \(P\): The spectrum with every magnitude set to M

F is the spectrum of the image extended with the border mode, and M its mean magnitude. Every frequency keeps its phase and gets the magnitude M. Oppenheim and Lim showed that the phase holds most of what makes an image recognizable, so the result still shows the edges and lines. Using M keeps the scale of the image. Magnitudes below 1e-9 times the largest count as 0, so frequencies that a mirror extension makes 0 stay 0 instead of turning rounding noise into content.

Each frequency F(f) is a magnitude |F| and a phase. The magnitude says how strong a wave is, and the phase where it sits. Edges are places where many waves line up in phase. Natural images have much more magnitude at low frequencies. Setting every magnitude to the same value raises the high frequencies, so only the places where waves line up stand out. The filter uses the mean magnitude M, so the result keeps the scale of the image. Magnitudes below 1e-9 times the largest count as 0. A mirror extension makes some frequencies exactly 0, and scaling their rounding noise up would add false content.

Kernel or operator

The gain depends on the image, so the Inspector lists the stages. The Frequency explorer shows the gain on the patch.

Algorithm

  1. Extend the image with the border mode by half its size, at most 256 pixels, on each side.
  2. Take the 2D FFT.
  3. Divide each frequency by its magnitude and multiply it by the mean magnitude.
  4. Take the inverse FFT and keep the real part.
  5. Crop the extension.

Parameters

Parameter Default Values Meaning
Output mapping outputMapping Stretch to full range Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 How signed results, such as gradients, become 8-bit pixel values.
Border mode border Reflect Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope Brightness only RGB, Brightness only Which part of the color image the filter changes.

Implementation

phaseOnlyFilter in web/src/core/filters/frequency/shaping.ts computes the gains with phaseOnlyValues. As for the other frequency filters, the image is extended with the border mode by half its size, at most 256 pixels, on each side. The filter needs the whole spectrum, so it always runs on the whole image, and a selection is cut out of the result.

Worked example

x 10 11 12 13 14 15 16 17 18 19 20 21
Input 40 40 40 40 40 40 215 215 215 215 215 215
Phase only, stretched 93 121 119 51 0 62 193 255 204 136 134 162

One row of a step edge, 32 pixels wide, before and after the phase-only filter, stretched to the full range. The flat parts move to a middle gray, and the result swings most at the step, where the edge is.

Complexity

  • Time: \(O(N log N)\)
  • Memory: \(O(N)\)

N is the number of pixels of the extended image, about 4 times the image for images up to 512 pixels on a side.

Artifacts and limitations

Limitations

  • Noise gets the same magnitude as image detail, so noisy images give noisy results.
  • The result has a new range of values, so it needs the output mapping.

Artifacts

  • A fine, grainy texture from the raised high frequencies.

Tests

The reference extends the plane with numpy.pad, filters it with numpy.fft and crops it. The same rule for magnitudes that count as 0 is used. Before the cases are written, the script checks that every frequency gets the mean magnitude.

References

  • Oppenheim, A. V. and Lim, J. S. The importance of phase in signals. Proceedings of the IEEE 69(5), 529 to 541, 1981. DOI 10.1109/PROC.1981.12022.