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.

  1. Original 1376x768 photograph of a red fox standing in a snowy pine forest with falling snowflakes and out-of-focus snow-covered branches.
  2. Local Apple Vision cutout of the red fox rendered in 216 milliseconds with 75.8% transparent pixels, preserving frosted ear tips, fur edges, and white whiskers.

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.

  1. Original 1376x768 turnaround sheet showing three separate armored bear poses on a solid slate-grey background with ground shadows.
  2. Single-pass Apple Vision cutout produced in 204 milliseconds using result.allInstances, isolating all three armored bear poses on a transparent background.

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.

  1. Brushed brass pocket compass with a matte navy dial and red-tipped needle generated by gpt-image-2.6-flare in 7.8 seconds, with a clean knockout around the outer silhouette and inside the top-right brass ring.
  2. Dark-brass geometric glass terrarium holding green moss and miniature ferns generated by gpt-image-2.6-sunburst in 39.8 seconds, with 27.5% semitransparent pixels showing the transparency checkerboard directly through the clear glass panes.
  3. Matte speckled ceramic espresso cup with warm crema generated by gpt-image-2.6-sunburst in 27.9 seconds, showing the transparency checkerboard through the open handle and delicate wisps of rising steam.

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

Comparison of transparent image workflows on macOS
RouteBest forSpeed and costMain limit
Apple VisionExisting photos, illustrations, and multi-subject sheets already on disk~202 to 216 ms locally on Apple Neural Engine, $0Needs a clear foreground subject; clips glass, smoke, and soft glow
OpenAI GPT-Image-2.6Generating new icons, stickers, and isolated UI assets from a text promptSeconds over the network, billed per API callBuilds new images; does not cut out existing local files
Difference mattingTranslucent glass, smoke, glow, and soft shadows from dual white/black renders~22 ms locally in CoreGraphics after rendering both frames, $0Requires 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.

vision-cutout.swift
#!/usr/bin/env swift// Apple Vision (VNGenerateForegroundInstanceMaskRequest) local $0 background removal.// Runs on the Apple Neural Engine (macOS 14+), zero cloud uploads, zero API cost.// Usage: swift vision-cutout.swift <input> <output.png> [--mask-only] import CoreImageimport Foundationimport ImageIOimport UniformTypeIdentifiersimport Vision let args = CommandLine.argumentsguard args.count >= 3 else {    fputs("Usage: vision-cutout.swift <input> <output.png> [--mask-only]\n", stderr)    exit(2)} let inputPath = args[1]let outputPath = args[2]let maskOnly = args.contains("--mask-only")let t0 = Date() let inputURL = URL(fileURLWithPath: inputPath)guard let ciInput = CIImage(contentsOf: inputURL) else {    fputs("Error: could not read image at \(inputPath)\n", stderr)    exit(1)} let request = VNGenerateForegroundInstanceMaskRequest()let handler = VNImageRequestHandler(ciImage: ciInput, options: [:])do {    try handler.perform([request])} catch {    fputs("Error: Vision request failed: \(error.localizedDescription)\n", stderr)    exit(1)} guard let result = request.results?.first else {    fputs("Error: Vision detected no foreground subject in \(inputPath)\n", stderr)    exit(1)} let maskBuffer: CVPixelBufferdo {    maskBuffer = try result.generateScaledMaskForImage(forInstances: result.allInstances, from: handler)} catch {    fputs("Error: failed to generate scaled foreground mask: \(error.localizedDescription)\n", stderr)    exit(1)} let ciMask = CIImage(cvPixelBuffer: maskBuffer)let ciContext = CIContext(options: [.useSoftwareRenderer: false])let extent = ciInput.extent let outputCI: CIImageif maskOnly {    outputCI = ciMask.cropped(to: extent)} else {    let clearBg = CIImage(color: CIColor(red: 0, green: 0, blue: 0, alpha: 0)).cropped(to: extent)    guard let blend = CIFilter(name: "CIBlendWithMask") else {        fputs("Error: CIBlendWithMask unavailable\n", stderr)        exit(1)    }    blend.setValue(ciInput, forKey: kCIInputImageKey)    blend.setValue(clearBg, forKey: kCIInputBackgroundImageKey)    blend.setValue(ciMask, forKey: kCIInputMaskImageKey)    guard let blended = blend.outputImage?.cropped(to: extent) else {        fputs("Error: blend produced empty image\n", stderr)        exit(1)    }    outputCI = blended} let srgb = CGColorSpace(name: CGColorSpace.sRGB)!guard let cgOut = ciContext.createCGImage(outputCI, from: extent, format: .RGBA8, colorSpace: srgb) else {    fputs("Error: failed to render RGBA8 CGImage\n", stderr)    exit(1)} // Compute alpha coverage stats so callers can verify real transparencylet w = cgOut.widthlet h = cgOut.heightvar rgba = [UInt8](repeating: 0, count: w * h * 4)let bctx = CGContext(    data: &rgba,    width: w,    height: h,    bitsPerComponent: 8,    bytesPerRow: w * 4,    space: srgb,    bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!bctx.draw(cgOut, in: CGRect(x: 0, y: 0, width: w, height: h)) var transparent = 0var semitransparent = 0let total = max(1, w * h)for i in stride(from: 3, to: rgba.count, by: 4) {    let a = rgba[i]    if a == 0 {        transparent += 1    } else if a < 250 {        semitransparent += 1    }} let outURL = URL(fileURLWithPath: outputPath)try? FileManager.default.createDirectory(at: outURL.deletingLastPathComponent(), withIntermediateDirectories: true)guard let dest = CGImageDestinationCreateWithURL(outURL as CFURL, UTType.png.identifier as CFString, 1, nil) else {    fputs("Error: could not create PNG destination at \(outputPath)\n", stderr)    exit(1)}CGImageDestinationAddImage(dest, cgOut, nil)guard CGImageDestinationFinalize(dest) else {    fputs("Error: failed to write PNG to \(outputPath)\n", stderr)    exit(1)} let elapsedMs = Int(Date().timeIntervalSince(t0) * 1000)let transPct = String(format: "%.1f", Double(transparent) * 100.0 / Double(total))let semiPct = String(format: "%.1f", Double(semitransparent) * 100.0 / Double(total))print("{\"engine\":\"apple-vision\",\"mask_only\":\(maskOnly),\"width\":\(w),\"height\":\(h),\"transparent_pct\":\(transPct),\"semitransparent_pct\":\(semiPct),\"elapsed_ms\":\(elapsedMs),\"output\":\"\(outputPath)\"}")