dbdicom.DataBaseDicom#

class dbdicom.DataBaseDicom(path)[source]#

Class to read and write a DICOM folder.

Parameters:

path (str) – path to the DICOM folder.

Methods

__init__(path)

close()

Close the DICOM folder

copy(from_entity, to_entity)

Copy a DICOM entity (patient, study or series)

delete(entity)

Delete a DICOM entity from the database

from_nifti(file, series[, ref, multislice])

Create a DICOM series from a nifti file.

move(from_entity, to_entity)

Move a DICOM entity

patients([name, contains, isin])

Return a list of patients in the DICOM folder.

pixel_data(series[, dims, include])

Read the pixel data from a DICOM series

print()

Print the contents of the DICOM folder

read()

Read the DICOM folder again

restore()

Restore the DICOM folder to the last saved state.

series([entity, name, contains, isin])

Return a list of series in the DICOM folder.

studies([entity, name, contains, isin])

Return a list of studies in the DICOM folder.

summary()

Return a summary of the contents of the database.

to_nifti(series, file[, dims, multislice])

Save a DICOM series in nifti format.

unique(pars, entity)

Return a list of unique values for a DICOM entity

volume(series[, dims, multislice])

Read a vreg.Volume3D from a DICOM series

write_volume(vol, series[, ref, multislice])

Write a vreg.Volume3D to a DICOM series

close()[source]#

Close the DICOM folder

This also saves changes in the header file to disk.

copy(from_entity, to_entity)[source]#

Copy a DICOM entity (patient, study or series)

Parameters:
  • from_entity (list) – entity to copy

  • to_entity (list) – entity after copying.

delete(entity)[source]#

Delete a DICOM entity from the database

Parameters:

entity (list) – entity to delete

from_nifti(file: str, series: list, ref: list | None = None, multislice=False)[source]#

Create a DICOM series from a nifti file.

Parameters:
  • file (str) – file path of the nifti file.

  • series (list) – DICOM series to create

  • ref (list) – DICOM series to use as template.

  • multislice (bool, optional) – Whether the data are to be written as multislice or not. In multislice data the voxel size is written in the slice gap rather thaan the slice thickness. Defaults to False.

move(from_entity, to_entity)[source]#

Move a DICOM entity

Parameters:

entity (list) – entity to move

patients(name=None, contains=None, isin=None)[source]#

Return a list of patients in the DICOM folder.

Parameters:
  • name (str, optional) – value of PatientName, to search for individuals with a given name. Defaults to None.

  • contains (str, optional) – substring of PatientName, to search for individuals based on part of their name. Defaults to None.

  • isin (list, optional) – List of PatientName values, to search for patients whose name is in the list. Defaults to None.

Returns:

list of patients fulfilling the criteria.

Return type:

list

pixel_data(series: list, dims: list | None = None, include=None) ndarray[source]#

Read the pixel data from a DICOM series

Parameters:
  • series (list) – DICOM series to read

  • dims (list, optional) – Dimensions of the array.

  • include (list, optional) – list of DICOM attributes that are read on the fly to avoid reading the data twice.

Returns:

numpy array with pixel values and an array with

coordinates of the slices according to dims. If include is provide these are returned as a dictionary in a third return value.

Return type:

tuple

print()[source]#

Print the contents of the DICOM folder

read()[source]#

Read the DICOM folder again

restore()[source]#

Restore the DICOM folder to the last saved state.

series(entity=None, name=None, contains=None, isin=None)[source]#

Return a list of series in the DICOM folder.

Parameters:
  • entity (str or list) – path to a DICOM folder (to search in the whole folder), or a list identifying a patient or a study (to search series of a given patient or study).

  • name (str, optional) – value of SeriesDescription, to search for series with a given description. Defaults to None.

  • contains (str, optional) – substring of SeriesDescription, to search for series based on part of their description. Defaults to None.

  • isin (list, optional) – List of SeriesDescription values, to search for series whose description is in a list. Defaults to None.

Returns:

list of series fulfilling the criteria.

Return type:

list

studies(entity=None, name=None, contains=None, isin=None)[source]#

Return a list of studies in the DICOM folder.

Parameters:
  • entity (str or list) – path to a DICOM folder (to search in the whole folder), or a two-element list identifying a patient (to search studies of a given patient).

  • name (str, optional) – value of StudyDescription, to search for studies with a given description. Defaults to None.

  • contains (str, optional) – substring of StudyDescription, to search for studies based on part of their description. Defaults to None.

  • isin (list, optional) – List of StudyDescription values, to search for studies whose description is in a list. Defaults to None.

Returns:

list of studies fulfilling the criteria.

Return type:

list

summary()[source]#

Return a summary of the contents of the database.

Returns:

Nested dictionary with summary information on the database.

Return type:

dict

to_nifti(series: list, file: str, dims=None, multislice=False)[source]#

Save a DICOM series in nifti format.

Parameters:
  • series (list) – DICOM series to read

  • file (str) – file path of the nifti file.

  • dims (list, optional) – Non-spatial dimensions of the volume. Defaults to None.

  • multislice (bool, optional) – Whether the data are to be read as multislice or not. In multislice data the voxel size is taken from the slice gap rather thaan the slice thickness. Defaults to False.

unique(pars: list, entity: list) dict[source]#

Return a list of unique values for a DICOM entity

Parameters:
  • pars (list) – attributes to return.

  • entity (list) – DICOM entity to search (Patient, Study or Series)

Returns:

dictionary with unique values for each attribute.

Return type:

dict

volume(series: list, dims: list | None = None, multislice=False) Volume3D[source]#

Read a vreg.Volume3D from a DICOM series

Parameters:
  • series (list) – DICOM series to read

  • dims (list, optional) – Non-spatial dimensions of the volume. Defaults to None.

  • multislice (bool, optional) – Whether the data are to be read as multislice or not. In multislice data the voxel size is taken from the slice gap rather thsan the slice thickness. Defaults to False.

Returns:

vole read from the series.

Return type:

vreg.Volume3D

write_volume(vol: Volume3D, series: list, ref: list | None = None, multislice=False)[source]#

Write a vreg.Volume3D to a DICOM series

Parameters:
  • vol (vreg.Volume3D) – Volume to write to the series.

  • series (list) – DICOM series to read

  • dims (list, optional) – Non-spatial dimensions of the volume. Defaults to None.

  • multislice (bool, optional) – Whether the data are to be read as multislice or not. In multislice data the voxel size is taken from the slice gap rather thsan the slice thickness. Defaults to False.