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.
install
pip install regional
example
from regional import one
region = one([[0, 0], [0, 1], [1, 0], [1, 1]])
region.bbox
>> [0, 0, 1, 1]
region.center
>> [0.5, 0.5]
list of lists of coordinates [[[x, y], [x, y], ...], [[x, y], [x, y], ...], ...]
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
attributes
region.hull
convex hull
region.bbox
rectangular bounding box
region.center
euclidean center
region.extent
total region extent
methods
region.distance(other)
distance to other region
region.merge(other)
merge with other region
region.exclude(other)
exclude other region
region.overlap(other, method)
compute overlap with other region
region.crop(min, max)
crop region to bounds
region.inbounds(min, max)
check whether region falls completely within bounds
regional
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
numpyandscipy, and composes with other modules for image analysis and display.install
example
see the included notebook for a longer example
usage
region = one(coords)constructs a single region
coords[[x, y], [x, y], ...]regions = many(list)list:[region, region, ...]or[[[x, y], [x, y], ...], [[x, y], [x, y], ...], ...]oneregion andmanyregions have the sameattributesandmethods, the only difference is that in the case ofmanyregions they are just evaluated once per regionattributes
region.hullconvex hull
region.bboxrectangular bounding box
region.centereuclidean center
region.extenttotal region extent
methods
region.distance(other)distance to other region
region.merge(other)merge with other region
region.exclude(other)exclude other region
region.overlap(other, method)compute overlap with other region
region.crop(min, max)crop region to bounds
region.inbounds(min, max)check whether region falls completely within bounds
region.dilate(size)dilate region
region.outline(inner, outer)compute region outline
region.mask(dims, base, fill, stroke, background, value, cmap)generate image with regions as colored masks (
valueandcmaponly for multiple regions)