dicube.dicom.dicom_meta
dicom.dicom_meta
Classes
| Name | Description |
|---|---|
| DicomMeta | A class for managing metadata from multiple DICOM datasets. |
| SortMethod | Enumeration of available sorting methods for DICOM datasets. |
DicomMeta
dicom.dicom_meta.DicomMeta(merged_data, filenames=None)A class for managing metadata from multiple DICOM datasets.
Uses pydicom’s to_json_dict() to extract information from all levels (including sequences) of multiple DICOM datasets. Recursively determines which fields are: - Shared (identical across all datasets) - Non-shared (different across datasets)
Provides methods to access, modify, and serialize this metadata.
Attributes: _merged_data (Dict[str, Dict[str, Any]]): The merged metadata from all datasets. filenames (List[str], optional): List of filenames for the datasets. slice_count (int): Number of datasets represented.
Methods
| Name | Description |
|---|---|
| display | Display the DicomMeta in a tabular format. |
| from_datasets | Create a DicomMeta instance from a list of pydicom datasets. |
| from_json | Create a DicomMeta instance from a JSON string. |
| get_shared_value | Get the shared value for a tag if it’s shared across all datasets. |
| get_values | Get values for a tag across all datasets. |
| get_vr | Get the Value Representation (VR) for a tag. |
| index | Create a new DicomMeta with only the specified dataset. |
| is_missing | Check if a tag is missing from the metadata. |
| is_shared | Check if a tag has consistent values across all datasets. |
| items | Get all (key, value) pairs in the DicomMeta. |
| keys | Get all tag keys in the DicomMeta. |
| set_nonshared_item | Set a non-shared metadata item with different values for each dataset. |
| set_shared_item | Set a shared metadata item for all datasets. |
| sort_files | Sort the files in the DicomMeta. |
| to_json | Serialize the DicomMeta to a JSON string. |
display
dicom.dicom_meta.DicomMeta.display(show_shared=True, show_non_shared=True)Display the DicomMeta in a tabular format.
Args: show_shared (bool): If True, display shared metadata. Defaults to True. show_non_shared (bool): If True, display non-shared metadata. Defaults to True.
from_datasets
dicom.dicom_meta.DicomMeta.from_datasets(datasets, filenames=None)Create a DicomMeta instance from a list of pydicom datasets.
Args: datasets (List[pydicom.Dataset]): List of pydicom datasets. filenames (List[str], optional): List of filenames corresponding to the datasets. Defaults to None.
Returns: DicomMeta: A new DicomMeta instance created from the datasets.
from_json
dicom.dicom_meta.DicomMeta.from_json(json_str, filenames=None)Create a DicomMeta instance from a JSON string.
Args: json_str (str): JSON string containing DicomMeta data. filenames (List[str], optional): List of filenames corresponding to the datasets. Defaults to None.
Returns: DicomMeta: A new DicomMeta instance created from the JSON data.
get_values
dicom.dicom_meta.DicomMeta.get_values(tag_input)Get values for a tag across all datasets.
Args: tag_input: The tag to retrieve, can be a Tag object, string, or (group, element) tuple
Returns: List[Any]: List of values, one for each dataset. May contain None for datasets where the tag is not present.
get_vr
dicom.dicom_meta.DicomMeta.get_vr(tag_input)Get the Value Representation (VR) for a tag.
Args: tag_input: The tag to check, can be a Tag object, string, or (group, element) tuple
Returns: str: The VR code (e.g., “CS”, “LO”, “SQ”) or empty string if not found
index
dicom.dicom_meta.DicomMeta.index(index)Create a new DicomMeta with only the specified dataset.
Args: index (int): Index of the dataset to extract.
Returns: DicomMeta: A new DicomMeta containing only the specified dataset.
is_missing
dicom.dicom_meta.DicomMeta.is_missing(tag_input)Check if a tag is missing from the metadata.
Args: tag_input: The tag to check, can be a Tag object, string, or (group, element) tuple
Returns: bool: True if tag is missing or has no value, False if present with a value
items
dicom.dicom_meta.DicomMeta.items()Get all (key, value) pairs in the DicomMeta.
Returns: Iterator: Iterator over (key, value) pairs.
keys
dicom.dicom_meta.DicomMeta.keys()Get all tag keys in the DicomMeta.
Returns: List[str]: List of tag keys.
sort_files
dicom.dicom_meta.DicomMeta.sort_files(
sort_method=SortMethod.INSTANCE_NUMBER_ASC,
)Sort the files in the DicomMeta.
Args: sort_method (SortMethod): Method to use for sorting. Defaults to SortMethod.INSTANCE_NUMBER_ASC.
Raises: ValueError: If the sort method is not supported.
to_json
dicom.dicom_meta.DicomMeta.to_json()Serialize the DicomMeta to a JSON string.
Returns: str: JSON string representation of the DicomMeta.
SortMethod
dicom.dicom_meta.SortMethod()Enumeration of available sorting methods for DICOM datasets.
Attributes: INSTANCE_NUMBER_ASC (int): Sort by instance number in ascending order. INSTANCE_NUMBER_DESC (int): Sort by instance number in descending order. POSITION_RIGHT_HAND (int): Sort by position using right-hand coordinate system. POSITION_LEFT_HAND (int): Sort by position using left-hand coordinate system.