Since the parts other than the foreground (people, etc.) are transparent, it can be used for background composition.
1. Make a mask image.
Acquire mask images using segmentation models such as the DeepLab v3 model distributed by Apple.
Please refer to this article.
Converting DeepLabV3 to CoreML Model.
DeepLab is a state-of-art deep learning model for semantic image segmentation.
Distribute the results of the segmentation model (DeepLabV3) to each label by Core ML Helpers.
Apple’s official distribution DeepLab V3 Core ML model outputs a (512,512) ML Multi Array. Each pixel has a label value…
2. Make a transparent image.
Create a transparent image with the same size as the original image.
Since the “non-transparent area” is specified in the argument of settingAlphaOne, specify zero to acquire a fully transparent image.
let transparentImage = originalCIImage.settingAlphaOne(in: CGRect.zero)
Foreground = original image, background = transparent image, mask image = mask image of the object you want to keep, and combine with CIFilter.
let compositeImage = CIFilter(name: "CIBlendWithMask", parameters: [
Prepare a background image and combine it again to create a composite image.
Request for work: