Segment#
- class photutils.segmentation.Segment(segment_data, label, slices, bbox, area, *, polygon=None)[source]#
Bases:
objectClass 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.
- bbox
BoundingBox The minimal bounding box that contains the labeled region.
- areafloat
The area of the segment in pixels**2.
- polygonShapely polygon, optional
The outline of the segment as a Shapely polygon.
- segment_dataint
Notes
Only the minimal bounding-box cutout of the segmentation array is stored (as a copy), so
Segmentinstances do not prevent garbage collection of the parent array.Attributes Summary
A cutout array of the segment using the minimal bounding box, where pixels outside the labeled region are set to zero (i.e., neighboring segments within the rectangular cutout array are not shown).
A
MaskedArraycutout array of the segment using the minimal bounding box.Methods Summary
make_cutout(data[, masked_array])Create a (masked) cutout array from the input
datausing 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 the labeled region are set to zero (i.e., neighboring segments within the rectangular cutout array are not shown).
- data_masked#
A
MaskedArraycutout array of the segment using the minimal bounding box.The mask is
Truefor pixels outside 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
datausing the minimal bounding box of the segment (labeled region).If
masked_arrayisFalse(default), then the returned cutout array is simply andarray. The returned cutout is a view (not a copy) of the inputdata. No pixels are altered (e.g., set to zero) within the bounding box.If
masked_arrayisTrue, then the returned cutout array is aMaskedArray, where the mask isTruefor pixels outside the segment (labeled region). The data part of the masked array is a view (not a copy) of the inputdata.- Parameters:
- data2D
ndarray The data array from which to create the masked cutout array.
datamust have the same shape as the segmentation array.- masked_arraybool, optional
If
Truethen aMaskedArraywill be created where the mask isTruefor pixels outside the segment (labeled region). IfFalse, then andarraywill be generated.
- data2D
- Returns:
- result2D
ndarrayorMaskedArray The cutout array.
- result2D