# `shapes`: 2D shapes drawing¶

This module provides functions making masks on an image.

The `Polygon` class provides checking if a point is inside a polygon.

The whole module uses the (row, col) (i.e., (y, x))) convention for 2D coordinates.

circle_fill(int crow, int ccol, float radius)

Generates coordinate of image points lying in a disk.

Parameters
• crow (int) – Row of the center of the disk

• ccol (int) – Column of the center of the disk

Returns

Array coordinates of points inside the disk (might be negative)

Return type

2-tuple of numpy.ndarray (rows, cols)

Generates coordinate of image points lying in a ellipse.

Parameters
• crow (int) – Row of the center of the ellipse

• ccol (int) – Column of the center of the ellipse

Returns

Array coordinates of points inside the ellipse (might be negative)

Return type

2-tuple of numpy.ndarray (rows, cols)

draw_line(int row0, int col0, int row1, int col1, int width=1)

Line includes both end points. Width is handled by drawing parallel lines, so junctions of lines belonging to different octant with width > 1 will not look nice.

Using Bresenham line algorithm: Bresenham, J. E. Algorithm for computer control of a digital plotter. IBM Systems Journal. Vol 4 No 1. 1965. pp 25-30

Parameters
• row0 (int) – Start point row

• col0 (int) – Start point col

• row1 (int) – End point row

• col1 (int) – End point col

• width (int) – Thickness of the line in pixels (default 1) Width must be at least 1.

Returns

Array coordinates of points inside the line (might be negative)

Return type

2-tuple of numpy.ndarray (rows, cols)

Return a mask of boolean, True for pixels inside a polygon.

Parameters
• vertices (numpy.ndarray like container of dimension Nx2) – Strip of segments end points (row, column) or (y, x)

• shape (2-tuple of int) – size of the mask as (height, width)

Returns

Return type

numpy.ndarray of dimension shape

class Polygon(vertices)

Define a polygon that provides inside check and mask generation.

Parameters

vertices (Nx2 array of floats of (row, col)) – corners of the polygon

is_inside(self, row, col)

Check if (row, col) is inside or outside the polygon

Parameters
• row (float) –

• col (float) –

Returns

True if position is inside polygon, False otherwise