fissa.polygons module#

Polygon tools.

Changed in version 1.0.0: Module renamed from fissa.ROI to fissa.polygons.

The functions below were adapted from the sima package http://www.losonczylab.org/sima, version 1.3.0. https://github.com/losonczylab/sima/blob/1.3.0/sima/ROI.py

License

This file is Copyright (C) 2014 The Trustees of Columbia University in the City of New York.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

fissa.polygons.poly2mask(polygons, im_size)[source]#

Convert polygons to a sparse binary mask.

>>> from fissa.polygons import poly2mask
>>> poly1 = [[0, 0], [0, 1], [1, 1], [1, 0]]
>>> poly2 = [[0, 1], [0, 2], [2, 2], [2, 1]]
>>> mask = poly2mask([poly1, poly2], (3, 3))
>>> mask[0].todense()
matrix([[ True, False, False],
        [ True,  True, False],
        [False, False, False]], dtype=bool)
Parameters
polygonssequence of coordinates or sequence of Polygons

A sequence of polygons where each is either a sequence of (x, y) or (x, y, z) coordinate pairs, an Nx2 or Nx3 numpy array, or a Polygon object.

im_sizetuple

Final size of the resulting mask.

Returns
maskslist of sparse matrices

A list of sparse binary masks of the points contained within the polygons, one mask per plane. Each mask is in linked list sparse matrix format.