https://github.com/netesh5/image_background_remover
A Flutter package that removes the background from images using an ONNX model. The package provides a seamless way to perform image processing, leveraging the power of machine learning through ONNX Runtime.
https://github.com/netesh5/image_background_remover
flutter image-background image-background-removal image-processing machine-learning onnx onnxruntime remove-background remove-background-image removebg
Last synced: about 2 months ago
JSON representation
A Flutter package that removes the background from images using an ONNX model. The package provides a seamless way to perform image processing, leveraging the power of machine learning through ONNX Runtime.
- Host: GitHub
- URL: https://github.com/netesh5/image_background_remover
- Owner: Netesh5
- License: bsd-3-clause
- Created: 2025-01-27T14:40:10.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-03-27T09:58:46.000Z (about 2 months ago)
- Last Synced: 2025-03-27T10:39:00.050Z (about 2 months ago)
- Topics: flutter, image-background, image-background-removal, image-processing, machine-learning, onnx, onnxruntime, remove-background, remove-background-image, removebg
- Language: Dart
- Homepage: https://pub.dev/packages/image_background_remover
- Size: 32.6 MB
- Stars: 2
- Watchers: 1
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Image Background Remover - Flutter
## ⌗ Overview
A Flutter package that removes the background from images using an ONNX model. The package provides a seamless way to perform image processing, leveraging the power of machine learning through ONNX Runtime. This package works completely offline without any external API dependencies---
## 🌟 Features
- Remove the background from images with high accuracy.
- Works entirely offline, ensuring privacy and reliability.
- Lightweight and optimized for efficient performance.
- Simple and seamless integration with Flutter projects.
- Add a custom background color to images.
- Customizable threshold value for better edge detection.---
## 🔭 Example
## Getting Started
### 🚀 Prerequisites
Before using this package, ensure that the following dependencies are included in your `pubspec.yaml`:
```yaml
dependencies:
image_background_remover: ^latest_version
```## Usage
# Initialization
Before using the `removeBg` method, you must initialize the ONNX environment:
```dart
import 'package:image_background_remover/image_background_remover.dart';@override
void initState() {
super.initState();
BackgroundRemover.instance.initializeOrt();
}
```# Dispose
Don't forget to dispose the onnx runtime session :
```dart
@override
void dispose() {
BackgroundRemover.instance.dispose();
super.dispose();
}
```# Remove Background
To remove the background from an image:
``` dart
import 'dart:typed_data';
import 'package:image_background_remover/image_background_remover.dart';Uint8List imageBytes = /* Load your image bytes */;
ui.Image resultImage = await BackgroundRemover.instance.removeBg(imageBytes);
/* resultImage will contain image with transparent background*/```
## 🆕 New Feature: Add Background Color
You can now add a custom background color to images after removing the background.
### Usage:
```dart
Uint8List modifiedImage = await BackgroundRemover.instance.addBackground(
image: originalImageBytes,
bgColor: Colors.white, // Set your desired background color
);```
## API
### Methods
| Method | Description | Parameters | Returns |
|---------------------------------|-----------------------------------------------------------------------------|------------------------------------------------|-----------------------------------|
| `initializeOrt()` | Initializes the ONNX runtime environment. Call this method once before using `removeBg`. | None | `Future` |
| `removeBg(Uint8List imageBytes, { double threshold = 0.5, bool smoothMask = true, bool enhanceEdges = true })` | Removes the background from an image. | `imageBytes` - The image in byte array format.
`threshold` - The confidence threshold for background removal (default: `0.5`). A higher value removes more background, while a lower value retains more foreground.
`smoothMask` - Whether to apply bilinear interpolation for smoother edges (default: `true`).
`enhanceEdges` - Whether to refine mask boundaries using gradient-based edge enhancement (default: `true`). | `Future` - The processed image with the background removed. |
| `addBackground({required Uint8List image, required Color bgColor})` | Adds a background color to the given image. | `image` - The original image in byte array format.
`bgColor` - The background color to be applied. | `Future` - The modified image with the background color applied. |## ⛔️ iOS Issue
Exception: ONNX session not initialized (iOS Release Mode & TestFlight)
To resolve this issue, update the following settings in Xcode:
Open Xcode and navigate to:
Runner.xcodeproj → Targets → Runner → Build SettingsUnder the Deployment section:
Set "Strip Linked Product" to "No"
Set "Strip Style" to "Non-Global-Symbols"## ⚠️ Warning
This package uses an offline model to process images, which is bundled with the application. **This may increase the size of your app**.
## 🔗 Contributing
Contributions are welcome! If you encounter any issues or have suggestions for improvements, feel free to create an issue or submit a pull request.## ☕ Support This Project
If you find this package helpful and want to support its development, you can buy me a coffee! Your support helps maintain and improve this package. 😊[](https://www.buymeacoffee.com/neteshpaudel)