image_background_remover 2.0.0
image_background_remover: ^2.0.0 copied to clipboard
A Flutter package that removes the background from images using an ONNX model.
2.0.0 #
🎉 Major Update: Migration to flutter_onnxruntime #
Breaking Changes
- Migrated from
onnxruntimetoflutter_onnxruntimepackage for better maintenance and support dispose()method is now asynchronous internally (no user code changes required)
New Features
- Modular Architecture: Refactored codebase into organized modules for better maintainability
services/onnx_session_manager.dart- ONNX Runtime session managementutils/image_processor.dart- Image processing utilitiesutils/mask_processor.dart- Mask processing utilitiesutils/background_composer.dart- Background composition utilities
- Better Resource Management: Improved memory management with proper tensor disposal
- Enhanced Error Handling: More informative error messages and validation
Improvements
- 16KB Android Page Size Support: Compatible with Google Play's 16KB requirement for Android 15+ devices
- Simplified ONNX session initialization (no manual buffer loading required)
- Better documentation with inline migration comments
- Improved code organization and separation of concerns
- Added comprehensive architecture documentation in
lib/src/README.md
Important Notes
- Isolate Support: This package cannot be used with Dart isolates because ONNX model loading requires Flutter asset access. See
WHY_NO_ISOLATES.mdfor detailed explanation. - Async/Await: Use async processing on the main isolate - it provides non-blocking behavior without isolate complexity
- Migration Guide: All changes are marked with
// Migration:comments in the code
API Changes
- Session management simplified (internal changes, no user-facing API changes)
- Tensor creation and disposal updated to new API (handled internally)
Files Added
lib/src/services/onnx_session_manager.dart- Session lifecycle managementlib/src/utils/image_processor.dart- Image processing utilitieslib/src/utils/mask_processor.dart- Mask manipulation utilitieslib/src/utils/background_composer.dart- Background compositionlib/src/README.md- Architecture documentationWHY_NO_ISOLATES.md- Isolate limitations explanation
Migration from v1.x
If upgrading from v1.x:
-
No code changes required! The dispose call remains the same:
@override void dispose() { BackgroundRemover.instance.dispose(); super.dispose(); }Note: Even though
dispose()is async internally, you should not await it in your widget's dispose method because Flutter's dispose must be synchronous. -
The public API remains completely backward compatible!
0.0.7 #
Added #
- Implemented threshold-based segmentation to refine background removal.
- Integrated a smooth edge method using bilinear interpolation and average neighboring to improve output quality and reduce harsh edges.
- Implemented edge enhancement for mask refinement using a Sobel-like gradient detection method.
0.0.1 #
Added #
- Initial release of the Background Remover Service Flutter package.
- ONNX Runtime integration for background removal using the
onnxmodel. - Functions to initialize ONNX session:
initializeOrt(): Initialize the ONNX environment and session.
- Image processing capabilities:
removeBg(Uint8List imageBytes): Removes the background from an input image and returns the image with a transparent background._resizeImage(): Resizes an image to 320x320 for ONNXy model compatibility._imageToFloatTensor(): Converts RGBA image data into a normalized float tensor for model input._applyMaskToOriginalSizeImage(): Applies the generated mask back to the original image size.
- Utility methods:
resizeMask(): Resizes the ONNX output mask to match the original image dimensions.
- Designed for cross-platform support (iOS, Android, Web, and Desktop).