How to get Metadata with SimpleITK in Java

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

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:

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

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

results in:

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

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

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.

2 Likes

wow that was fast @blowekamp , very thanks!!

i got it!
For future readers:

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:

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