# Frequency-domain artifacts in generated images

Source: https://passreal.com/guides/frequency-artifacts

Transposed convolution and upsampling operate on a fixed grid, and a fixed grid imposes a periodic component on the output. In a two-dimensional Fourier transform that component appears as regularly spaced peaks away from the centre. Photographs have a smooth, roughly power-law spectrum with no such peaks, which makes the difference visible without any trained model.

## Where the periodicity comes from

Generative architectures build an image by repeatedly increasing resolution. A
transposed convolution inserts zeros between input samples and convolves; a
nearest or bilinear upsample repeats or interpolates on a fixed lattice. Either
way, the operation treats positions differently depending on where they fall
relative to a grid.

That grid dependence is periodic by construction, with a period set by the
upsampling factor. Periodic structure in the spatial domain is exactly what a
Fourier transform concentrates into isolated peaks. Stack several upsampling
stages and you get several periods, and therefore several sets of peaks at
related spacings.

The effect is not a bug that better training removes. It is a property of
building an image on a lattice, and it is why the topic has a decade of
literature behind it.

## Seeing it without a detector

The check is short enough to write from memory: read the image, convert to
greyscale, take `numpy.fft.fft2`, centre it with `fftshift`, take the log of the
magnitude, and display.

A photograph produces a bright centre with energy decaying outward, plus
whatever the scene contributes - strong axis-aligned energy from buildings,
diagonal energy from repeating fabric. It is smooth in the sense that matters:
there are no isolated bright points sitting in otherwise empty regions.

A generated image frequently shows a symmetric arrangement of those isolated
points. Once seen, they are hard to unsee, and no threshold or trained
classifier is needed to notice them.

## What compression does to them

JPEG divides high-frequency coefficients by the largest values in its
quantization table, so aggressive compression attenuates exactly the region
where these peaks live. This leads people to conclude that saving at low quality
solves the problem.

It attenuates rather than removes, and it costs visible quality in the process.
An image compressed hard enough to flatten the peaks looks compressed. The
approach also leaves a file whose compression is inconsistent with what its
metadata claims, trading one measurable oddity for another.

## Why the radial average hides things

A common shortcut is to reduce the spectrum to a one-dimensional radial profile
by averaging over all orientations at each distance from the centre. It makes
comparison across images easy and it throws away the thing being looked for.

Grid periodicity is axis-aligned. Its energy sits at a small number of specific
coordinate pairs, and averaging over orientation spreads that concentration
across an entire ring, diluting a sharp peak into a bump that may not clear the
noise. A defect living at one location becomes a barely visible rise.

The practical consequence is that a pipeline judged only on radial profiles can
look like it removed something it merely smeared. Looking at the full
two-dimensional magnitude image, unaveraged, is the check that does not lie to
you, and it takes one extra line of code.

The same reasoning applies in reverse to correction. A filter defined radially
cannot selectively address a defect that lives at one coordinate pair, because a
radial filter treats every orientation identically by construction.

## What a low-pass filter does instead

The pipeline applies a radial low-pass filter at 0.88 of the Nyquist
frequency. That attenuates the band where the periodic component sits, without
notching individual peaks - a spectrum with surgical holes in it is its own
signature, and easier to spot than the peaks were.

The sensor stage runs first, adding grain at intensity 0.018, which matters
here for a reason beyond noise floors: broadband noise raises the spectrum's
high-frequency floor, so residual peaks stand less far above their surroundings.

Lateral chromatic aberration reaching 1.25 px at the corners contributes
too, by making the channels disagree slightly about where edges are. Perfect
inter-channel registration is itself a regularity, and one that a spectrum
computed per channel will show.

There is a limit worth stating. Attenuation is not removal, and a classifier
trained on the residue after this kind of filtering can still find some of it.
The setting sits at 0.88 because lowering it removes more structure and
starts costing visible sharpness - a trade measured on real images rather than
chosen for how it sounds.

## Questions

### How do I look at the spectrum myself?

Convert to greyscale, apply a 2D FFT, shift the zero frequency to the centre and display the log magnitude. Ten lines of NumPy. Comparing a generated image and a photograph of similar content side by side makes the difference obvious without any threshold.

### What does a photograph's spectrum look like?

Broadly smooth, with energy falling off from the centre roughly as a power law, plus structure that reflects the scene: strong horizontal and vertical components in architecture, diagonal energy in a striped shirt. Scene structure varies; grid periodicity does not.

### Do these artifacts survive JPEG compression?

Partly. JPEG quantises high frequencies most aggressively, so heavy compression attenuates them. Enough survives at normal quality settings to remain measurable, which is why compression alone is not a fix.

### Is this the same as a GAN fingerprint?

Related but not identical. Grid periodicity from upsampling is common to architectures that upsample, which includes both GANs and diffusion decoders. A model fingerprint is a finer, model-specific pattern that identifies which network produced an image.

### Why not filter the peaks out precisely?

Notching individual peaks leaves its own trace: a spectrum with holes in it is as unnatural as one with spikes. A broad low-pass filter attenuates the region the peaks live in without carving a signature into the result.

Try it: https://passreal.com/app (three images free)
