dicom2nifti.common module

dicom2nifti

@author: abrys

dicom2nifti.common.apply_scaling(data, dicom_headers)[source]

Rescale the data based on the RescaleSlope and RescaleOffset Based on the scaling from pydicomseries

Parameters:
  • dicom_headers – dicom headers to use to retreive the scaling factors
  • data – the input data
dicom2nifti.common.create_affine(sorted_dicoms)[source]

Function to generate the affine matrix for a dicom series This method was based on (http://nipy.org/nibabel/dicom/dicom_orientation.html)

Parameters:sorted_dicoms – list with sorted dicom files
dicom2nifti.common.do_scaling(data, rescale_slope, rescale_intercept, private_scale_slope=1.0, private_scale_intercept=0.0)[source]
dicom2nifti.common.get_fd_array_value(tag, count)[source]

Getters for data that also work with implicit transfersyntax

Parameters:
  • count – number of items in the array
  • tag – the tag to read
dicom2nifti.common.get_fd_value(tag)[source]

Getters for data that also work with implicit transfersyntax

Parameters:tag – the tag to read
dicom2nifti.common.get_fl_value(tag)[source]

Getters for data that also work with implicit transfersyntax

Parameters:tag – the tag to read
dicom2nifti.common.get_is_value(tag)[source]

Getters for data that also work with implicit transfersyntax

Parameters:tag – the tag to read
dicom2nifti.common.get_numpy_type(dicom_header)[source]

Make NumPy format code, e.g. “uint16”, “int32” etc from two pieces of info: mosaic.PixelRepresentation – 0 for unsigned, 1 for signed; mosaic.BitsAllocated – 8, 16, or 32

Parameters:dicom_header – the read dicom file/headers
Returns:numpy format string
dicom2nifti.common.get_ss_value(tag)[source]

Getters for data that also work with implicit transfersyntax

Parameters:tag – the tag to read
dicom2nifti.common.get_volume_pixeldata(sorted_slices)[source]

the slice and intercept calculation can cause the slices to have different dtypes we should get the correct dtype that can cover all of them

Parameters:sorted_slices (list of slices) – sliced sored in the correct order to create volume
dicom2nifti.common.is_ge(dicom_input)[source]

Use this function to detect if a dicom series is a GE dataset

Parameters:dicom_input – list with dicom objects
dicom2nifti.common.is_hitachi(dicom_input)[source]

Use this function to detect if a dicom series is a hitachi dataset

Parameters:dicom_input – directory with dicom files for 1 scan of a dicom_header
dicom2nifti.common.is_multiframe_dicom(dicom_input)[source]

Use this function to detect if a dicom series is a siemens 4D dataset NOTE: Only the first slice will be checked so you can only provide an already sorted dicom directory (containing one series)

Parameters:dicom_input – directory with dicom files for 1 scan
dicom2nifti.common.is_orthogonal(dicoms, log_details=False)[source]

Validate that volume is orthonormal

Parameters:dicoms – check that we have a volume without skewing
dicom2nifti.common.is_philips(dicom_input)[source]

Use this function to detect if a dicom series is a philips dataset

Parameters:dicom_input – directory with dicom files for 1 scan of a dicom_header
dicom2nifti.common.is_siemens(dicom_input)[source]

Use this function to detect if a dicom series is a siemens dataset

Parameters:dicom_input – directory with dicom files for 1 scan
dicom2nifti.common.is_valid_imaging_dicom(dicom_header)[source]

Function will do some basic checks to see if this is a valid imaging dicom

dicom2nifti.common.read_dicom_directory(dicom_directory, stop_before_pixels=False)[source]

Read all dicom files in a given directory (stop before pixels)

Parameters:
  • stop_before_pixels (bool) – Should we stop reading before the pixeldata (handy if we only want header info)
  • dicom_directory (six.string_types) – Directory with dicom data
Returns:

List of dicom objects

dicom2nifti.common.set_fd_value(tag, value)[source]

Setters for data that also work with implicit transfersyntax

Parameters:
  • value – the value to set on the tag
  • tag – the tag to read
dicom2nifti.common.set_ss_value(tag, value)[source]

Setter for data that also work with implicit transfersyntax

Parameters:
  • value – the value to set on the tag
  • tag – the tag to read
dicom2nifti.common.set_tr_te(nifti_image, repetition_time, echo_time)[source]

Set the tr and te in the nifti headers

Parameters:
  • echo_time – echo time
  • repetition_time – repetition time
  • nifti_image – nifti image to set the info to
dicom2nifti.common.sort_dicoms(dicoms)[source]

Sort the dicoms based om the image possition patient

Parameters:dicoms – list of dicoms
dicom2nifti.common.validate_orientation(dicoms)[source]

Validate that all dicoms have the same orientation

Parameters:dicoms – list of dicoms
dicom2nifti.common.validate_orthogonal(dicoms)[source]

Validate that volume is orthonormal

Parameters:dicoms – check that we have a volume without skewing
dicom2nifti.common.validate_slicecount(dicoms)[source]

Validate that volume is big enough to create a meaningfull volume This will also skip localizers and alike

Parameters:dicoms – list of dicoms
dicom2nifti.common.validate_sliceincrement(dicoms)[source]

Validate that the distance between all slices is equal (of very close to)

Parameters:dicoms – list of dicoms
dicom2nifti.common.write_bval_file(bvals, bval_file)[source]

Write an array of bvals to a bval file

Parameters:
  • bvals – array with the values
  • bval_file – filepath to write to
dicom2nifti.common.write_bvec_file(bvecs, bvec_file)[source]

Write an array of bvecs to a bvec file

Parameters:
  • bvecs – array with the vectors
  • bvec_file – filepath to write to