Coder Social home page Coder Social logo

rmbg's Introduction

RMBG Crate

This crate provides an easy-to-use interface for removing backgrounds from images, leveraging a machine learning model. It's designed to integrate seamlessly into Rust projects requiring background removal capabilities.

Rust docs: https://docs.rs/rmbg/latest/rmbg/struct.Rmbg.html Crates.io: https://crates.io/crates/rmbg

Features

  • Load and apply a machine learning model to remove backgrounds from images.
  • Maintains original image dimensions, replacing the background with transparency.
  • Preprocess and postprocess images to conform to model requirements.

Getting Started

Prerequisites

Before using the rmbg crate, you need to download the required model.onnx file. This model is a crucial component as it powers the background removal process. You can download it from the following URL:

https://huggingface.co/briaai/RMBG-1.4/blob/main/onnx/model.onnx

Place the downloaded model.onnx file in a known directory within your project.

Installation

Add rmbg to your Cargo.toml file:

[dependencies]
rmbg = { version = "0.1.0", default-features = false }

Note for Library Developers

If you are developing a library that includes rmbg, it is heavily recommended to disable default features to avoid unnecessary bloat. Cargo features are additive, and enabling default features in a library can prevent downstream users from opting out of those features, leading to increased compile times and binary sizes.

Instead, enable the necessary features in your development dependencies as follows:

[dev-dependencies]
rmbg = { version = "0.1.0", features = ["download-binaries"] }

Instruct downstream users to include ort in their dependencies if needed, with the download-binaries feature enabled:

[dependencies]
ort = { version = "...", features = ["download-binaries"] }

Usage

To use the rmbg crate in your project, first, initialize an instance of the Rmbg struct with the path to the model.onnx file. Then, call the remove_background method with an image to process.

Here's a simple example:

use rmbg::Rmbg;
use image::DynamicImage;

fn main() -> anyhow::Result<()> {
    // Load the model
    let rmbg = Rmbg::new("path/to/model.onnx")?;

    // Load an image
    let original_img = image::open("path/to/image.png")?;

    // Remove the background
    let img_without_bg = rmbg.remove_background(&original_img)?;

    // Save or further process `img_without_bg` as needed
    Ok(())
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Model License

The model.onnx file used by this crate is subject to its own license terms. The model is released under the bria-rmbg-1.4 license, which is a Creative Commons license for non-commercial use only. Commercial use of the model requires a commercial agreement with BRIA.

Please ensure you comply with the model's license terms when using it in your projects.

rmbg's People

Contributors

pekc83 avatar

Stargazers

Shengxi Lee avatar Emma Böcker avatar Wesley Moore avatar Uriah Galang avatar Daniel Yang avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.