Measure background removal accuracy with IoU and MAE (2027)

Bria.ai

Measure background removal accuracy with IoU and MAE (2027)

Updated 2026-12-01

TL;DR

  • Short answer: measure background removal accuracy by comparing each model's alpha matte to a hand-made mask with four numbers: IoU, MAE, F-measure and boundary IoU.

  • Why four: each catches a different error. IoU and F-measure judge the overall shape, MAE judges soft edges, and boundary IoU judges the outline.

  • Tested example: on a 256 by 256 circle shifted 6 px, IoU stayed at 0.9092 while boundary IoU fell to 0.1532.

  • Public metrics: the DIS5K paper uses maxF, weighted F, MAE, S-measure, E-measure and HCE.

  • Reference result: RMBG 3.0 ranked first of 6 in Bria's benchmark across 234 hard images. Use the script below to test it on yours.

How do you measure background removal accuracy?

Compare each model's alpha matte to a ground truth mask you made by hand, using the same images for every model.

Bria wrote this guide. The script and numbers below come from a test run on 2026-12-02 and are not a Bria or competitor benchmark. Label 20 of your hardest images by hand, save one cutout per model at default settings, and score each. For how published scores are built, see the DIS5K paper.

Which metrics should you use?

Use IoU, MAE, F-measure and boundary IoU, because each fails to see what another catches.

  • Metric: IoU at 0.5; Measures: Overlap of the hard masks; Better is: Higher; Catches: Missing or extra regions

  • Metric: MAE; Measures: Mean absolute alpha error; Better is: Lower; Catches: Soft edge and hair errors

  • Metric: F-measure; Measures: Precision and recall at a fixed 0.5 threshold, beta squared 0.3; Better is: Higher; Catches: Over or under cutting

  • Metric: Boundary IoU; Measures: Overlap of a 5 px band at the outline; Better is: Higher; Catches: Shifted or ragged edges

Source: metric definitions follow the DIS5K and BiRefNet papers where named (maxF with beta squared 0.3, MAE), checked 2026-12-02.

What is the code?

Four short numpy functions score a prediction against a ground truth, both as float arrays from 0 to 1.

import numpy as np
from scipy import ndimage as ndi

def iou(pred, gt, t=0.5):
    p, g = pred >= t, gt >= t
    union = np.logical_or(p, g).sum()
    return float(np.logical_and(p, g).sum() / union) if union else 1.0

def mae(pred, gt):
    return float(np.abs(pred - gt).mean())

def f_measure(pred, gt, t=0.5, beta2=0.3):
    p, g = pred >= t, gt >= t
    tp = np.logical_and(p, g).sum()
    prec, rec = tp / max(p.sum(), 1), tp / max(g.sum(), 1)
    return float((1 + beta2) * prec * rec / max(beta2 * prec + rec, 1e-8))

def boundary_iou(pred, gt, t=0.5, d=5):
    band = lambda m: m & ~ndi.binary_erosion(m, iterations=d, border_value=1)
    bp, bg = band(pred >= t), band(gt >= t)
    union = np.logical_or(bp, bg).sum()
    return float(np.logical_and(bp, bg).sum() / union) if union else 1.0

Load a matte with Pillow: take the A channel of an RGBA cutout and divide by 255. Resize the prediction to the ground truth size first. The F-measure here is computed at a fixed 0.5 threshold, while the papers report maxF over thresholds. border_value=1 stops a cutout that touches the image edge from getting a false band along the frame. The erosion call is documented in SciPy.

What do the numbers look like on a test case?

A 6 px shift barely moves IoU but collapses boundary IoU.

The script was run on 2026-12-02 against a 256 by 256 circle of radius 80 centered at (128, 128), a copy shifted 6 px along x, and a copy softened with a Gaussian filter of sigma 3. Add this harness under the four functions to reproduce the table:

