fiftyone.utils.dicom¶
DICOM utilities.
Classes:
|
Parser for labeled image samples stored in DICOM format. |
|
Importer for DICOM datasets datasets stored on disk. |
-
class
fiftyone.utils.dicom.
DICOMSampleParser
(keywords=None, parsers=None)¶ Bases:
fiftyone.utils.data.parsers.LabeledImageSampleParser
Parser for labeled image samples stored in DICOM format.
- Parameters
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 loadedparsers (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
Attributes:
The
fiftyone.core.labels.Label
class(es) returned by this parser.Whether this parser produces paths to images on disk for samples that it parses.
Whether this parser produces
fiftyone.core.metadata.ImageMetadata
instances for samples that it parses.The current sample.
Methods:
Returns the image from the current sample.
Returns the label for the current sample.
Clears the current sample.
Returns the image metadata for the current sample.
Returns the image path 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.
-
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 typea list or tuple of
fiftyone.core.labels.Label
classes. In this case, the parser can produce a single label field of any of these typesa 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 labelsNone
. 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 tofiftyone.core.labels.Label
instances, orNone
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
a
fiftyone.core.metadata.ImageMetadata
instance
-
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)¶ Bases:
fiftyone.utils.data.importers.LabeledImageDatasetImporter
,fiftyone.utils.data.importers.ImportPathsMixin
Importer for DICOM datasets datasets stored on disk.
See this page for format details.
- Parameters
dataset_dir (None) – the dataset directory. If omitted,
dicom_path
must be provideddicom_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 indataset_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 loadedparsers (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 possibleimage_format (None) – the image format to use to write the images to disk. By default,
fiftyone.config.default_image_ext
is usedshuffle (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
Attributes:
The
fiftyone.core.labels.Label
class(es) returned by this importer.Whether this importer produces a dataset info dictionary.
Whether this importer produces
fiftyone.core.metadata.ImageMetadata
instances for each image.Methods:
setup
()Performs any necessary setup before importing the first sample in the dataset.
close
(*args)Performs any necessary actions after the last sample has been imported.
Returns the dataset info for the dataset.
-
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 typea list or tuple of
fiftyone.core.labels.Label
classes. In this case, the importer can produce a single label field of any of these typesa 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 labelsNone
. 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