> ## Documentation Index
> Fetch the complete documentation index at: https://docs.encord.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Reading DICOM Metadata

<Note>DICOM metadata is distinct from `clientMetadata`, which is the metadata associated with individual data units. See our [tutorial on `clientMetadata`](/sdk-documentation/datasets-sdk/sdk-client-metadata) for more information.</Note>

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](/platform-documentation/Annotate/annotate-export/annotate-how-to-export-labels).

## Reading series metadata

The following code reads and prints the [patient ID](https://dicom.innolitics.com/ciods/rt-plan/patient/00101002/00100020) (`patient_id`), [series ID](https://dicom.innolitics.com/ciods/mr-image/general-series/00081250/0020000e) (`series_uid`) and [study ID](https://dicom.innolitics.com/ciods/mr-image/general-study/0020000d) (`study_uid`) of all label rows in the specified Project.

<CodeGroup>
  ```python theme={"dark"}

  #Import dependencies
  from encord import EncordUserClient

  # Authenticate with Encord using the path to your private key
  client = 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 IDs
  project = client.get_project("<project_hash>")

  # Fetch the label and frame information for this project
  label_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 ID
      print (label_row.metadata)
  ```

  ```python Output theme={"dark"}
  patient_id='example_fmri_140207' study_uid='1.2.840.113619.6.283.47340.8065.13236498290.27' series_uid='1.2.840.113619.2.28.3100000.21673.1390073.97'
  ```
</CodeGroup>

***

## Reading frame metadata

The following code reads and prints frame specific DICOM metadata including the [DICOM instance ID](https://dicom.innolitics.com/ciods/rt-structure-set/sop-common/00080018) (`dicom_instance_uid`), the multiframe frame number (`multiframe_frame_number`), the file URI (`file_uri`) and the [height](https://dicom.innolitics.com/ciods/rt-dose/general-image/00880200/00280010) as well as [width of the frame](https://dicom.innolitics.com/ciods/rt-dose/image-pixel/00280011), as can be seen in the sample output provided.

<CodeGroup>
  ```python theme={"dark"}

  #Import dependencies
  from encord import EncordUserClient

  # Authenticate with Encord using the path to your private key
  client = 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 IDs
  project = client.get_project("<project_hash>")

  # Fetch the label and frame information for this project
  label_rows = project.list_label_rows_v2()

  for label_row in label_rows:
      # Initialize labels
      label_row.initialise_labels()
      
      # Print Frame specific DICOM metadata
      for v in label_row.get_frame_views():
          print(v.metadata)

  ```

  ```python Output theme={"dark"}
  dicom_instance_uid='1.5.740.183619.283.6905.311000.16119.13000477777.716' multiframe_frame_number=None file_uri='my-storage-location/iaDJxNNrMubabutFPcP9oszw2shmeHm2/5e8880c2-9177-4cf6-b298-ebd3d1d31eb8' width=256 height=256
  ```
</CodeGroup>

## Reading frame dimensions

Use the script below to obtain the dimensions for a given slice or frame.

<Warning>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.</Warning>

<CodeGroup>
  ```python Sample Code theme={"dark"}

  #Import dependencies
  from encord import EncordUserClient

  # Authenticate with Encord using the path to your private key
  client = 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 IDs
  project = client.get_project("<project_hash>")

  # Fetch the label and frame information for this project
  label_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}")

  ```

  ```python Example Output theme={"dark"}
  series width: 1381, height: 1982
  frame width: 1381, height: 1982
  frame metadata width: 934, height: 1982
  frame width: 1381, height: 1982
  frame metadata width: 1381, height: 1632
  ```
</CodeGroup>
