Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alkasm/magicwand
A Python+OpenCV implementation similar to Adobe Photoshop's magic wand selection tool.
https://github.com/alkasm/magicwand
Last synced: 13 days ago
JSON representation
A Python+OpenCV implementation similar to Adobe Photoshop's magic wand selection tool.
- Host: GitHub
- URL: https://github.com/alkasm/magicwand
- Owner: alkasm
- License: mit
- Created: 2017-08-23T08:52:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-03T06:18:35.000Z (about 5 years ago)
- Last Synced: 2024-10-12T16:27:26.538Z (29 days ago)
- Language: Python
- Size: 1.07 MB
- Stars: 91
- Watchers: 5
- Forks: 25
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
## magicwand
Flood filling masking tool.
Displays an image with a tolerance trackbar. A user can click anywhere on the image to seed a selection, where the range of allowable deviation from a color is given by the trackbar value. The mean and standard deviation of the selected region is displayed in the window's status bar.
![Example Image](readme-example.png)
## Getting Started
Install into a Python virtual environment, as you would any other Python project.
```sh
$ python3 -m venv venv
$ source venv/bin/activate
(venv) $ pip install git+https://github.com/alkasm/magicwand
```Run the module as a script on any image you want:
```sh
(venv) $ python3 -m magicwand path/to/image.png
```## Usage
As a script, just run the module directly as above. You can always check the `--help` flag when running the module as a script for more info:
```sh
(venv) $ python3 -m magicwand --help
usage: magic wand selector [-h] imagepositional arguments:
image path to imageoptional arguments:
-h, --help show this help message and exit
```Use inside your own Python projects:
```python
>>> from magicwand import SelectionWindow
>>> import cv2 as cv
>>>
>>> img = cv.imread("lane.jpg")
>>> window = SelectionWindow(img)
>>> window.show()
>>>
>>> print(f"Selection mean: {window.mean[:, 0]}.")
Selection mean: [106.76420172 93.78792503 89.71121334].
```The window object has a few properties you might be interested in after successfully filtering your image:
```python
>>> window.mean # average value for each channel - from cv.meanStdDev(img, mask)
>>> window.stddev # standard deviation for each channel - from cv.meanStdDev(img, mask)
>>> window.mask # mask from cv.floodFill()
>>> window.img # image input into the window
>>> window.seed # most recent seed point for cv.floodFill()
```