How to flood-fill part of a bitmap enclosed by a black border with my chosen color?

前端 未结 2 418
孤城傲影
孤城傲影 2020-12-06 08:22

I want to programmatically modify a bitmap using python but don\'t really need a thorough grounding in the subject, so would like to concentrate on learning just what I need

相关标签:
2条回答
  • 2020-12-06 09:07

    PIL has an undocumented function ImageDraw.floodfill:

    >>> import ImageDraw
    >>> help(ImageDraw.floodfill)
    Help on function floodfill in module ImageDraw:
    
    floodfill(image, xy, value, border=None)
        Fill bounded region.
    

    (Flood-filling should generally be a last resort because it interacts poorly with anti-aliased lines. It is usually better to get the actual boundary data for the counties and then draw a filled polygon. However, PIL doesn't support anti-aliased line drawing so this advice is useless unless you switch your drawing module to something more capable like PythonMagick or pycairo.)

    0 讨论(0)
  • 2020-12-06 09:13

    You can try the opencv binding in python. Here is some example: http://opencv.willowgarage.com/documentation/python-introduction.html

    You can then use the cvFloodFill function to flood fill a region.

    0 讨论(0)
提交回复
热议问题