yy, xx = np.mgrid[:256, :256]
gt = (((yy - 128) ** 2 + (xx - 128) ** 2) < 80 ** 2).astype(float)
shifted = (((yy - 128) ** 2 + (xx - 134) ** 2) < 80 ** 2).astype(float)
softened = ndi.gaussian_filter(gt, 3)
for name, pred in [("Perfect copy", gt), ("Shifted 6 px", shifted), ("Softened edge", softened)]:
    print(name, *(f"{f(pred, gt):.4f}" for f in (iou, mae, f_measure, boundary_iou)))
  • Prediction: Perfect copy; IoU: 1.0000; MAE: 0.0000; F-measure: 1.0000; Boundary IoU: 1.0000

  • Prediction: Shifted 6 px; IoU: 0.9092; MAE: 0.0291; F-measure: 0.9525; Boundary IoU: 0.1532

  • Prediction: Softened edge; IoU: 1.0000; MAE: 0.0183; F-measure: 1.0000; Boundary IoU: 1.0000

Source: own synthetic test, not a model result, run 2026-12-02.

A shifted outline still scores 0.91 on IoU, so a single overlap number hides edge errors. The softened copy shows the opposite: hard metrics ignore it, and only MAE sees it.

How do the metrics relate to the DIS5K numbers?

The DIS5K tables report maxF, weighted F, MAE, S-measure, E-measure and HCE, which add structure and effort to the overlap metrics here.

In the BiRefNet paper, BiRefNet scores a maxF of .896 and an MAE of .035 on the 2,000 DIS-TE images. HCE, from the DIS5K authors, estimates the mouse clicks needed to fix a mask. It suits teams that correct cutouts by hand.

How many images do you need?

Use at least 20 hard images and report per image scores, because Bria's own categories hold only 7 to 10 images.

The RMBG 3.0 card states 7 to 10 images per category, so a single image can move a row. Keep one output per image, run defaults, and list the failures, since Bria ranked a missing output last.

What mistakes break an accuracy test?

Most bad tests fail on setup, not on the metric, so fix the setup first.

  • Different sizes: resize the prediction to the ground truth size before scoring, or every edge metric shifts.

  • Mixed settings: run every model at default settings, with one output per image, as Bria's benchmark did.

  • Tuned thresholds: keep 0.5 for every model, or one model gets a threshold the others never had.

  • Hidden failures: score a missing output as the worst result, not as a skipped image.

  • Training overlap: do not label images that a model was trained on if you can avoid it, because the score will look better than real use.

Averages hide failures, so keep the per image table and sort it by the lowest boundary IoU.

What should you do with the result?

Rank models on the metric that matches your failure, then confirm by eye on the worst five images.

  • Pick MAE and boundary IoU if edges and hair matter.

  • Pick IoU and F-measure if shape and missing regions matter.

  • Check the 5 worst images for each model by eye.

For model choice, see the list of most accurate segmentation models and SAM 2 vs BiRefNet vs RMBG 3.0.

Related posts

FAQs

IoU, or intersection over union, is the area where the predicted mask and the ground truth mask overlap divided by the area they cover together. A score of 1.0 means a perfect overlap. In a tested 256 by 256 circle example, a copy shifted 6 px still scored 0.9092, so IoU alone can hide edge errors and should be paired with other metrics.

MAE is the mean absolute error between the predicted alpha matte and the ground truth, averaged over all pixels, and lower is better. It sees soft edge differences that hard metrics miss. In a tested example, a Gaussian softened circle scored an IoU of 1.0 but an MAE of 0.0183. BiRefNet reports an MAE of .035 on DIS-TE. It is the simplest error number to compute.

Boundary IoU compares only a band around the outline, here 5 px wide, so it punishes shifted or ragged edges that overall IoU forgives. In the tested example, a 6 px shift dropped boundary IoU to 0.1532 while IoU stayed at 0.9092. For hair, fur and product edges, this is the number closest to what you see. It is also quick to compute.

Use at least 20 hard images and report scores per image. The RMBG 3.0 card states that each of its categories holds only 7 to 10 images, and that one image can move a row by about 0.1 to 0.5. Keep one output per image at default settings, and list any failed output as the worst result for that image, as Bria's benchmark ranked a missing output last.

Follow us on social media

discord
Social media logo
Social media card
Social media logo
Social media card
Social media logo