Portrait without Depth ios

try! Swift 2019 demo app that converts Depth-less 2D images into Portrait mode.

172
12
Swift

Portrait-without-Depth-ios

MIT License
Twitter

try! Swift 2019 demo app that converts Depth-less 2D images into Portrait mode.

How to build

  1. Download opencv2.framework from here v3.4.x iOS pack, then put it into this folder.
  2. Open Portrait.xcworkspace with Xcode 10.x and build it

About this app

In iOS’s Portrait mode, you can take beautiful photos that keep your subject sharp while blurring the background.
This so-called bokeh effect can be done by using Depth.
In contrast, this app attempts to make Depth-less 2D images into Portrait mode by following steps.

1. Segmentation ✂️

This app uses “GrabCut” to perform segmentation of the subject and the background.

GrabCut with Rect

grabcut-with-rect

GrabCut with Mask

grabcut-with-mask

2. Color leak prevention 🎨

As it’s not beautiful if the subject color leaks into the background, this app tries to delete the subject from the background by using “Inpainting”.

Blur & Inpainting

blur-and-inpainting

3. Depth-of-Field 📷

“Depth-of-Field” is the range where the photo is in focus.
I implemented an adjusting function to blur an area.

Adjust

adjust-depth-of-field

Result✨
before ← → after

Please give it a try !

Requirement

Xcode 10.x+
iOS 12.0+

Author

Rina Kotake

Licenses

Special Thanks ✨