
# napari-rembg
Segment images using a collection of fast and lightweight generalist segmentation models in Napari. This plugin is based on the [rembg](https://github.com/danielgatis/rembg) project.

**Key features**
- Choose among **five generalist segmentation models**, including SAM (Segment Anything Model).
- Quickly annotate individual objects by drawing **bounding boxes** around them.
- Possibility to generate predictions via a remote **web API** and keep the installation lightweight on client machines.
- Compatible with 2D, RGB, 2D+t, and 3D images (slice by slice).
## Installation
You can install `napari-rembg` via [pip]. If you wish to use your local machine for the predictions (most users):
pip install "napari-rembg[local]"
If you wish to generate predictions from a [web api](#running-the-segmentation-via-a-web-api), go for a minimal install:
pip install napari-rembg
## Models
- [u2net](https://github.com/xuebinqin/U-2-Net): A pre-trained model for general use cases.
- [u2netp](https://github.com/xuebinqin/U-2-Net): A lightweight version of u2net.
- [silueta](https://github.com/xuebinqin/U-2-Net/issues/295): Same as u2net with a size reduced to 43 Mb.
- [isnet](https://github.com/xuebinqin/DIS): A pre-trained model for general use cases.
- [sam](https://github.com/facebookresearch/segment-anything): Segment Anything Model pre-trained for any use cases (`vit_b`)

The models automatically get downloaded in the user's home folder in the `.u2net` directory the first time inference is run.
## Usage
Start `napari-rembg` from the `Plugins` menu of Napari:
```
Plugins > Napari Select Foreground > Select foreground
```
### Segment an image loaded into Napari
Select your image in the `Image` dropdown and press `Run`. The output segmentation appears in the `Labels` layer selected in the `Mask` field (if no layer is selected, a new one is created).
### Segment individual objects using bounding boxes
- Click on the `Add` button next to the `ROI` field. This adds a `Shapes layer` to the viewer.
- Click and drag bounding boxes around objects in the image. Each time you draw a bounding box a segmentation is generated in the region selected.

You can choose to auto-increment the label index to distinguish individual objects. Deselect that option to annotate a single foreground class.
## Running the segmentation via a web API
You can run the `rembg` segmentation via a web API running in a `docker` container.
**Advantages**
- The segmentation can be run on a remote machine with optimization (e.g. GPU).
- The segmentation models will be downloaded inside the docker container instead of the user's file system.
- You can minimally install the package with `pip install napari-rembg` on the client's machine. This will *not* install the `rembg` library, which can solve potential dependency conflicts or bugs.
**Setup**
See [these instructions](./src/rembg-api/README.md) on how to set up the docker container and web API.
**Usage**
Start `napari-rembg` from the `Plugins` menu of Napari:
```
Plugins > Napari Select Foreground > Select foreground (Web API)
```
## Related projects
If you are looking for similar generalist segmentation plugins, check out these related projects:
- [napari-sam](https://github.com/MIC-DKFZ/napari-sam)
- [napari-segment-anything](https://github.com/royerlab/napari-segment-anything)
## Contributing
Contributions are very welcome.
## License
Distributed under the terms of the [BSD-3] license,
"napari-rembg" is free and open source software.
## Issues
If you encounter any problems, please file an issue along with a detailed description.
[napari]: https://github.com/napari/napari
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[@napari]: https://github.com/napari
[BSD-3]: http://opensource.org/licenses/BSD-3-Clause
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin
[pip]: https://pypi.org/project/pip/
[PyPI]: https://pypi.org/
----------------------------------
This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.
Raw data
{
"_id": null,
"home_page": "https://github.com/EPFL-Center-for-Imaging/napari-rembg.git",
"name": "napari-rembg",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Mallory Wittwer",
"author_email": "mallory.wittwer@epfl.ch",
"download_url": "https://files.pythonhosted.org/packages/4f/3a/074f3be864fbf3e5b4fd82b8c566cd73409fb69287aec6190aab8802cb0f/napari-rembg-0.0.7.tar.gz",
"platform": null,
"description": "\n# napari-rembg\n\nSegment images using a collection of fast and lightweight generalist segmentation models in Napari. This plugin is based on the [rembg](https://github.com/danielgatis/rembg) project.\n\n\n\n**Key features**\n\n- Choose among **five generalist segmentation models**, including SAM (Segment Anything Model).\n- Quickly annotate individual objects by drawing **bounding boxes** around them.\n- Possibility to generate predictions via a remote **web API** and keep the installation lightweight on client machines.\n- Compatible with 2D, RGB, 2D+t, and 3D images (slice by slice).\n\n## Installation\n\nYou can install `napari-rembg` via [pip]. If you wish to use your local machine for the predictions (most users):\n\n pip install \"napari-rembg[local]\"\n\nIf you wish to generate predictions from a [web api](#running-the-segmentation-via-a-web-api), go for a minimal install:\n\n pip install napari-rembg\n\n## Models\n\n- [u2net](https://github.com/xuebinqin/U-2-Net): A pre-trained model for general use cases.\n- [u2netp](https://github.com/xuebinqin/U-2-Net): A lightweight version of u2net.\n- [silueta](https://github.com/xuebinqin/U-2-Net/issues/295): Same as u2net with a size reduced to 43 Mb.\n- [isnet](https://github.com/xuebinqin/DIS): A pre-trained model for general use cases.\n- [sam](https://github.com/facebookresearch/segment-anything): Segment Anything Model pre-trained for any use cases (`vit_b`)\n\n\n\nThe models automatically get downloaded in the user's home folder in the `.u2net` directory the first time inference is run.\n\n## Usage\n\nStart `napari-rembg` from the `Plugins` menu of Napari:\n\n```\nPlugins > Napari Select Foreground > Select foreground\n```\n\n### Segment an image loaded into Napari\n\nSelect your image in the `Image` dropdown and press `Run`. The output segmentation appears in the `Labels` layer selected in the `Mask` field (if no layer is selected, a new one is created).\n\n### Segment individual objects using bounding boxes\n\n- Click on the `Add` button next to the `ROI` field. This adds a `Shapes layer` to the viewer.\n- Click and drag bounding boxes around objects in the image. Each time you draw a bounding box a segmentation is generated in the region selected.\n\n\n\nYou can choose to auto-increment the label index to distinguish individual objects. Deselect that option to annotate a single foreground class.\n\n## Running the segmentation via a web API\n\nYou can run the `rembg` segmentation via a web API running in a `docker` container.\n\n**Advantages**\n- The segmentation can be run on a remote machine with optimization (e.g. GPU).\n- The segmentation models will be downloaded inside the docker container instead of the user's file system.\n- You can minimally install the package with `pip install napari-rembg` on the client's machine. This will *not* install the `rembg` library, which can solve potential dependency conflicts or bugs.\n\n**Setup**\n\nSee [these instructions](./src/rembg-api/README.md) on how to set up the docker container and web API.\n\n**Usage**\n\nStart `napari-rembg` from the `Plugins` menu of Napari:\n\n```\nPlugins > Napari Select Foreground > Select foreground (Web API)\n```\n\n## Related projects\n\nIf you are looking for similar generalist segmentation plugins, check out these related projects:\n\n- [napari-sam](https://github.com/MIC-DKFZ/napari-sam)\n- [napari-segment-anything](https://github.com/royerlab/napari-segment-anything)\n\n## Contributing\n\nContributions are very welcome. \n\n## License\n\nDistributed under the terms of the [BSD-3] license,\n\"napari-rembg\" is free and open source software.\n\n## Issues\n\nIf you encounter any problems, please file an issue along with a detailed description.\n\n[napari]: https://github.com/napari/napari\n[Cookiecutter]: https://github.com/audreyr/cookiecutter\n[@napari]: https://github.com/napari\n[BSD-3]: http://opensource.org/licenses/BSD-3-Clause\n[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin\n[pip]: https://pypi.org/project/pip/\n[PyPI]: https://pypi.org/\n\n----------------------------------\n\nThis [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "AI-based foreground extraction in scientific and natural images.",
"version": "0.0.7",
"project_urls": {
"Homepage": "https://github.com/EPFL-Center-for-Imaging/napari-rembg.git",
"Source Code": "https://github.com/EPFL-Center-for-Imaging/napari-rembg.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ee7c0506986d85fb0b7ef9612ce0525a34001ae32f6fd12fc2eadd7c041b1675",
"md5": "805f144d73e4a8611ce129dfe11370bd",
"sha256": "ddc555773c78d979914f129fe5be1c23889fbb4fe9d1ce0957e9e94e9deb0b4a"
},
"downloads": -1,
"filename": "napari_rembg-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "805f144d73e4a8611ce129dfe11370bd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11405,
"upload_time": "2024-02-17T10:07:37",
"upload_time_iso_8601": "2024-02-17T10:07:37.370539Z",
"url": "https://files.pythonhosted.org/packages/ee/7c/0506986d85fb0b7ef9612ce0525a34001ae32f6fd12fc2eadd7c041b1675/napari_rembg-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4f3a074f3be864fbf3e5b4fd82b8c566cd73409fb69287aec6190aab8802cb0f",
"md5": "23a57d652ab5ec2d3f02b9d07a7b576a",
"sha256": "2d44d3b5804cdb52d3cd7341d6f2b71f60a8bceb94b535ee046695ca1049bb46"
},
"downloads": -1,
"filename": "napari-rembg-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "23a57d652ab5ec2d3f02b9d07a7b576a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11613,
"upload_time": "2024-02-17T10:07:39",
"upload_time_iso_8601": "2024-02-17T10:07:39.104082Z",
"url": "https://files.pythonhosted.org/packages/4f/3a/074f3be864fbf3e5b4fd82b8c566cd73409fb69287aec6190aab8802cb0f/napari-rembg-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-17 10:07:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "EPFL-Center-for-Imaging",
"github_project": "napari-rembg",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "napari-rembg"
}