DEV Community

DeepSwapAI
DeepSwapAI

Posted on

How many pixels a face needs before a swap stops working

Every face swap has a floor, and it is measured in pixels rather than in quality settings. Below a certain number of pixels across the face, the model has nothing to align to: the eyes are two dark smudges, the jaw is a gradient, and whatever it produces is a guess wearing the right colour. Above it, the same model looks suddenly competent. The gap between those two results is not a better model. It is arithmetic.

What a swap actually consumes

A face swap needs landmarks before it needs texture: eye corners, nose tip, mouth corners, jaw contour. Those landmarks are located on a grid, and the grid is the image. If the whole face is 40 pixels wide, the distance between the two eye centres is maybe 14 pixels, and a landmark detector has to place a point to within one or two pixels to keep the pose estimate sane. At that scale a single pixel of error is a seven percent error in the interocular distance, which is enough to rotate the head a few degrees in the wrong direction.

Most detectors work on a fixed input size, commonly 112 or 128 pixels square for the recognition stage, and a few hundred for the alignment stage. So a face that arrives at 90 pixels gets upscaled to meet that input, which invents detail rather than recovering it. The face that arrives at 400 pixels gets downscaled, which is lossless by comparison. This is why a swap on a small face is not merely softer; it is placed on the wrong geometry.

The numbers that matter

As a working rule, count pixels from the chin to the top of the forehead, hairline excluded:

  • Under 60 px: the swap is a mask. Fine in a crowd shot at thumbnail size, useless in anything you can zoom.
  • 60 to 120 px: pose is roughly right, identity is approximate, teeth and eyes are painted. Acceptable for a background face in a group photo.
  • 120 to 250 px: the normal working range for phone video and casual photos. Most visible failures here are texture and lighting, not geometry.
  • 250 to 600 px: close-up portrait territory. Now the source photo's own resolution and sharpness become the limit, not the target.
  • Above 600 px: pores, vellus hair and the wet line of the lower eyelid are being redrawn. Anything the source does not contain has to be invented, and invention is where the uncanny part lives.

These are not vendor specifications, they are the thresholds at which different kinds of error become visible. Two different photos of the same face at 150 px and 500 px will fail in completely different ways.

Where the pixel budget is spent

A frame is a fixed budget, and the face only gets a share of it. In a 1080p group photo of eight people, each face might get 150 pixels across, which is enough. Crop the same photo to a single person and the face is still 150 pixels but now fills the frame, so the viewer's eye expects 800. That mismatch between what the file contains and what the composition promises is the most common reason a high resolution photo produces a soft swap.

Video makes it worse in a way people rarely check: a 4K clip downscaled for delivery, or a phone that records 1080p but stores a 720p preview, gives the model a different face than the one the viewer eventually sees. If the swap runs on the preview and the delivery is the original, the face is both too small and too soft.

What to do about it

  1. Measure before you swap. Open the photo, zoom to the face, and count the chin-to-forehead pixels once. It takes ten seconds and predicts the result better than any settings panel.
  2. Crop and swap at full size, then scale down. A swap performed on the largest available version of the face and then resized to delivery keeps the geometry honest. Doing it the other way round bakes the error in.
  3. Match the source to the target scale. If the target face is 140 pixels, a 4000-pixel studio portrait is not automatically better: it will be downscaled to the same working size, but its lighting and sharpening will not match. A source shot at a similar distance and lens reads better.
  4. Keep the face away from the frame edge. Cropped faces lose landmarks at the jaw and the temple, and the pose estimate drifts. Give the detector the whole head, ears included.
  5. Do not upscale before the swap. Interpolated pixels carry no new information, and some detectors are confused by the smoothed edges an upscale leaves behind. Upscale after, if you need a bigger export.

The useful mental model is that a face swap is a reconstruction, and reconstruction needs samples. Fewer than about a hundred samples across the face and the model is guessing at the thing you are asking it to be exact about. The rest of the pipeline (lighting, colour, edge blending) only starts to matter once that floor is cleared.

To try it on photos, video and GIF with batch and multi-face scenes, HD output and no watermark, it runs in the browser at deepswapai.com.

Top comments (0)