Extract subject of a picture programmatically

Hello,

I'm doing a iOS app and I'm trying to find a way to extract programmatically a person from his identity picture (and to leave behind the background)

I'm watching WWDC "Lift subjects from images in your app" video (a really cool feature) and i'm wondering if this feature would be possible programmatically, without the need of a human person interaction.

Thank you.

Replies

After rewatching the video a second time, it appears that i"m trying to do is easy, with few lines of code (something like that) :

var uiImage: UIImage?
let analyser = ImageAnalyzer()
let interaction = ImageAnalysisInteraction()
let configuration = ImageAnalyzer.Configuration([.text, .visualLookUp, .machineReadableCode])
let analysis = try? await analyser.analyze(image, configuration: configuration)
interaction.analysis = analysis
uiImage = try? await interaction.image(for: interaction.subjects)

Looks like you found your answer! For what it's worth, you might also want to take a look at the Vision API: VNGenerateForegroundInstanceMaskRequest

API details: https://developer.apple.com/documentation/vision/vngenerateforegroundinstancemaskrequest

More about it in the second half of this session: https://developer.apple.com/wwdc23/10176