Comb filter¶
| Fact | Value |
|---|---|
| Also called | Harmonic notch filter, Comb notch filter |
| Status | Implemented and tested |
| Family | Frequency-domain filters |
| Engine | Browser |
| Type | Linear, frequency, frequency response |
| Output | Image |
| Operator shown as | frequency-response (exact) |
| Support radius | global |
| Code | web/src/core/filters/frequency/notch.ts, combFilter |
| Operator code | web/src/core/filters/frequency/notch.ts, harmonics |
| Channels | RGB, Brightness only |
Overview¶
The comb filter removes a periodic pattern together with its harmonics. A pattern with sharp edges, such as bars or scan lines, is not a pure wave. It makes peaks at a base frequency and at whole multiples of it. The comb places a notch on each multiple, so one setting removes the whole pattern.
How it works¶
- Read the base frequency of the pattern in the Spectrum panel.
- The filter places notches at 1, 2, 3 and more times that frequency, up to the chosen count.
- It removes those regions of the spectrum, with their mirror points, and transforms back.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \((f_{x0}, f_{y0})\): The base frequency in cycles per pixel
- \((u_k, v_k)\): The center of harmonic k
- \(H_k\): The high-pass factor of the notch at harmonic k and its mirror points
The comb filter is a notch-reject filter whose notches sit at k times the base frequency, up to the chosen count. Harmonics whose fx or fy passes 0.5 cycles per pixel are left out. Each harmonic is notched at its mirror points too, as in the notch-reject filter. Gonzalez and Woods build notch filters from high-pass factors. Placing them on harmonics is this filter's own convenience.
Bars of 4 light and 4 dark pixels form a square wave with period 8. A square wave holds the odd harmonics of its base frequency, here 0.125, 0.375 and so on, with falling strength. The comb is a notch-reject filter with notches at k times the base frequency, as long as both parts stay within 0.5 cycles per pixel. Placing the notches on harmonics is this filter's own convenience. The reflect and reflect 101 border modes mirror the image at its edges. So a pattern at (fx, fy) also shows up in the extension at (-fx, fy). For these modes each notch also acts at (-fx, fy) and (fx, -fy). The Spectrum panel draws those points as dashed rings.
Kernel or operator¶
The operator is the response H with its row of notches. The Inspector draws it, and the Spectrum panel tints it on the spectrum of the image.
Algorithm¶
- Extend the image with the border mode by half its size, at most 256 pixels, on each side.
- Take the 2D FFT.
- Multiply each frequency by H.
- Take the inverse FFT and keep the real part.
- Crop the extension.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Base frequency x fx |
0.125 | -0.5 to 0.5 cycles/px | The base frequency along x, in cycles per pixel. A pattern of vertical lines every 8 pixels has 0.125. |
Base frequency y fy |
0 | -0.5 to 0.5 cycles/px | The base frequency along y, in cycles per pixel. A pattern of horizontal lines every 4 pixels has 0.25. |
Harmonics harmonics |
3 | 1 to 20 | How many multiples of the base frequency get a notch. Multiples past 0.5 cycles per pixel are left out. |
Notch shape shape |
Butterworth | Ideal, Butterworth, Gaussian | The shape of each notch, as for the low-pass and high-pass filters. |
Notch radius radius |
0.01 | 0.002 to 0.1 cycles/px | The radius D_0 of each notch, in cycles per pixel. |
Order order |
2 | 1 to 10 | The order n of Butterworth notches. Other shapes ignore it. |
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 |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
combFilter in web/src/core/filters/frequency/notch.ts lists the harmonics with harmonics and builds H with notchResponse. 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 spectrum of the extended image is multiplied by H. The filter needs the whole spectrum, so it always runs on the whole image, and a selection is cut out of the result. A pattern that does not fit the image a whole number of times is cut off at the image edges. Its peak then leaks into nearby frequencies, so a little of the pattern stays near the edges.
Worked example¶
| Harmonic k | Center (fx, fy) | H at the center | H halfway to the next |
|---|---|---|---|
| 1 | (0.125, 0) | 0 | 1 |
| 2 | (0.250, 0) | 0 | 1 |
| 3 | (0.375, 0) | 0 | 1 |
The base frequency (0.125, 0) with 3 harmonics gives notches at 0.125, 0.25 and 0.375 cycles per pixel and at their mirror points, 6 centers in all, since harmonics on the x axis have no separate mirror points across the axes. Between the harmonics H is close to 1.
Complexity¶
- Time: \(O(N log N + N K)\)
- Memory: \(O(N)\)
N is the number of pixels of the extended image and K the number of notch centers.
Artifacts and limitations¶
Limitations
- The base frequency must be known. Read it from the Spectrum panel.
- A pattern that does not fit the image a whole number of times leaks around its peaks, so some of it stays near the image edges.
Artifacts
- Faint waves near the image edges where the pattern was cut off.
Tests¶
The reference lists the same harmonics and builds the same product with NumPy. The cases cover an oblique base frequency, a vertical one and three notch shapes.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/frequency/frequency.test.ts
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 4, filtering in the frequency domain.