Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

something like gimp "fuzzy select" in python/PIL

I have image with some object at not solid background. I want to extract this objects like in gimp using "fuzzy select". This can be an example:

http://img249.imageshack.us/gal.php?g=25750902.png

Question is what is the best way to do it using python/PIL...

like image 263
Adam Avatar asked May 02 '10 17:05

Adam


Video Answer


2 Answers

I suppose you would need some flood-fill algorithm (such as breadth-first-traversal) in which you stop exploring pixels with different color than black.

Wikipedia has an excellent explanation with animations and pseudo-code

http://en.wikipedia.org/wiki/Flood_fill

like image 80
aioobe Avatar answered Sep 27 '22 16:09

aioobe


And besides, if you want to add feature like "tolerance" in Photoshop, you should apply this method Connected-component_labeling when getting connected vertex on your graph while doing flood fill

like image 36
batbaatar Avatar answered Sep 27 '22 17:09

batbaatar