Local transparent cutouts with Apple Vision
A 122-line Swift script isolates foreground subjects on the Apple Neural Engine in about 210 milliseconds for $0.
Uploading a local file to a cloud API just to strip its background is wasted work. You pay per call and wait several seconds on a network request while a capable segmentation model sits idle on your own machine. Since macOS 14, Apple has shipped foreground masking inside the system Vision framework. It runs offline on the Apple Neural Engine with zero external packages, cutting out a wide image in a fifth of a second for $0.
Waiting on a browser upload or an API spinner breaks your focus when you're assembling a deck, cleaning up a sprite sheet, or wiring an asset script. I put Apple's foreground instance mask request (VNGenerateForegroundInstanceMaskRequest) into a 122-line Swift CLI called vision-cutout.swift. Across four 1376x768 test images on an Apple Silicon Mac, every cutout finished between 202 and 216 milliseconds.
Lifting single and multi-pose subjects
The script takes an input file and an output path, runs the Vision request, and builds a full-resolution soft matte from result.allInstances. Using allInstances grabs every distinct foreground subject in the frame instead of just the largest one. A CIBlendWithMask filter then composites the result onto an empty RGBA canvas on the GPU, or writes out the raw grayscale matte if you pass --mask-only. At the end, the script scans the alpha channel and prints a single line of JSON with transparent_pct, semitransparent_pct, and elapsed_ms.
The 1376x768 winter fox photo above finished in 216 milliseconds. Vision cleared 75.8% of the canvas to full transparency and left 1.6% as soft edge pixels. It dropped the out-of-focus pine branches and falling snow while holding onto frosted ear tips, fur edges, and individual white whiskers. Look closely at the fox's left cheek (viewer's left) to see where the mask hits its spatial limit: inside that tight cluster of white whiskers, a thin sliver of dark forest stays caught between adjacent hairs.
Character sheets show why result.allInstances is worth knowing about. In the 1376x768 armored bear turnaround above, three separate poses stand on a slate-grey backdrop with painted ground shadows. One 204-millisecond pass lifted all three figures together, clearing 63.3% of the image and leaving 4.0% as soft edges around the fur and claws. Two other 1376x768 sheets in the same batch ran just as fast: a three-pose character sheet took 213 milliseconds (43.1% transparent, 5.6% semitransparent) and a three-item prop sheet took 202 milliseconds (66.9% transparent, 5.4% semitransparent).
Where silhouette masks fall short
Subject size matters. When I ran the script on a wide snowy landscape with a distant figure, Vision found nothing to isolate and exited cleanly with Error: Vision detected no foreground subject. If the subject fills only a tiny fraction of the frame, crop closer before running the cutout.
The model also assumes every subject is an opaque solid with soft outer edges. When an image has clear glass, drifting smoke, colored glow, or soft drop shadows, a silhouette mask either clips the falloff at the boundary or leaves the old background color baked right into the translucent pixels. For true interior opacity or brand-new assets generated from a prompt, you need a different tool.
Generating native RGBA with GPT-Image-2.6
When you're generating a new icon, sticker, or UI illustration from a text prompt, don't generate a flat backdrop only to cut it out later. Passing background="transparent" with output_format="png" (or "webp") to OpenAI's Image API returns four-channel RGBA straight from the generator, as documented in OpenAI's image generation guide. Within the GPT-Image-2.6 family, gpt-image-2.6-flare handles fast everyday passes, while gpt-image-2.6-sunburst is built for finer visual detail and tighter editing precision.
The three 1024x1024 PNGs above came straight back from the API with native alpha channels. On gpt-image-2.6-flare at medium quality, the brass compass finished in 7.8 seconds (45.1% transparent, 2.2% semitransparent), knocking out both the outer boundary and the hollow top-right ring. Switching to gpt-image-2.6-sunburst at high quality produced true interior translucency: the glass terrarium took 39.8 seconds with 27.5% semitransparent pixels that let the checkerboard show straight through the panes, while the espresso cup took 27.9 seconds with 5.9% semitransparent wisps of steam and an open handle. Waiting 8 to 40 seconds and paying per call makes sense when you need fresh glass, steam, or icons from a prompt, whereas existing files on disk still belong on Apple Vision.
Recovering glass and smoke with dual renders
Opaque-only generators like Google's Nano Banana models output three-channel RGB with no alpha option, and deterministic 3D or vector tools often render against a solid canvas. If you try to lift translucent glass, smoke, glow, or soft shadows from a green screen, the backdrop color spills into every semitransparent pixel. Instead, render the exact same subject twice: once over pure #FFFFFF white (1) and once over pure #000000 black (0). With those two frames, you can solve exact per-pixel opacity using the closed-form Porter-Duff alpha compositing equations.
Under standard over compositing, a foreground color F with opacity alpha produces W = alpha * F + (1 - alpha) against white and B = alpha * F against black. Subtracting the black pixel from the white pixel cancels F out completely, leaving W - B = 1 - alpha. Averaging that channel difference across red, green, and blue gives alpha = clamp(1 - mean(W - B), 0, 1) for each pixel.
Once you have alpha, you don't even have to divide B to recover the unmultiplied foreground color. Standard CoreGraphics bitmaps use CGImageAlphaInfo.premultipliedLast, where every RGB channel is stored as alpha * F, and the black render B already holds that exact value. Clamping each channel of B to <= alpha and snapping tiny 8-bit rounding noise (alpha < 0.01 to 0 and alpha > 0.992 to 1) gives you a clean premultiplied RGBA PNG directly.
The second script below, diff-matte.swift, runs this pixel loop in 132 lines of CoreGraphics and ImageIO code. On a 200x200 synthetic test pattern with a 50%-opacity cyan ring around an opaque center, it finished in 22 milliseconds. It measured 49.1% transparent pixels and 38.6% semitransparent pixels, matching the exact 49.7% and 37.7% geometry within 8-bit rounding. The catch is alignment: both frames must match pixel for pixel, so this trick fits deterministic renders and locked background swaps. Loose AI re-generations that shift the subject's outline between passes will leave double edges.
Comparison of transparent image workflows on macOS
| Route | Best for | Speed and cost | Main limit |
|---|---|---|---|
| Apple Vision | Existing photos, illustrations, and multi-subject sheets already on disk | ~202 to 216 ms locally on Apple Neural Engine, $0 | Needs a clear foreground subject; clips glass, smoke, and soft glow |
| OpenAI GPT-Image-2.6 | Generating new icons, stickers, and isolated UI assets from a text prompt | Seconds over the network, billed per API call | Builds new images; does not cut out existing local files |
| Difference matting | Translucent glass, smoke, glow, and soft shadows from dual white/black renders | ~22 ms locally in CoreGraphics after rendering both frames, $0 | Requires pixel-locked alignment between the white and black frames |
Both scripts run directly via /usr/bin/env swift without an Xcode project and emit the same JSON fields so a build script can verify transparent_pct automatically. You can inspect or copy the full source and shell commands in the explorer below.






