Segment

class photutils.segmentation.Segment(segment_data, label, slices, bbox, area)[source]

Bases: object

Class for a single labeled region (segment) within a segmentation image.

Parameters
segment_dataint ndarray

A segmentation array where source regions are labeled by different positive integer values. A value of zero is reserved for the background.

labelint

The segment label number.

slicestuple of two slices

A tuple of two slices representing the minimal box that contains the labeled region.

bboxBoundingBox

The minimal bounding box that contains the labeled region.

areafloat

The area of the segment in pixels**2.

Attributes Summary

data

A cutout array of the segment using the minimal bounding box, where pixels outside of the labeled region are set to zero (i.e., neighboring segments within the rectangular cutout array are not shown).

data_ma

A MaskedArray cutout array of the segment using the minimal bounding box.

Methods Summary

make_cutout(data[, masked_array])

Create a (masked) cutout array from the input data using the minimal bounding box of the segment (labeled region).

Attributes Documentation

data

A cutout array of the segment using the minimal bounding box, where pixels outside of the labeled region are set to zero (i.e., neighboring segments within the rectangular cutout array are not shown).

data_ma

A MaskedArray cutout array of the segment using the minimal bounding box.

The mask is True for pixels outside of the source segment (i.e., neighboring segments within the rectangular cutout array are masked).

Methods Documentation

make_cutout(data, masked_array=False)[source]

Create a (masked) cutout array from the input data using the minimal bounding box of the segment (labeled region).

If masked_array is False (default), then the returned cutout array is simply a ndarray. The returned cutout is a view (not a copy) of the input data. No pixels are altered (e.g., set to zero) within the bounding box.

If masked_array` is `True`, then the returned cutout array is a `~numpy.ma.MaskedArray`, where the mask is `True` for pixels outside of the segment (labeled region).  The data part of the masked array is a view (not a copy) of the input ``data.

Parameters
dataarray-like

The data array from which to create the masked cutout array. data must have the same shape as the segmentation array.

masked_arraybool, optional

If True then a MaskedArray will be created where the mask is True for pixels outside of the segment (labeled region). If False, then a ndarray will be generated.

Returns
resultndarray or MaskedArray

The cutout array.