Urgent.News

What's breaking now, across thousands of outlets.

Tech

Premultiplied alpha didn't remove my cutout's white fringe

A background-removed PNG dropped onto a dark page often shows a thin grey-white rim. The usual advice is to composite with premultiplied alpha. I expected that to help, measured it, and it changed nothing: on my test cutout the fringe averaged a luminance of 75.4 over black with the straight-alpha formula, and exactly 75.4 again after converting to premultiplied first. The white is not a…

Premultiplied alpha did not eliminate the white fringe around cutouts. The usual solution, compositing with premultiplied alpha, didn't help when measured. The fringe appeared as a luminance of 75.4 on the test cutout, both with straight-alpha and after converting to premultiplied. The white wasn't a compositing artifact but stored in the edge pixels.

The experiment used two white-background photos from Wikimedia Commons and a ficus cuttings in a glass bottle. The cutouts were generated using ImgIng on its fast tier, and both straight and premultiplied PNGs were compositing onto black for measurement. The matting model and edge options were not built by the user, so they were inferred from exported files.

Straight alpha keeps a pixel's color and opacity as separate values, while premultiplied alpha stores the color already multiplied by opacity. PNG requires straight alpha, but canvas and GPU pipelines often work premultiplied internally. Mixing them caused the white fringe. The fringe pixels had an average luminance of 160.1, while the opaque fur just inside the edge was at 108.6.

Every fringe pixel with alpha between 128 and 254 was within 2 of the source color, and all opaque pixels were the same. The white fringe came from the hair-thin edge where the subject color mixed with the white backdrop. The fringe was fixed by changing the data, removing the mix between the subject color and the mix. ImgIng's decontamination toggle separated the subject color from the mix but pushed the pale variegated leaf toward transparent, causing holes over black.

To fix the white fringe, check if the blend formula matches how the file is stored, and if the math is right, examine the subject before enabling decontamination.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How I turned Docker incidents into game levels (with postmortems)

Every tutorial teaches you how to start a container. Almost none teach you what to do when one is down at 3am and people are waiting.

  • "DockerLinux" game teaches Linux and Docker troubleshooting in simulated server environment.
  • Game runs in browser, replaying solutions against fresh broken servers to verify fixes.

More from Saturday 3 October →