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])

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, coords, include])

Read the pixel data from a DICOM series

print()

Print the contents of the DICOM folder

read()

Read the DICOM folder again

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])

Save a DICOM series in nifti format.

unique(pars, entity)

Return a list of unique values for a DICOM entity

volume(series[, dims])

Read a vreg.Volume3D from a DICOM series

write_volume(vol, series[, ref])

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)[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.

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, coords=False, include=None) ndarray[source]#

Read the pixel data from a DICOM series

Parameters:
  • series (list or str) – DICOM series to read. This can also be a path to a folder containing DICOM files, or a patient or study to read all series in that patient or study. In those cases a list is returned.

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

  • coords (bool) – If set to Trye, the coordinates of the arrays are returned alongside the pixel data

  • 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, with

at least 3 dimensions (x,y,z). If coords is set these are returned too as an array with coordinates of the slices according to dims. If include is provide the values are returned as a dictionary in the last return value.

Return type:

numpy.ndarray or tuple

print()[source]#

Print the contents of the DICOM folder

read()[source]#

Read the DICOM folder again

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)[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.

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) 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.

Returns:

vole read from the series.

Return type:

vreg.Volume3D

write_volume(vol: Volume3D | tuple, series: list, ref: list | None = None)[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

  • ref (list) – Reference series