# rmbg-mask
`rmbg-mask` generates an 8-bit grayscale foreground mask from an image using
a local copy of the RMBG 2.0 model. It never downloads model files.
RMBG 2.0's downloadable weights are restricted to non-commercial use unless
you have a separate commercial agreement with BRIA. Review the model license
before using this program.
## Installation
For development with uv:
```sh
uv sync
uv run rmbg-mask --help
```
Alternatively, install the project with pip:
```sh
python -m pip install .
rmbg-mask --help
```
## Usage
Download RMBG 2.0 separately and place all of its repository files in one
local directory. Then run:
```sh
rmbg-mask input.jpg mask.png --model /path/to/RMBG-2.0
```
The output mask has the same dimensions as the input image. White represents
foreground, black represents background, and intermediate values preserve the
model's soft edges.
Use `--processing-resolution` (or `-r`) to control the square resolution used
for inference:
```sh
rmbg-mask input.jpg mask.png \
--model /path/to/RMBG-2.0 \
--processing-resolution 1536
```
Higher resolutions may retain more detail, but use substantially more memory
and processing time. The default is 1024.
The device defaults to CUDA when available, then MPS, then CPU. It can be
selected explicitly:
```sh
rmbg-mask input.jpg mask.png --model ./RMBG-2.0 --device cpu
```
## Testing
The unit tests do not load the model:
```sh
uv run python -m unittest discover -s tests
```