iOS 27 introduces GenerateIterativeSegmentationRequest in the Vision framework, letting users interactively isolate any object in an image by providing a point, bounding box, lasso, or scribble as a seed, then iteratively refine the resulting mask.
β’ Enables Photoshop-style object isolation with a single tap β no ML model training required by the developer
β’ Supports iterative refinement (add/remove regions) making it suitable for polished photo editing and object extraction workflows
β’ Pairs naturally with Foundation Models image inputs and Vision tools for richer, multi-step image understanding pipelines
Demonstrates using GenerateIterativeSegmentationRequest to segment a tapped object in a photo, then refine the mask by adding a second point to include an adjacent object.
import Vision
import UIKit
import CoreImage
final class TapToSegmentViewController: UIViewController {
private let imageView = UIImageView()
private var sourceImage: UIImage = UIImage(named: "cafe_photo")!
private var currentRequest: GenerateIterativeSegmentationRequest?
private var handler: ImageRequestHandler?
override func viewDidLoad() {
super.viewDidLoad()
setupImageView()
ensureModelReady()
}
private func setupImageView() {
imageView.image = sourceImage
imageView.contentMode = .scaleAspectFit
imageView.isUserInteractionEnabled = true
imageView.frame = view.bounds
view.addSubview(imageView)
let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap(_:)))
imageView.addGestureRecognizer(tap)
}
private func ensureModelReady() {
Task {
// Check if segmentation assets are downloaded
let status = await GenerateIterativeSegmentationRequest.assetStatus
if status != .ready {
try await GenerateIterativeSegmentationRequest.downloadAssets()
}
}
}
@objc private func handleTap(_ gesture: UITapGestureRecognizer) {
let tapPoint = gesture.location(in: imageView)
let imageSize = imageView.bounds.size
// Convert UIKit coordinates (origin top-left) to
// Vision normalized coordinates (origin bottom-left, values 0-1)
let normalizedPoint = NormalizedPoint(
x: tapPoint.x / imageSize.width,
y: 1.0 - (tapPoint.y / imageSize.height)
)
Task {
await segmentObject(at: normalizedPoint)
}
}
private func segmentObject(at point: NormalizedPoint) async {
guard let cgImage = sourceImage.cgImage else { return }
// Create handler once and reuse across refinements
if handler == nil {
handler = ImageRequestHandler(cgImage)
}
do {
// Build the iterative segmentation request with an initial seed point
var request = GenerateIterativeSegmentationRequest()
request.addPoint(point, label: .foreground)
// If we already have a prior request, carry over its state for refinement
if let prior = currentRequest {
request.previousResults = prior.results
}
let result = try await handler!.perform(request)
// result.pixelBuffer is a mask: white = segmented, black = background
if let mask = result.pixelBuffer {
let maskImage = CIImage(cvPixelBuffer: mask)
let composite = applyMask(maskImage, to: CIImage(cgImage: cgImage))
await MainActor.run {
imageView.image = composite
}
}
currentRequest = request
} catch {
print("Segmentation failed: \(error)")
}
}
private func applyMask(_ mask: CIImage, to source: CIImage) -> UIImage {
let context = CIContext()
let filter = CIFilter.blendWithMask()
filter.inputImage = source
filter.maskImage = mask.samplingLinear()
filter.backgroundImage = CIImage.empty()
let output = filter.outputImage ?? source
if let cgOut = context.createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgOut)
}
return sourceImage
}
}Foundation Models is a new Apple framework introduced in iOS 27 that gives developers on-device access to the same Apple Intelligence language model powering system features, enabling text generation, structured output, and tool-calling entirely on-device without a network connection.
Visual Intelligence brings iOS 17's Visual Look Up capabilities to a new developer-facing API surface in iOS 27, letting apps pipe live camera frames or static images through on-device scene understanding to extract subjects, text, barcodes, and rich semantic labels without any cloud round-trip.
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, allowing anyone to integrate server-based or local models (e.g. Claude, Gemini, CoreAI, MLX) using the same API as Apple's on-device system model.
In-depth guide
iOS 27 On-Device AI & Apple Intelligence βVision uses a normalized coordinate system with origin at the lower-left corner (values 0β1); lasso stroke width must be at least 1% of image width or results will be poor; the segmentation model must be downloaded on-device before first use β handle assetStatus accordingly
Requires model download before first use on a given device; call downloadAssets() and check assetStatus before performing the request
iOS 27 opens the Foundation Models framework to third-party LLM providers via a new public LanguageModel protocol, enabling anyone to integrate custom, server-based, or open-source models using the same Swift API as Apple's on-device system model.