Cut objects out
SAM outlines whatever you click, offering three guesses. A background remover finds the main subject by itself.
Your photos and camera frames are processed on this device and never uploaded.
Loading the recorded results
SAM 2.1 tiny reads each picture once (the slow part) and then outlines every click in a fraction of a second. BiRefNet lite needs no clicks.
Challenges
0 of 4 complete
- With a single click, get three candidate masks where the largest is at least ten times the size of the smallest. (not yet)
- Show a mask that fills less than half of its own bounding box. (not yet)
- Find a click where SAM rates even its best mask below 50%. (not yet)
- Find a photo where the subject finder keeps nothing at all. (not yet)
Try this
- On the dog, click the collar, then the head, then the lawn. Compare SAM’s three guesses each time.
- Show the whole dog and read how much of its own box it fills.
- Try a pillar in the corridor or the plum branch in the print, and read SAM’s rating of its best mask.
- Switch to Find the subject and try every sample photo. Which ones come back empty?
Masks, IoU, and a soft cut-outPython with NumPy
import numpy as np
# The true outline of an L-shaped object in a 6 x 8 picture (True = object).
truth = np.zeros((6, 8), dtype=bool)
truth[1:5, 2] = True # the upright
truth[4, 2:7] = True # the foot
def iou(a, b):
"""Intersection over union: overlap divided by the area either one covers."""
return (a & b).sum() / (a | b).sum()
# Two guesses: just the upright, and the whole L plus one stray pixel.
upright = np.zeros_like(truth)
upright[1:5, 2] = True
whole = truth.copy()
whole[0, 7] = True
print(f"upright: IoU {iou(upright, truth):.2f}")
print(f"whole: IoU {iou(whole, truth):.2f}") # SAM predicts this number for each guess
# How much of its own bounding box the object fills.
rows, cols = np.nonzero(truth)
box = (rows.max() - rows.min() + 1) * (cols.max() - cols.min() + 1)
print(f"the L fills {truth.sum() / box:.0%} of its box")
# Cutting out with a soft matte: each pixel mixes the photo and a new backdrop.
alpha = np.array([0.0, 0.3, 1.0]) # background, a wisp of hair, subject
photo, backdrop = 200.0, 50.0 # brightness of one photo pixel and the backdrop
print("composite:", alpha * photo + (1 - alpha) * backdrop)upright: IoU 0.50
whole: IoU 0.89
the L fills 40% of its box
composite: [ 50. 95. 200.]Sample photos, all CC0 on Wikimedia Commons: Dog by Joselodos; Cat by Vyshnavi medicharla; Cat on a motorcycle by CAPTAIN RAJU; Breakfast by Andy Li; Street by Mucklagh; Cafe by Andy Li; Corridor by Sindugab; Woodblock print by Utagawa Hiroshige (Metropolitan Museum of Art).