vision-subject-cutout
Zero-CGo (CGO_ENABLED=0), zero-TCC macOS Neural Engine subject lifting ("Lift Subject from Background") and GPU portrait-blur compositing using vision, coreimage, coregraphics, and x/capture — with no Python, ONNX, or bundled model weights.
What It Does
- Loads
-in <image> or synthesizes a 640x640 high-contrast studio scene via CoreGraphics when -in is omitted.
- Runs
VNGenerateForegroundInstanceMaskRequest on the Apple Neural Engine to segment foreground instances.
- Generates a transparent-background cutout PNG and a GPU portrait-blur PNG (
CIGaussianBlur + CIBlendWithMask via CIContext) and writes both via x/capture.
Usage
# Zero-friction run on built-in synthetic scene:
CGO_ENABLED=0 go run ./examples/vision/vision-subject-cutout
# Run on your own image:
CGO_ENABLED=0 go run ./examples/vision/vision-subject-cutout -in photo.jpg -out cutout.png -blur blur.png -radius 20
Flags:
-in — input image path (default: synthetic 640x640 studio scene)
-out — transparent cutout PNG path (default: temp dir)
-blur — portrait-blur PNG path (default: temp dir)
-radius — Gaussian blur sigma for background (default 18.0)
Sample Output
Input: synthetic studio scene (640x640)
Instances: 1 detected (ANE mask: 4.193s)
Coverage: 22.1% foreground pixels (GPU blur+composite: 169ms)
Cutout PNG: /var/folders/.../cutout.png (25621 bytes)
Blur PNG: /var/folders/.../portrait-blur.png (44055 bytes, sigma=18.0)