samuroi.masks package

Classes

class samuroi.masks.branch.BranchMask(data=None, name=None)[source]

Bases: samuroi.masks.mask.Mask

Represent a dendrite branch, or part of a dendrite branch. Provide functionality for splitting, joining and iterating over segments.

append(other, gap=False)[source]
changed = None

The event which will be triggered when the branch mask was changed.

children

Get the list of child segments of this branch.

Warning

Do not modify this list manually. Instead use samuroi.masks.branch.BranchMask.split().

Returns:the list of children.
data
Returns:return the data of the wrapped samuroi.util.branch.Branch object.
static from_hdf5(f)[source]
linescan(data, mask)[source]

Calculate the trace for all children and return a 2D array of traces. :param data: the data to apply on. :param mask: some additional overlay mask :return: 2D numpy array holding traces for all children

move(offset)[source]

Move the branch and all its children.

outline
Returns:return the outline of the wrapped samuroi.util.branch.Branch object.
segments = None

Child masks aka segments of the branch.

split(nsegments=2, length=None, k=1, s=0)[source]

Split this branch and create a set of child segments.

Note

One can either provide a nsegments or length.

Splitting of a branch will modify the samuroi.masks.branch.BranchMask.children attribute and hence trigger a samuroi.masks.branch.BranchMask.changed event.

Parameters:
  • nsegments – the number of segments.
  • length – the length of each segment (the last segment will have the remainder of modulo division).
  • k – smoothness parameter for spline interpolation
  • s – smoothness parameter for spline interpolation
to_hdf5(f)[source]
class samuroi.masks.circle.CircleMask(center, radius, name=None)[source]

Bases: samuroi.masks.mask.Mask

center
static from_hdf5(f)[source]
move(offset)[source]

Move the circle mask in the direction defined by offset. Will trigger the changed event. :param offset: list with two elements denoting x (positive right, negative left) and y (positive up, negative down).

radius
to_hdf5(f)[source]
class samuroi.masks.mask.Mask(name=None)[source]

If a mask is mutable, it needs to provide a changed signal, which is supposed to be triggered upon modification.

__call__(data, mask)[source]

Apply self on data and calculate the time trace. Before the application of self, the data is masked with the mask provided in the parameters. I.e. the final resulting mask is an and composition of self and mask.

Parameters:
  • data – the video data .
  • mask – a 2D mask array with same shape as video resolution.
Returns:

1D numpy array holding the time trace of this mask.

__weakref__

list of weak references to the object (if defined)

to_hdf5(f)[source]

Save the mask to to an opened hd5 file. :param f: the hd5 file handle.

class samuroi.masks.pixel.PixelMask(name=None, xy=None, x=None, y=None)[source]

Bases: samuroi.masks.mask.Mask

static from_hdf5(f)[source]
to_hdf5(f)[source]
x
y
class samuroi.masks.polygon.PolygonMask(outline, name=None)[source]

Bases: samuroi.masks.mask.Mask

A mask that is defined by the corners of a polygon

static from_hdf5(f)[source]
lowerleft
move(offset)[source]
outline
to_hdf5(f)[source]
upperright
weights

Generate the weight mask of the rectangular area covering the given polygon.

class samuroi.masks.segment.SegmentMask(data, parent)[source]

Bases: samuroi.masks.mask.Mask

data
Returns:return the data of the wrapped samuroi.util.branch.Branch object.
join(next=True)[source]
Join two segments into one. Arguments:
next: True or False, denote whether to join the segment with the preceding or succeeding one.
move(offset)[source]

Move the segment don’t trigger any event since this will be handled by the parent branch object.

outline
Returns:return the outline of the wrapped samuroi.util.branch.Branch object.
split(nsegments=2, length=None, k=1, s=0)[source]

Split the segment in n equal parts, and adopt the parent branch accordingly.

class samuroi.masks.segmentation.Segmentation(data, name=None)[source]

Bases: samuroi.masks.mask.Mask

Represent a full segmentation of the 2D array. The segmentation should be immutable. Maybe a special handling for index 0 would be nice?!?

class Child(parent, index)[source]

Bases: samuroi.masks.mask.Mask

A proxy object that implements the mask interface but is just a facade around one index of the segmentation

parent
x
y
Segmentation.children
Segmentation.data
static Segmentation.from_hdf5(f)[source]
Segmentation.to_hdf5(f)[source]