Polygon Utitilities¶
Drawing¶
Mahotas is not a package to generate images, but there are a few simple functions to draw lines and polygons on an image (the target image is known as the canvas in this documentation).
The simplest function is line
: Give it two points and it draws a line
between them. The implementation is simple, and in Python, so it will be slow
for many complex usage.
The main purpose of these utilities is to aid debugging and visualisation. If you need to generate fancy graphs, look for packages such as matplotlib.
Convex Hull¶
Convex hull functions are a more typical image processing feature. Mahotas has
a simple one, called convexhull
. Given a boolean image (or anything that
will get interpreted as a boolean image), it finds the convex hull of all its
on points.
The implementation is in C++, so it is fast.
A companion function fill_convexhull
returns the convex hull as a binary
image.
API Documentation¶

mahotas.polygon.
line
((y0, x0), (y1, x1), canvas, color=1) Draw a line
Parameters: p0 : pair of integers
first point
p1 : pair of integers
second point
canvas : ndarray
where to draw, will be modified in place
color : integer, optional
which value to store on the pixels (default: 1)
Notes

mahotas.polygon.
fill_polygon
([(y0, x0), (y1, x1), ..., ]canvas, color=1) Draw a filled polygon in canvas
Parameters: polygon : list of pairs
a list of (y,x) points
canvas : ndarray
where to draw, will be modified in place
color : integer, optional
which colour to use (default: 1)

mahotas.polygon.
convexhull
(bwimg) Compute the convex hull as a polygon
This is an implementation of the Graham Scan: http://en.wikipedia.org/wiki/Graham_scan
Parameters: bwimg : ndarray
input image (interpreted as boolean). Only 2D arrays are supported.
Returns: hull : ndarray
Set of (y,x) coordinates of hull corners

mahotas.polygon.
fill_convexhull
(bwimg) Compute the convex hull and return it as a binary mask
Parameters: bwimage : input image (interpreted as boolean) Returns: hull : image of same size and dtype as bwimg with the hull filled in.