# fiftyone.utils.dicom¶

DICOM utilities.

Classes:

 DICOMDatasetImporter([dataset_dir, …]) Importer for DICOM datasets datasets stored on disk. DICOMSampleParser([keywords, parsers]) Parser for labeled image samples stored in DICOM format.
class fiftyone.utils.dicom.DICOMSampleParser(keywords=None, parsers=None)

Parser for labeled image samples stored in DICOM format.

Parameters

Methods:

 Clears the current sample. Returns the image from the current sample. Returns the image metadata for the current sample. Returns the image path for the current sample. Returns the label for the current sample. with_sample(sample) Sets the current sample so that subsequent calls to methods of this parser will return information from the given sample.

Attributes:

 current_sample The current sample. has_image_metadata Whether this parser produces fiftyone.core.metadata.ImageMetadata instances for samples that it parses. has_image_path Whether this parser produces paths to images on disk for samples that it parses. label_cls The fiftyone.core.labels.Label class(es) returned by this parser.
property label_cls

The fiftyone.core.labels.Label class(es) returned by this parser.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the parser is guaranteed to return labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the parser can produce a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the parser will return label dictionaries with keys and value-types specified by this dictionary. Not all keys need be present in the imported labels

• None. In this case, the parser makes no guarantees about the labels that it may return

property has_image_path

Whether this parser produces paths to images on disk for samples that it parses.

property has_image_metadata

Whether this parser produces fiftyone.core.metadata.ImageMetadata instances for samples that it parses.

get_image()

Returns the image from the current sample.

Returns

a numpy image

get_label()

Returns the label for the current sample.

Returns

a fiftyone.core.labels.Label instance, or a dictionary mapping field names to fiftyone.core.labels.Label instances, or None if the sample is unlabeled

clear_sample()

Clears the current sample.

Also clears any cached sample information stored by the parser.

property current_sample

The current sample.

Raises

ValueError – if there is no current sample

get_image_metadata()

Returns the image metadata for the current sample.

Returns
get_image_path()

Returns the image path for the current sample.

Returns

the path to the image on disk

with_sample(sample)

Sets the current sample so that subsequent calls to methods of this parser will return information from the given sample.

Guaranteed to call clear_sample() before setting the current sample.

Parameters

sample – a sample

class fiftyone.utils.dicom.DICOMDatasetImporter(dataset_dir=None, dicom_path=None, images_dir=None, keywords=None, parsers=None, image_format=None, shuffle=False, seed=None, max_samples=None)

Importer for DICOM datasets datasets stored on disk.

Parameters
• dataset_dir (None) – the dataset directory. If omitted, dicom_path must be provided

• dicom_path (None) –

an optional parameter that enables explicit control over the location of the DICOM files. Can be any of the following:

• a glob pattern like "*.dcm" specifying the location of the DICOM files in dataset_dir

• the name of a DICOMDIR file in dataset_dir

• an absolute glob pattern of DICOM files or the absolute path to a DICOMDIR file. In this case, dataset_dir has no effect

If None, the parameter will default to *.dcm

• images_dir (None) – the directory in which the images will be written. If not provided, the images will be unpacked into dataset_dir

• keywords (None) – an optional keyword or list of keywords from pydicom.dataset.Dataset.dir() to load from the DICOM files. By default, all available fields are loaded

• parsers (None) – an optional dict mapping keywords to functions that parse the values generated by pydicom.dataset.Dataset.get() for certain fields. By default, all fields are converted to primitive values, if possible

• image_format (None) – the image format to use to write the images to disk. By default, fiftyone.config.default_image_ext is used

• shuffle (False) – whether to randomly shuffle the order in which the samples are imported

• seed (None) – a random seed to use when shuffling

• max_samples (None) – a maximum number of samples to import. By default, all samples are imported

Methods:

 close(*args) Performs any necessary actions after the last sample has been imported. Returns the dataset info for the dataset. Performs any necessary setup before importing the first sample in the dataset.

Attributes:

 has_dataset_info Whether this importer produces a dataset info dictionary. has_image_metadata Whether this importer produces fiftyone.core.metadata.ImageMetadata instances for each image. label_cls The fiftyone.core.labels.Label class(es) returned by this importer.
property label_cls

The fiftyone.core.labels.Label class(es) returned by this importer.

This can be any of the following:

• a fiftyone.core.labels.Label class. In this case, the importer is guaranteed to return labels of this type

• a list or tuple of fiftyone.core.labels.Label classes. In this case, the importer can produce a single label field of any of these types

• a dict mapping keys to fiftyone.core.labels.Label classes. In this case, the importer will return label dictionaries with keys and value-types specified by this dictionary. Not all keys need be present in the imported labels

• None. In this case, the importer makes no guarantees about the labels that it may return

property has_dataset_info

Whether this importer produces a dataset info dictionary.

property has_image_metadata

Whether this importer produces fiftyone.core.metadata.ImageMetadata instances for each image.

setup()

Performs any necessary setup before importing the first sample in the dataset.

This method is called when the importer’s context manager interface is entered, DatasetImporter.__enter__().

close(*args)

Performs any necessary actions after the last sample has been imported.

This method is called when the importer’s context manager interface is exited, DatasetImporter.__exit__().

Parameters

*args – the arguments to DatasetImporter.__exit__()

get_dataset_info()

Returns the dataset info for the dataset.

By convention, this method should be called after all samples in the dataset have been imported.

Returns

a dict of dataset info