bilateral filter
The bilateral filter smooths an image while keeping edges crisp, by being choosy about which neighbours it averages. A plain Gaussian blur averages a pixel with all its neighbours by distance alone, so it inevitably bleeds bright and dark regions into each other across edges. The bilateral filter adds a second condition: a neighbour only contributes strongly if it is both spatially close and similar in brightness to the center pixel. Across a sharp edge the neighbours on the other side are very different in value, so they are down-weighted to nearly zero, and the edge survives.
Formally the output at pixel p is a normalized weighted average over neighbours q: output(p) = (1/W) * sum over q of G_s(distance from p to q) * G_r(|I(p) - I(q)|) * I(q), where W is the sum of the weights. There are two Gaussians: a spatial kernel G_s with width sigma_s controlling how far the filter reaches, and a range (intensity) kernel G_r with width sigma_r controlling how much brightness difference is tolerated before a neighbour is rejected. Large sigma_r makes it behave like an ordinary Gaussian; small sigma_r makes it strongly edge-preserving. It is nonlinear (the weights depend on the image content) and non-iterative.
The bilateral filter underpins tone mapping (smoothing the base layer of HDR images while keeping detail), detail enhancement, and denoising. Done naively it is slow, O(N * r^2) for radius r, so fast approximations such as the bilateral grid and the permutohedral lattice are used. It is not flawless: it can produce gradient reversal artifacts (overshoot near edges) and a staircase or cartoon effect on smooth gradients, where a continuous ramp breaks into flat plateaus. It belongs to a family of edge-aware methods including anisotropic diffusion, non-local means (which compares whole patches, not single pixels), and the guided filter (which is faster and avoids gradient reversal).
Beautifying a portrait: a bilateral filter with moderate sigma_s and small sigma_r smooths skin pores (small intensity variations) into porcelain while leaving the high-contrast boundaries of eyes, lips, and hair perfectly sharp.
Pitfall: sigma_r is defined in intensity units, so it must match your data range, a value tuned for 0-255 images behaves completely differently on 0-1 floating-point images. Mis-scaling sigma_r is the most common reason a bilateral filter either does nothing or blurs everything.