Modelplace.AI
  • 👋Overview
  • 🧑‍🏫Solutions
    • Face Detection
    • Pose Tracking
    • Background Removal for Video Conferences
    • Background Removal for Images
  • 🚀Getting Started
    • Get a framework
    • Run a demo
    • Integrate a framework
  • ✨API
    • Face Detection
    • Pose Tracking
    • Background Removal for Video Conferences
    • Background Removal for Images
  • 🤔Troubleshooting
  • 📄Licence
    • Face Detection
    • Pose Estimation
Powered by GitBook
On this page
  1. API

Background Removal for Images

API Interface of the iOS Framework

Instantiate Background Removal model with preferred confidence threshold value (might be changed in runtime).

Lower threshold values keep more pixels that possibly correspond to the background. Higher threshold values remove more pixels that possibly correspond to the foreground. The effective range for this parameter is [0., 1.].

private var backgroundRemover = BackgroundRemover(threshold: 0.5)

Load the model with backgroundRemover.loadModel method

Example:

backgroundRemover.loadModel { error in
    self.dismissPresentedViewController(animated: true) {
        if error != nil {
            showError(on: self, message: "Failed to initialize BG Removal model: \(error!.localizedDescription)")
        }
    }
}

Schedule the task with backgroundRemover.removeBackground method when the model is loaded

Example:

let result = self.backgroundRemover.removeBackground(fromImage: image) { mask, error in
    if error != nil {
        showAlert(on: self, message: "BG Model runtime failure: \(error!.localizedDescription)")
        return
    }
    DispatchQueue.main.async {
        (self.loadingViewController as! LoadingViewController).update(text: "Applying Mask...")
        DispatchQueue.global().async {
            self.applyMask(mask!, to: image)
        }

    }
}

The mask is returned as a UIImage object with non-zero pixels corresponding to the foreground with the defined confidence threshold.

PreviousBackground Removal for Video ConferencesNextTroubleshooting

Last updated 2 years ago

✨