Skip to content

A Python+OpenCV implementation similar to Adobe Photoshop's magic wand selection tool.

License

Notifications You must be signed in to change notification settings

xixixihaha/magicwand

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

magicwand

A Python+OpenCV implementation similar to Adobe Photoshop's magic wand selection tool.

Displays an image with a tolerance trackbar. A user can click anywhere on the image to select a region with similar colors, where the range of allowable deviation from a color is given by the trackbar value.

usage

import cv2
from magicwand import SelectionWindow
image = cv2.imread('lane.jpg', 0)
window = SelectionWindow('Selection Window', image)
window.show()

files

example.py     An example script showing usage of the module magicwand.py
lane.jpg       An example image for the example script
LICENSE.txt    MIT license
magicwand.py   Main module containing the SelectionWindow class

methods

There are some internal ("private") methods to run the selection task and modify the displayed image, and there are some public methods implemented in magicwand.py which can help get some information about the accepted selection:

   min, max = getMinMax() returns the min and max color inside the selection mean, stddev = getMeanStdDev() returns the mean and standard deviation of color inside the selection

Both functions return two 3-vector numpy arrays if the image is 3-channel, otherwise they return two single values.

future

In the future, support will be added to add to the current selection, and maybe subtract as well. Allowing the change of colorspaces may be helpful, but will only make sense if each channel will have their own sliders; having a range of hue values the the same range of saturation values doesn't really make sense otherwise. I may build out the SelectionWindow class to a more general ImageWindow class to make it easier for people to add trackbars and mouseclick events and listen to them.

About

A Python+OpenCV implementation similar to Adobe Photoshop's magic wand selection tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%