surfa.Overlay
surfa.Overlay#
- class surfa.Overlay(data, labels=None, metadata=None)#
1D mesh overlay class defining an array with data frames.
- Parameters
data (array_like) – Image data array.
labels (dict or LabelLookup, optional) – Label-name lookup for segmentation indices.
metadata (dict, optional) – Dictionary containing arbitrary array metadata.
Attributes
basedim
Base spatial dimensionality of the array (always excludes frame dimension).
baseshape
Base spatial shape of the data array (always excludes the frame dimension).
data
Core data numpy ndarray.
dtype
Data type.
framed_data
Core data array reshaped to include the frame dimension, regardless of nframes.
labels
Label-name lookup for segmentation indices.
metadata
Dictionary to store various metadata associated with the image.
nframes
Number of data frames.
shape
True shape of the internal data array.
size
Total number of elements in the data array.
Methods
- astype(dtype, copy=True, order='K')#
Copy of the array, casted to a specified type.
- Parameters
dtype (np.dtype) – Target datatype.
copy (bool) – Return copy if array already has matching datatype.
order ({‘C’, ‘F’, ‘A’, ‘K’}) – Controls the memory layout order of the result. ‘C’ means C order, ‘F’ means Fortran order, ‘A’ means ‘F’ order if all the arrays are Fortran contiguous, ‘C’ order otherwise, and ‘K’ means as close to the order the array elements appear in memory as possible.
- Returns
arr – Array with target datatype.
- Return type
- ceil()#
Ceil the array to integer values.
- clip(a_min, a_max)#
Clip the array between low and high values.
- Parameters
a_min (array_like or None) – Minimum and maximum value. If None, clipping is not performed on the corresponding edge
a_max (array_like or None) – Minimum and maximum value. If None, clipping is not performed on the corresponding edge
- collapse(mapping=None)#
Collapse a one-hot encoded probabilistic map to discrete labels.
- Parameters
mapping (array_like of int) – List of label indices that correspond to probabilistic data frames encoded.
- Returns
arr – Collapsed, discrete segmentation array.
- Return type
- copy()#
Return a deep copy of the object.
- floor()#
Floor the array to integer values.
- max(frames=False)#
Compute the maximum.
- Parameters
frames (bool) – Compute max along frame axis.
- Returns
Returns scalar max value, unless frames=True, in which case a new Overlay is returned.
- Return type
scalar or Overlay
- mean(nonzero=False, frames=False)#
Compute the mean.
- Parameters
nonzero (bool) – If enabled, only consider nonzero elements. This is ignored if frames=True.
frames (bool) – Compute mean along frame axis.
- Returns
Returns scalar mean value, unless frames is set to true, in which case a new Overlay is returned.
- Return type
scalar or Overlay
- min(nonzero=False, frames=False)#
Compute the minimum.
- Parameters
nonzero (bool) – If enabled, only consider nonzero elements. This is ignored if frames=True.
frames (bool) – Compute min along frame axis.
- Returns
Returns scalar min value, unless frames is set to true, in which case a new Overlay is returned.
- Return type
scalar or Overlay
- new(data)#
Return a new instance of the array with updated data. Metadata is preserved.
- onehot(mapping, dtype=<class 'numpy.int32'>)#
Convert discrete labels to a one-hot encoded probabilistic map.
- Parameters
mapping (array_like of int) – List of label indices to one-hot encode. Label order is preserved.
dtype (np.dtype) – Output segmentation datatype.
- Returns
arr – Multi-frame one-hot segmentation array.
- Return type
- percentile(percentiles, method='linear', nonzero=False)#
Compute the q-th percentile of the data.
- Parameters
percentiles (array_like of float) – Percentile or sequence of percentiles to compute, which must be between 0 and 100 inclusive.
method (str) – Method to use for estimating the percentile. View numpy percentile doc for more information.
nonzero (bool) – If enabled, only consider nonzero elements.
- Returns
percentile – Computes percentiles.
- Return type
scalar or ndarray
- round()#
Round the array to the nearest integer value.
- save(filename, fmt=None, intent=0)#
Write array to file.
- Parameters
filename (str) – Target filename to write array to.
fmt (str) – Optional file format to force.
- unique()#
Find all unique elements of an array, sorted.
- zeros(dtype=None, frames=None, order='K')#
Return a copy of the framed array with all elements set to zero.
- Parameters
dtype (np.dtype) – Data type of new array.
frames (int) – Number of frames to allocate. If None, the number of frames is determined from the source array.
order ({‘C’, ‘F’, ‘K’}) – Controls the memory layout order of the result. ‘C’ means C order, ‘F’ means Fortran order, and ‘K’ means as close to the order the array elements appear in memory as possible.
- Returns
arr – Array with zero values.
- Return type