Descreening¶
| Fact | Value |
|---|---|
| Also called | Halftone removal, Moire removal for scans, Screen removal |
| Status | Implemented and tested |
| Family | Restoration and reconstruction |
| Engine | Science engine |
| Type | Nonlinear, frequency, automatic spectral peak suppression |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | engine/src/pixelnexus_engine/filters/artifacts.py, descreen |
| Operator code | engine/src/pixelnexus_engine/filters/artifacts.py, descreen_representation |
| Packages | SciPy |
| Channels | RGB, Brightness only |
Overview¶
Descreening removes the regular dot pattern of printed halftones from scans of magazines, newspapers and printed photos. A regular pattern makes a few sharp, isolated peaks in the spectrum. The filter finds those peaks by itself, lowers them to the level of the spectrum around them, and turns the spectrum back into an image. The picture keeps its detail between the peaks. It runs in the PixelNexus engine on your computer.
How it works¶
- Extend the channel with the border mode and take its spectrum.
- For each frequency, find the highest value of the log spectrum on a ring around it.
- Mark the frequencies that stand above that ring by the threshold, far enough from the center, and widen them.
- Lower the marked frequencies to the median of their ring, keeping the phase.
- Turn the spectrum back into an image and crop it.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(L\): The log magnitude of the spectrum
- \(R(f)\): The ring of frequency bins around f, from s + 1 to half the ring size away
- \(B\): The background, the median of L on the ring
- \(P\): The peaks, widened by the spread
- \(s\): The peak spread
- \(\tau\): The peak threshold
- \(f_0\): The lowest frequency searched, in cycles per pixel
A halftone screen is a regular grid of dots. In the spectrum, a regular pattern is a set of sharp, isolated peaks at its frequency and its harmonics. The image itself also has strong features in the spectrum, but they are lines and rings: an edge makes a line, a disk makes rings. So the filter compares the log magnitude L at each frequency with the highest value on a ring R(f) around it. The ring runs from s + 1 to half the ring size away. A point on a line or a ring has neighbors on R(f) as high as itself, so only isolated peaks stand above all of R(f). Cores that stand more than tau above, at least f0 cycles per pixel from the center, are widened by a square D_s of s bins. Their magnitude is lowered to B, the median of L on the ring. The phase is kept, so the rest of the image keeps its place. This is a notch filter as in Gonzalez and Woods, with the notches found automatically. The rule for finding peaks is PixelNexus's own. The spectrum is symmetric and every step treats f and -f alike, so the result is real.
A screen is periodic, so its spectrum is a lattice of isolated peaks: the screen frequency and its harmonics. The spectrum of the picture is not flat either. Edges make lines through the center and round shapes make rings. A simple rule, such as everything far above a median background, mistakes those lines and rings for a screen and damages the picture. The isolation test avoids that. A point on a line or a ring has neighbors on the surrounding ring that are as high as itself, while a screen peak stands above all of them. This is notch filtering, as in Gonzalez and Woods, with the notches placed automatically. The peak rule is PixelNexus's own. A binary screen also leaves broadband noise that no notch removes, so a scan stays a little grainy.
Kernel or operator¶
The Inspector asks the engine for the stages with the current settings: the log spectrum, the peak test with its ring, and the suppression.
Algorithm¶
- Extend the channel with the border mode and take its FFT.
- Compute the log magnitude, and its highest value and median on the ring around every bin, with wrap-around.
- Mark the bins that stand above the highest value on their ring by the threshold, above the lowest frequency, and widen them.
- Lower the magnitude at the peaks to the median on the ring and keep the phase.
- Take the inverse FFT and crop to the image.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Output output |
Cleaned image | Cleaned image, Removed pattern | The cleaned image, or what was removed, around a mid gray of 128. |
Peak threshold threshold |
0.5 | 0.1 to 4 | A frequency is the core of a peak where its log magnitude is this much above the highest value on the ring around it. 0.5 means about 1.6 times as large. |
Lowest frequency minRadius |
0.1 | 0.01 to 0.45 cycles/px | Peaks are looked for only at this frequency or above, so the broad shapes of the image are safe. 0.1 is a period of 10 pixels. |
Ring size window |
41 | 9 to 81 | The outer diameter of the ring each frequency is compared with, in frequency bins. |
Peak spread spread |
5 | 0 to 10 | Each peak core is widened by this many frequency bins in every direction. The ring starts at the spread plus 1. |
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¶
descreen in engine/src/pixelnexus_engine/filters/artifacts.py runs descreen_plane on each channel the scope names. peak_mask builds the ring with ring_footprint and uses the maximum and median filters of scipy.ndimage with wrap-around, since the spectrum is periodic. All steps treat a frequency and its mirror alike, so the result is real. There is no live preview. The result arrives when you click Apply.
Worked example¶
| Scan | Scan | Descreened | Gaussian, sigma 2 |
|---|---|---|---|
| Disks, period 6, 45 degrees | 17.42 | 22.32 | 24.10 |
| Disks, period 5, 15 degrees | 19.65 | 22.93 | 24.23 |
| Siemens star, period 6, 45 degrees | 16.19 | 20.19 | 22.23 |
| Siemens star, period 5, 15 degrees | 18.91 | 22.84 | 22.42 |
The PSNR in dB against the image under the scanner blur alone. Each scan is a clustered-dot screen of the image, with the period in pixels and the angle given, blurred with a Gaussian of sigma 1.2 as a scanner would. Both images are 160 by 160 pixels. By PSNR, descreening with the defaults stays a little behind a Gaussian blur of sigma 2 on three of the four scans. The dots of a binary screen also leave broadband noise, which no notch can remove, while the blur removes some of it. On the disks and the Siemens star without a screen, the filter changes no pixel at all, since their spectra hold lines and rings, not isolated peaks.
Complexity¶
- Time: \(O(N log N + N w^2)\)
- Memory: \(O(N)\)
N is the number of pixels of the extended image and w the ring size. The maximum and median filters over the ring dominate.
Artifacts and limitations¶
Limitations
- A binary halftone has broadband dot noise besides its peaks, and that noise stays.
- Fine regular textures in the image itself, such as fabric or grids, can be taken for a screen.
- By PSNR it is about as good as a Gaussian blur on the test scans. See the worked example.
Artifacts
- Faint ripples near strong edges, since peaks are removed in a hard-edged way.
- Weak remains of the screen where the peaks were below the threshold.
Tests¶
A disk with a two-way cosine screen must come back to within 30 dB, and the removed output must match the screen. Images without a screen, a soft disk, a Siemens star and a photo-like image, must change by less than half a level. The engine API tests run jobs and check the stages of the representation.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 4, filtering in the frequency domain.