nanslice.slicer module

slicer.py

This module contains the core Slicer object that samples Layers to produce image arrays that can be drawn with matlplotlib.

class nanslice.slicer.Slicer(bbox, pos, axis, samples=64, orient='clin')[source]

Bases: object

The Slicer class.

When constructed, creates an array of world-space co-ordinates which represent the desired slice

Constructor Parameters:

  • bbox – Box instance that defines the world-space bounding box that you want to slice
  • pos – Position within the box to generate the slice through
  • axis – Which axis you want to slice across. Either x/y/z or 0/1/2
  • samples – Number of samples in the horizontal direction
  • orient – ‘clin’ or ‘preclin’
get_voxel_coords(tfm)[source]

Returns an array of voxel space co-ordinates for this slice, which will be cached. If a subsequent call uses the same affine transform, the cached co-ordinates will be returned. If a new transform is passed in, then a fresh set of co-ordinates are calculated first.

Parameters:

  • tfm – An affine transform that defines an images physical space (usually the .affine property of an nibabel image)
sample(img, order, scale=1.0, volume=0)[source]

Samples the passed 3D/4D image and returns a 2D slice

Paramters:

  • img – An nibabel image
  • order – Interpolation order. 1 is linear interpolation
  • scale – Scale factor to multiply all voxel values by
  • volume – If sampling 4D data, specify the desired volume
nanslice.slicer.axis_indices(axis, orient='clin')[source]

Returns a pair of indices corresponding to right/up for the given orientation. Parameters: axis: The perpendicular axis to the slice. Use Axis_map to convert between x/y/z and 0/1/2 orient: Either ‘clin’ or ‘preclin’