Read image and metada from folder full of dicom image

Hello high tea key,
i am trying to read image and metadata from a folder with the following code.
It succeed to open the image but find no metadata and i sure they are. How can i access to them?

from _main_import vtk, qt, ctk, slicer
from math import *
import numpy as np
from vtk.util import numpy_support
import SimpleITK as sitk
import sitkUtils as su
import math

data_directory = "D:/travail/M2-2020/199200661/test"
series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory)

if not series_IDs:
    print("ERROR:""+data_directory+"\" does not contain DICOM series.")

for i,series_ID in enumerate(series_IDs):
    series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(data_directory, series_ID,useSeriesDetails=False) #useSeriesDetails ?
    series_reader = sitk.ImageSeriesReader()
        img = series_reader.Execute()
        #sitk.Show( img, "Dicom Series" )
        su.PushToSlicer(img, "image_"+series_ID,1)
        for k in series_reader.GetMetaDataKeys(0):
            v = series_reader.GetMetaData(0,k)
            print("({0}) = = \"{1}\"".format(k,v))
    except RuntimeError:
        print ("--> Fundamental error in image layer, skipping...")

Hello @drcjaudet,

Your code looks correct, configuring the ImageSeriesReader to load all tags and accessing the tags for the first slice. Have you tried accessing the keys for another slice?

Can you provide the data that causes the issue? Without access to the data it is hard to guess what is causing the issue (given that the code looks fine).

Hello Zivy,
i find another way by using:

import dicom
img_metadata=dicom.read_file(series_file_names[0])  #importation des metadatas 
img_metadata.Modality #for example.

Thank a lot,
See you Cyril

Hello @drcjaudet,

Happy to see that you resolved your issue.

One point to keep in mind, in the SimpleITK implementation using the series reader you have access to the meta-data from all slices. This may not be the case when you read a whole image. Likely you don’t care about this, but the underlying reader will most often consolidate the information from all slices in some manner and not retain the per slice information.

Indeed but for my purpose with PET images it is even better to access to the per slice information so you can compute the SUV value not per exam but per slice.:wink:
Have a nice day,