Metadata-Version: 2.1
Name: jupyter_paint_segment
Version: 0.1.0
Summary: A jupyter widget for manual image segmantation
Home-page: https://github.com/adusachev/jupyter-paint-segment
License: MIT
Keywords: jupyter,widget,segmentation,image
Author: adusachev
Author-email: adusachev@yandex.ru
Requires-Python: >=3.9
Classifier: Framework :: Jupyter
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: anywidget (>=0.9.15,<0.10.0)
Requires-Dist: matplotlib (>=3.7.5,<4.0.0)
Requires-Dist: opencv-python (>=4.11.0.86,<5.0.0.0)
Requires-Dist: pandas (>=2.0.3,<3.0.0)
Requires-Dist: pillow (>=10.4.0,<11.0.0)
Project-URL: Repository, https://github.com/adusachev/jupyter-paint-segment
Description-Content-Type: text/markdown

# jupyter-paint-segment


## Overview

A jupyter widget for interactive drawing segmentation masks.

Brush, rectangle and eraser tools are available.
Size of brush and eraser can be changed using slider.


![](./docs/images/sheep_dog_interactive_v2.gif)


---

## Installation

```sh
pip install jupyter_paint_segment
```

requires: python >= 3.9


---

## Usage

Demo notebook: `./examples/main.ipynb`


1. Load image into numpy array:
```python
# with PIL: 
from PIL import Image
import numpy as np
pilImage = Image.open("./examples/images/sheeps.png")
image = np.array(pilImage)

# or with opencv:
import cv2 as cv
image_bgr = cv.imread("./examples/images/sheeps.png")
image = cv.cvtColor(image_bgr, cv.COLOR_BGR2RGB)
```

2. Define labels and colors (optionally) and create widget:
```python
from jupyter_paint_segment import SegmentWidget

widget = SegmentWidget(
    image=image,
    labels=["sheep", "dog"],
    colors=["red", "blue"],
    image_scale=1,
)
widget
```


3. Get segmentation results:
```python
labels_array, labels_map = widget.segmentation_result()

labels_map
# {'sheep': 1, 'dog': 2, 'unlabeled_background': 0}
labels_array
# array([[0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        ...,
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0],
#        [0, 0, 0, ..., 0, 0, 0]])
```

```python
import matplotlib.pyplot as plt

plt.imshow(labels_array)
```

![](./docs/images/result_seg_mask.png)


---


## Related projects

This project was highly inspired by [jupyter-bbox-widget](https://github.com/gereleth/jupyter-bbox-widget).


---

## License

This project is licensed under the [MIT license](https://github.com/adusachev/jupyter-paint-segment/blob/master/LICENSE).

---


