src.imagedata.formats package
Subpackages
Submodules
src.imagedata.formats.abstractplugin module
Abstract class for image formats.
Defines generic functions.
- class src.imagedata.formats.abstractplugin.AbstractPlugin(name, description, authors, version, url)[source]
Bases:
objectAbstract base class definition for imagedata format plugins. Plugins must be a subclass of AbstractPlugin and must define the atttributes set in __init__() and the following methods:
read() method write_3d_numpy() method write_4d_numpy() method
- Variables:
input_order
tags
transformationMatrix
- property authors
Plugin authors
Multi-line string naming the author(s) of the plugin.
- property description
Plugin description
Single line string describing the image format.
- getPositionForVoxel(r, transformation=None)[source]
Get patient position for center of given voxel r
Use Patient Position and Image Orientation to calculate world coordinates for given voxel
- Parameters:
r – (z,y,x) of voxel in voxel coordinates as numpy.array
transformation – transformation matrix when different from self.transformationMatrix
- Returns:
(z,y,x) of voxel in world coordinates (mm) as numpy.array
- getTimeline()[source]
Get timeline
- Returns:
- Timeline in seconds, as numpy array of floats
Delta time is given as seconds. First image is t=0. Length of array is number of tags.
- Raises:
ValueError – tags for dataset is not time tags
- getVoxelForPosition(p, transformation=None)[source]
Get voxel for given patient position p
Use Patient Position and Image Orientation to calculate world coordinates for given voxel
- Parameters:
p – (z,y,x) of voxel in world coordinates (mm) as numpy.array
transformation – transformation matrix when different from self.transformationMatrix
- Returns:
(z,y,x) of voxel in voxel coordinates as numpy.array
- property name
Plugin name
Single word string describing the image format. Typical names: dicom, nifti, itk.
- plugin_type = 'format'
- read(sources, pre_hdr, input_order, opts)[source]
Read image data
Generic version for images which will be sorted on their filenames.
- Parameters:
sources – list of sources to image data
pre_hdr – DICOM template
input_order – sort order
opts – Input options (dict)
- Returns:
- Tuple of
hdr: Header dict
si[tag,slice,rows,columns]: numpy array
- static replace_geometry_attributes(im, gim)[source]
Replace geometry attributes in image with values from gim
- property url
Plugin URL
URL string to the site of the plugin or the author(s).
- property version
Plugin version
String giving the plugin version. Version scheme: 1.0.0
src.imagedata.formats.dicomplugin module
src.imagedata.formats.itkplugin module
Read/Write image files using ITK
- exception src.imagedata.formats.itkplugin.DependencyError[source]
Bases:
ExceptionThrown when a required module could not be loaded.
- class src.imagedata.formats.itkplugin.ITKPlugin(name=None, description=None, authors=None, version=None, url=None)[source]
Bases:
AbstractPluginRead/write ITK files.
- authors = 'Erling Andersen'
- description = 'Read and write ITK files.'
- extensions = ['.mhd', '.mha', '.jpg', '.jpeg', '.tiff']
- get_image_from_numpy(image)[source]
Returns an itk Image created from the supplied scipy ndarray.
If the image_type is supported, will be automatically transformed to that type, otherwise the most suitable is selected.
- Note: always use this instead of directly the itk.PyBuffer, as that
object transposes the image axes.
- Parameters:
array (image an)
np.ndarray (type image)
- Returns:
an instance of itk.Image holding the array’s data, type itk.Image (instance)
- name = 'itk'
- url = 'www.helse-bergen.no'
- version = '2.1.0'
- write_3d_numpy(si, destination, opts)[source]
Write 3D numpy image as ITK file
- Parameters:
self – ITKPlugin instance
si – Series array (3D or 4D), including these attributes:
slices (-)
spacing (-)
imagePositions (-)
transformationMatrix (-)
orientation (-)
tags (-)
destination – dict of archive and filenames
opts – Output options (dict)
- write_4d_numpy(si, destination, opts)[source]
Write 4D numpy image as ITK files
- Parameters:
self – ITKPlugin instance
si – [tag,slice,rows,columns]: Series array, including these attributes:
slices (-)
spacing (-)
imagePositions (-)
transformationMatrix (-)
orientation (-)
tags (-)
destination – dict of archive and filenames
opts – Output options (dict)
- write_numpy_itk(si, archive, filename)[source]
Write single volume to file
- Parameters:
self – ITKPlugin instance, including these attributes: - slices (not used) - spacing - imagePositions - transformationMatrix - orientation (not used) - tags (not used)
si – numpy 3D array [slice,row,column]
archive – archive object
filename – file name
src.imagedata.formats.matplugin module
Read/Write Matlab-compatible MAT files
- exception src.imagedata.formats.matplugin.DependencyError[source]
Bases:
ExceptionThrown when a required module could not be loaded.
- exception src.imagedata.formats.matplugin.ImageTypeError[source]
Bases:
ExceptionThrown when trying to load or save an image of unknown type.
- class src.imagedata.formats.matplugin.MatPlugin[source]
Bases:
AbstractPluginRead/write MAT files.
- authors = 'Erling Andersen'
- description = 'Read and write MAT files.'
- extensions = ['.mat']
- name = 'mat'
- url = 'www.helse-bergen.no'
- version = '1.1.0'
- write_3d_numpy(si, destination, opts)[source]
Write 3D numpy image as MAT file
- Parameters:
self – MATPlugin instance
si – Series array (3D or 4D), including these attributes: slices, spacing, tags
destination – dict of archive and filenames
opts – Output options (dict)
- write_4d_numpy(si, destination, opts)[source]
Write 4D numpy image as MAT files
- Parameters:
self – MATPlugin instance
si[tag – Series array, including these attributes: slices, spacing, tags
slice – Series array, including these attributes: slices, spacing, tags
rows – Series array, including these attributes: slices, spacing, tags
columns] – Series array, including these attributes: slices, spacing, tags
destination – dict of archive and filenames
opts – Output options (dict)
src.imagedata.formats.niftiplugin module
Module contents
This module provides plugins for various imaging formats.
Standard plugins provides support for DICOM and Nifti image file formats.
- src.imagedata.formats.get_uid(k=[0]) UID[source]
Generator function which will return a unique UID.