nanslice.box module

Box.py

Contains a simple bounding-box class

class nanslice.box.Box(center=None, size=None, corners=None)[source]

Bases: object

A simple bounding-box class

Constructor parameters:

  • center – The center of the box (x,y,z) in world-space co-ordinates
  • size – The size of the box (x,y,z) in world-space units
  • corners – Two corners (x,y,z) of the box in world-space co-ordinates

Either corners or both center and size must be specified

center

Returns the geometric center of the bounding-box

diag

Returns the vector diagonal of the bounding-box

end

Returns the ‘end’ corner of the bounding-box (opposite the start)

classmethod fromImage(img)[source]

Creates a bounding box from the corners defined by an image

Parameters:

  • img – An nibabel image
classmethod fromMask(img, padding=0)[source]

Creates a bounding box that encloses all non-zero voxels in a volume

Parameters:

  • img – The volume to create the bounding-box from
  • padding – Number of extra voxels to pad the resulting box by
slice_positions(num_slices, start=0, end=1)[source]

Returns an array of slice positions along the specified axis

start

Returns the ‘start’ corner of the bounding-box