DEV Community

hao jia
hao jia

Posted on

When the matting answer key is a bigger model, a hair error of 54 measures the outline, not the strands

A hair-edge error of about 54 on a 0–255 alpha scale reads like a verdict on the model under test. It is only a verdict if the thing it was compared against was right, and without a hand-pulled matte there is nothing that is right by construction. The convenient shortcut is to treat a larger, slower model as the answer key. A mask-upsampling measurement run on 2026-11-13 took that shortcut, and the answer key turned out to have a blind spot of its own.

The answer key was another model

The pipeline is the in-browser background removal of ImgIng https://imging.ai/ . Its loaded model config gives the fast tier ISNet INT8 at a 1024×1024 input and the top tier BiRefNet HR-Matting FP16 at 2048×2048, and the mask is stretched back to the photo size on export. Area downscaling of a 2048×2048 portrait produced the test inputs, with sides of 768, 1024, 1440 and 1920 px. The model under test was that ISNet INT8 file, run locally with ONNX Runtime at 1024, its mask upsampled back to each size. The reference was the top tier's output on the 2048 original, shrunk by area to each size. It has twice the input resolution and is still a model's guess. The portrait is "Windblown" by Kaci Baum, CC0, via Wikimedia Commons. Every number below comes from that one portrait, one Apple silicon Mac and one run per setting.

The score is a mean absolute alpha difference inside a hair band, which the reference alone decides: its semi-transparent pixels (0.02 to 0.98) and a ring of about 2 px around them. Whatever the reference calls hair gets scored, and whatever it misses is never looked at.

Even the 2048 reference merged the stray strands

Lay the hair crop beside its masks and the blind spot is plain. Single strands blowing loose outside the head are visible in the photo crop, yet no mask separates them, the reference included. Every mask draws that region as one soft clump. So the band traces the edge of the clump, and 54 says the two models disagree on where that outline sits and how dense it is. It says nothing about individual strands, because no mask in the comparison contains any.

The sparse-hair numbers agree. On pixels where the reference alpha is between 0.05 and 0.6, the fast model's alpha summed to 144.4% to 149.1% of the reference across the four sizes. It paints the thin fringe more solid, carrying some background between strands along with it. Whether the truth is nearer 100% or 145% this setup cannot answer, because that needs a real matte that was never made here.

An ideal-model control splits the two terms

The useful trick is to push the reference through the same resize path: shrink it to 1024, upsample it back, and score it against itself. Only the round trip is left. Below is a simplified sketch written from that definition; the numbers come from the full script, not from these lines.

key_1k = cv2.resize(key_alpha, (1024, 1024), interpolation=cv2.INTER_AREA)
key_back = cv2.resize(key_1k, (w, h), interpolation=cv2.INTER_CUBIC)
fringe = hair_band(key_alpha)        # 0.02 < a < 0.98, grown ~2 px
round_trip = np.abs(key_back - key_alpha)[fringe].mean() * 255
Enter fullscreen mode Exit fullscreen mode

At 1024 the control scored 0.00, as it must when nothing is resized; a harness that misses zero there needs fixing first. At 768 it was 0.89. At 1440 bilinear gave 1.51 and bicubic 0.73, and at 1920 the pair was 1.43 and 0.79. The fast model against the reference gave 51.57, 55.32, 53.85 and 54.22 at the same four sizes, with bicubic within 0.01 of bilinear. At 1920, pixels off by more than 25 were 53.22% of the band for the fast model and 0.02% for the control.

So the resolution term is around 1 and the disagreement term is around 54, and the second does not climb from 768 to 1920. On this portrait that rules out the resize as the place where the outline goes wrong. It does not make the fast model 54 points worse at hair. It puts it 54 points away from one other model, on an outline both of them drew.

The answer key also grades your filters

A guided filter (photo RGB as guide, radius 2×side/1024, eps 1e-4) was the candidate upgrade over a plain resize. With the fast model it scored 53.38 to 55.96, no better than bilinear. With the ideal control it rose to between 11.42 and 14.96. A nine-setting sweep at 1920 found the best control result at r=1, eps=1e-2, scoring 2.67, still behind bicubic at 0.79.

My reading is an inference that nothing here tested. The reference has crisp edges, so any step that softens edges gets marked down whether or not real hair is softer. Against a true matte the ranking might change, or might hold. Per-region tuning and trimap refinement were not tried.

Label the number before quoting it

Wherever the figure gets quoted, name it for what it is: agreement with BiRefNet HR-Matting at 2048 on the outline of the hair mass, one portrait. Put the ideal-model control in the next column so the round-trip cost sits beside the model gap. Leave strand-level claims out until a reference actually contains strands, a hand-pulled matte or a synthetic composite with known alpha. And list what was not covered: sizes above 1920, the pro tier, and any other photo.

Top comments (0)