# How to get Metadata with SimpleITK in Java

**URL:** <https://discourse.itk.org/t/how-to-get-metadata-with-simpleitk-in-java/6066>\
**Category:** Uncategorized\
**Tags:** metadata, simpleitk\
**Created:** [July 13, 2023, 6:07pm UTC](https://discourse.itk.org/t/how-to-get-metadata-with-simpleitk-in-java/6066 "2023-07-13T18:07:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 13, 2023, 6:07pm UTC](https://discourse.itk.org/t/how-to-get-metadata-with-simpleitk-in-java/6066/1 "2023-07-13T18:07:50Z")

</div>

i have a dicom folder that contains many dicom files, i load then using this code:

```auto
public static org.itk.simple.Image loadLocalFolder (Stage stage) throws Exception {
        String dicomFolderPath = LocalLoader.selectFolder(stage);
        ImageSeriesReader reader = new ImageSeriesReader();
        VectorString dicomNames = ImageSeriesReader.getGDCMSeriesFileNames(dicomFolderPath);
        reader.setFileNames(dicomNames);
        reader.loadPrivateTagsOn();
        reader.metaDataDictionaryArrayUpdateOn();
        reader.setDebug(true);
        long start = System.nanoTime();
        Image readerResult = reader.execute();
        long finish = System.nanoTime();
        System.out.println("total time " + ((double) (finish - start)/1_000_000_000) + " segundos");
        return readerResult;
    }

```

opening the same dicom folder in Radiant Dicom viewer, i get this metadata displayed:

 ![Captura de tela 2023-07-13 151013](https://discourse.itk.org/uploads/default/original/2X/1/1f7c4fc13f326005709fc312076d1c332776c424.jpeg)

But cant find a way to get this information with simpleITK…  
printing all metadata keys like this:

```auto
System.out.println("-----------------");
for (String key : volume.getVolume().getMetaDataKeys()) {
        System.out.println("key: " + key + ", value: " + volume.getVolume().getMetaData(key));
}
System.out.println("-----------------");

```

results in:

```auto
-----------------
key: ITK_non_uniform_sampling_deviation, value: [UNKNOWN_PRINT_CHARACTERISTICS]

-----------------

```

---

<div class="post-metadata">

**Author:** ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)\
**Post date:** [July 13, 2023, 6:18pm UTC](https://discourse.itk.org/t/how-to-get-metadata-with-simpleitk-in-java/6066/2 "2023-07-13T18:18:43Z")

</div>

Hello @Salu_Ramos,

The DICOM tags are stores per file or slice in the dcm series files. These values are not merge ( loosely ) into the joined series or volume.

However, when `MetaDataDictionaryArrayUpdate` is enabled an array of metadata dictionaries are loaded and stored in the `ImageSeriesReader`. Please methods such as `ImageSeriesReader::GetMetaData (unsigned int slice, const std::string &key)` to access the dictionaries per slice.

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 13, 2023, 6:34pm UTC](https://discourse.itk.org/t/how-to-get-metadata-with-simpleitk-in-java/6066/3 "2023-07-13T18:34:56Z")

</div>

wow that was fast @blowekamp , very thanks!!

i got it!  
For future readers:

```auto
public static org.itk.simple.Image loadLocalFolder (Stage stage) throws Exception {
        String dicomFolderPath = LocalLoader.selectFolder(stage);
        ImageSeriesReader reader = new ImageSeriesReader();
        VectorString dicomNames = ImageSeriesReader.getGDCMSeriesFileNames(dicomFolderPath);
        reader.setFileNames(dicomNames);
        reader.loadPrivateTagsOn();
        reader.metaDataDictionaryArrayUpdateOn();
        reader.setDebug(true);
        long start = System.nanoTime();
        Image readerResult = reader.execute();
        long finish = System.nanoTime();
        System.out.println("total time " + ((double) (finish - start)/1_000_000_000) + " segundos");
        for (String key : reader.getMetaDataKeys(0)) {
            System.out.println("key: " + key + ", value: " + reader.getMetaData(0, key));
        }
        return readerResult;
    }

```

result:

 ![image](https://discourse.itk.org/uploads/default/original/2X/3/3ce1b9c72386b0550e58a1adffe686ffa975fe95.png)

At first I found the names of the keys very strange, I spoke with a friend of mine and he sent me this link which is the dictionary for these keys: [All CIODs – DICOM Standard Browser](https://dicom.innolitics.com/ciods)
