manipulation and display of spatial regions in python
This package makes it easy to display spatial regions, and is useful when working with geometries, maps, feature extraction, or other spatial analyses. Designed to be small and light-weight, built on numpy
and scipy
, and composes with other modules for image analysis and display.
pip install regional
from regional import one
region = one([[0, 0], [0, 1], [1, 0], [1, 1]])
region.bbox
>> [[0, 1], [0, 1]]
region.center
>> [0.5, 0.5]
see the included notebook for a longer example
constructs a single region
coords
- list of coordinates
[[x, y], [x, y], ...]
- list of coordinates
list
:- list of regions
[region, region, ...]
or - list of lists of coordinates
[[[x, y], [x, y], ...], [[x, y], [x, y], ...], ...]
- list of regions
one
region and many
regions have the same attributes
and methods
, the only difference is that in the case of many
regions they are just evaluated once per region
convex hull
rectangular bounding box
euclidean center
total region extent
distance to other region
merge with other region
exclude other region
compute overlap with other region
crop region to bounds
check whether region falls completely within bounds
dilate region
compute region outline
generate image with regions as colored masks (value
and cmap
only for multiple regions)