Use MediaPipe’s body segmentation model to cut your live silhouette out of the webcam feed and composite it over a generative background in real time. No alpha channel juggling - just masks, multiplies, and an Add.
Operator Families in this Recipe
- TOPs (Texture Operators): Webcam input, masking, and compositing.
- COMPs (Component Operators): The MediaPipe plugin container.
Before You Start
You need the free MediaPipe TouchDesigner plugin (mediapipe.tox) by Torin Blankensmith and Dom Scott. Download it from github.com/torinmb/mediapipe-touchdesigner. Drop the .tox file into your network - no Python installation needed.
Part 1: Camera and MediaPipe Setup
- Add a Video Device In TOP and set Device to your webcam. Connect to a Null TOP named
CAM. - Drag
mediapipe.toxinto the network. - Connect
CAMto the first input ofmediapipe1. - In
mediapipe1parameters, set Model toSelfieSegmentation. - Enable Image Segmentation.
Finding the Mask Output
Click the small triangle on
mediapipe1to expand its output pins. The Selfie Segmentation mask is a separate output slot - white = person, black = background. If it shows all-black, wait a second for the model to warm up.
Part 2: Clean the Mask
Raw segmentation masks have rough, flickery edges.
- Connect the mask output to a Blur TOP → Filter Size
4. - Connect to a Threshold TOP → Threshold
0.4. - Connect to a Null TOP named
MASK.
Part 3: Generate the Background
- Add a Noise TOP at the same resolution as
CAM(e.g.,1280 x 720).- Type →
Sparse, Amplitude →1.0, Period →0.5. - Right-click Translate X → Expression →
absTime.seconds * 0.05.
- Type →
- Add an HSV Adjust TOP.
- Saturation Multiplier →
1.5. - Right-click Hue Offset → Expression →
absTime.seconds * 10.
- Saturation Multiplier →
- Connect to a Null TOP named
BG.
Part 4: Composite Person Over Background
- Multiply TOP (
FG_ONLY): inputsCAMandMASK. Person pixels survive; everywhere else goes black. - Invert TOP on
MASK. - Multiply TOP (
BG_ONLY): inputsBGand the Invert output. - Add TOP: inputs
FG_ONLYandBG_ONLY. Since the masks are exact inverses, no pixel is counted twice. - Connect to a Null TOP named
OUT.
Part 5: Polish
- Before
OUT, add a Bloom TOP (Threshold:0.4, Intensity:0.5). - Add a Level TOP → Contrast
1.2.
Background Variations
| Background Source | Effect |
|---|---|
| Noise TOP (default) | Organic flowing color field |
| Feedback loop with Blur | Silhouette leaves glowing afterimage trails |
| Video Device In TOP (second camera) | Live video as background |
| Slit-Scan Time Warp output | Silhouette over a temporal smear |
| Reaction-Diffusion output | Silhouette over growing biological patterns |
Troubleshooting
- “Mask is all black.” - Check that Image Segmentation is enabled and SelfieSegmentation is selected. Even lighting makes a big difference here.
- “Edges flicker every frame.” - Increase Blur TOP filter size to
6or8. For temporal smoothing, blend 85% previous mask + 15% new mask through aMix TOP. - “Color fringe from clothing bleeds into background.” - Raise the Threshold to
0.55for a tighter cutout. - “Performance is slow.” - Enable GPU Mode in the MediaPipe COMP. Dropping
CAMto640 x 480also helps significantly.
Next Steps
- Neon silhouette: Replace
CAMinFG_ONLYwith aConstant TOP(bright cyan). Your shape becomes a flat neon cutout. - Body-driven background: Pipe
MASKoutput into the Noise TOP’s Translate X parameter so moving toward the camera shifts the background. - Multiple people: Switch the model to
MultiClass- it segments up to 4 people with separate color channels per person.
Parameter Tuning & Behavior
| Parameter | Behavior |
|---|---|
| Blur Filter Size (mask) | Higher = softer edge; Lower = hard aliased edge. |
| Threshold | Higher = tighter cutout; Lower = keeps semi-transparent fringe areas. |
| Noise Period (background) | Higher = large blobs; Lower = fine grain texture. |
| Hue Offset Speed | Higher = rapid cycling; Lower = slow ambient shift. |
Network Architecture
[ WEBCAM ] [ MEDIAPIPE ]
Video Device In ──▶ CAM ──▶ mediapipe1 (SelfieSegmentation)
│ │
│ Mask output
│ │
│ Blur TOP
│ │
│ Threshold TOP
│ │
│ ┌──────── MASK
│ │ │
│ │ Invert TOP
│ │ │
▼ ▼ ▼
Multiply TOP Multiply TOP (BG × Inverted Mask)
(CAM × MASK) │
FG_ONLY │ BG_ONLY
│ │
└──────┬───────┘
▼
Add TOP ──▶ Bloom ──▶ Level ──▶ OUT
[ BACKGROUND ]
Noise TOP ──▶ HSV Adjust ──▶ BGSources:
- MediaPipe TouchDesigner Plugin - GitHub
- Background Removal - Derivative Community
- Image Segmentation - Derivative Documentation
(y) Return to Recipes & Projects | (y) Return to TouchDesigner | (y) Return to Home