QuadTreeRegion#

class scarlet2.detect.QuadTreeRegion(bbox, capacity=5, sub_regions=None, boxes=None, depth=0, detect=None)[source]#

Bases: object

A QuadTree that stores bounding boxes (rather than points).

Boxes that span sub-region boundaries are stored in all overlapping sub-regions so that query() always returns the full set of overlapping boxes.

Parameters:
  • bbox (Box) – The box that encloses this region.

  • capacity (int) – Maximum number of boxes before the region is split.

  • sub_regions (list of QuadTreeRegion, optional) – Pre-existing sub-regions (normally left as None).

  • boxes (list of Box, optional) – Pre-existing boxes (normally left as None).

  • depth (int) – Depth of this node in the full tree (used for debugging).

  • detect (array-like, optional) – Detection image; when provided enables debug visualisations.

add(other_box)[source]#

Add a box to the region.

Parameters:

other_box (Box) – The box to insert.

add_footprints(footprints)[source]#

Insert bounding boxes for a list of Footprint objects.

Each box gets a .footprint attribute pointing back to the originating Footprint so it can be retrieved from a query.

Parameters:

footprints (list of Footprint) – Footprints to add bounding boxes for.

Return type:

self

footprint_image(bbox=None)[source]#

Return a 2-D image of all footprint masks in the tree.

Parameters:

bbox (Box, optional) – Output image bounding box. If None, the union of all footprint bounding boxes is used.

Returns:

image

Return type:

ndarray

property peaks#

Yield all Peak objects contained in the tree.

query(other_box=None)[source]#

Return all boxes that overlap with other_box.

Parameters:

other_box (Box, optional) – Query box. Defaults to the full region bbox.

Returns:

results – Boxes that overlap with other_box. A set is used so that boxes stored in multiple sub-regions are only returned once.

Return type:

set of Box

split()[source]#

Sub-divide this region into four quadrants.