NiBabel

Access a cacophony of neuro-imaging file formats

This Page

Reggie -- the one

nibabel.nicom.dicomwrappers.Wrapper

digraph inheritance823f9afeb3 { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "Wrapper" [shape=ellipse,URL="#nibabel.nicom.dicomwrappers.Wrapper",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; }

class nibabel.nicom.dicomwrappers.Wrapper(dcm_data=None)

Class to wrap general DICOM files

Methods:

  • get_affine()
  • get_data()
  • get_pixel_array()
  • is_same_series(other)
  • __getitem__ : return attributes from dcm_data
  • get(key[, default]) - as usual given __getitem__ above

Attributes and things that look like attributes:

  • dcm_data : object
  • image_shape : tuple
  • image_orient_patient : (3,2) array
  • slice_normal : (3,) array
  • rotation_matrix : (3,3) array
  • voxel_sizes : tuple length 3
  • image_position : sequence length 3
  • slice_indicator : float
  • series_signature : tuple

Attributes

b_matrix
q_vector

Methods

get
get_affine
get_data
get_pixel_array
image_orient_patient
image_position
image_shape
instance_number
is_same_series
rotation_matrix
series_signature
slice_indicator
slice_normal
voxel_sizes

Initialize wrapper

Parameters :

dcm_data : None or object, optional

object should allow attribute access. Usually this will be a dicom.dataset.Dataset object resulting from reading a DICOM file. If None, just make an empty dict.

Attributes

b_matrix
q_vector

Methods

get
get_affine
get_data
get_pixel_array
image_orient_patient
image_position
image_shape
instance_number
is_same_series
rotation_matrix
series_signature
slice_indicator
slice_normal
voxel_sizes
b_matrix = None
get(key, default=None)
get_affine()

Return mapping between voxel and DICOM coordinate system

Parameters :

None :

Returns :

aff : (4,4) affine

Affine giving transformation between voxels in data array and mm in the DICOM patient coordinate system.

get_data()

Get scaled image data from DICOMs

We return the data as DICOM understands it, first dimension is rows, second dimension is columns

Returns :

data : array

array with data as scaled from any scaling in the DICOM fields.

get_pixel_array()

Return unscaled pixel array from DICOM

static image_orient_patient()

Note that this is _not_ LR flipped

static image_position()

Return position of first voxel in data block

Parameters :

None :

Returns :

img_pos : (3,) array

position in mm of voxel (0,0) in image array

static image_shape()

The array shape as it will be returned by get_data()

static instance_number()

Just because we use this a lot for sorting

is_csa = False
is_mosaic = False
is_same_series(other)

Return True if other appears to be in same series

Parameters :

other : object

object with series_signature attribute that is a mapping. Usually it’s a Wrapper or sub-class instance.

Returns :

tf : bool

True if other might be in the same series as self, False otherwise.

q_vector = None
static rotation_matrix()

Return rotation matrix between array indices and mm

Note that we swap the two columns of the ‘ImageOrientPatient’ when we create the rotation matrix. This is takes into account the slightly odd ij transpose construction of the DICOM orientation fields - see doc/theory/dicom_orientaiton.rst.

static series_signature()

Signature for matching slices into series

We use signature in self.is_same_series(other).

Returns :

signature : dict

with values of 2-element sequences, where first element is value, and second element is function to compare this value with another. This allows us to pass things like arrays, that might need to be allclose instead of equal

static slice_indicator()

A number that is higher for higher slices in Z

Comparing this number between two adjacent slices should give a difference equal to the voxel size in Z.

See doc/theory/dicom_orientation for description

static slice_normal()
static voxel_sizes()

voxel sizes for array as returned by get_data()