DICOM metadata is distinct from clientMetadata, which is the metadata associated with individual data units. See our tutorial on clientMetadata for more information.
DICOM related metadata is accessed by specifying the dataset using the <project_hash>. It contains the patient ID, series ID, and study ID that link the unlabeled DICOM data to the labeled data that is exported from Encord.
The following code reads and prints the patient ID (patient_id), series ID (series_uid) and study ID (study_uid) of all label rows in the specified Project.
#Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyclient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>")# Specify the project for which you want to read the patient and series IDsproject = client.get_project("<project_hash>")# Fetch the label and frame information for this projectlabel_rows = project.list_label_rows_v2()for label_row in label_rows:# Initialize labels label_row.initialise_labels()# Print Patient ID, Series ID, and Study IDprint(label_row.metadata)
The following code reads and prints frame specific DICOM metadata including the DICOM instance ID (dicom_instance_uid), the multiframe frame number (multiframe_frame_number), the file URI (file_uri) and the height as well as width of the frame, as can be seen in the sample output provided.
#Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyclient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>")# Specify the project for which you want to read the patient and series IDsproject = client.get_project("<project_hash>")# Fetch the label and frame information for this projectlabel_rows = project.list_label_rows_v2()for label_row in label_rows:# Initialize labels label_row.initialise_labels()# Print Frame specific DICOM metadatafor v in label_row.get_frame_views():print(v.metadata)
Use the script below to obtain the dimensions for a given slice or frame.
Width and height fields other than those printed by this script may be present in the metadata. These refer to the DICOM series’ dimensions (the maximum width and height of the series) and will not be applicable to all slices or frames.
#Import dependenciesfrom encord import EncordUserClient# Authenticate with Encord using the path to your private keyclient = EncordUserClient.create_with_ssh_private_key( ssh_private_key_path="<private_key_path>")# Specify the project for which you want to read the patient and series IDsproject = client.get_project("<project_hash>")# Fetch the label and frame information for this projectlabel_rows = project.list_label_rows_v2()for label_row in label_rows:# Initialize labels label_row.initialise_labels()for v in label_row.get_frame_views():print(f"frame width: {v.metadata.width}, height: {v.metadata.height}")