import os
import SimpleITK as sitk
import numpy as np
# Specify the folder containing DICOM files
folder_path ="path_to_folder_containing_dicom_files"# Get the list of DICOM files in the folder
dicom_files =[os.path.join(folder_path,file)forfilein os.listdir(folder_path)iffile.endswith('.dcm')]# Read the DICOM series
reader = sitk.ImageSeriesReader()
reader.SetFileNames(dicom_files)
image = reader.Execute()# Convert the 3D image to a NumPy array
volume = sitk.GetArrayFromImage(image)# Access metadata (same for all DICOM files in the folder)
first_file = dicom_files[0]
first_dataset = sitk.ReadImage(first_file)
patient_name = first_dataset.GetMetaData("PatientName")