20 import SimpleITK
as sitk
30 +
" <input_directory_with_DICOM_series> <output_directory>"
36 data_directory = sys.argv[1]
37 series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory)
40 'ERROR: given directory "'
42 +
'" does not contain a DICOM series.'
45 series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(
46 data_directory, series_IDs[0]
50 series_reader.SetFileNames(series_file_names)
57 series_reader.MetaDataDictionaryArrayUpdateOn()
58 series_reader.LoadPrivateTagsOn()
59 image3D = series_reader.Execute()
74 writer.KeepOriginalImageUIDOn()
90 modification_time = time.strftime(
"%H%M%S")
91 modification_date = time.strftime(
"%Y%m%d")
98 direction = filtered_image.GetDirection()
100 (k, series_reader.GetMetaData(0, k))
101 for k
in tags_to_copy
102 if series_reader.HasMetaDataKey(0, k)
104 (
"0008|0031", modification_time),
105 (
"0008|0021", modification_date),
106 (
"0008|0008",
"DERIVED\\SECONDARY"),
109 "1.2.826.0.1.3680043.2.1125."
134 series_reader.GetMetaData(0,
"0008|103e") +
" Processed-SimpleITK",
138 for i
in range(filtered_image.GetDepth()):
139 image_slice = filtered_image[:, :, i]
141 for tag, value
in series_tag_values:
142 image_slice.SetMetaData(tag, value)
145 image_slice.SetMetaData(
"0008|0012", time.strftime(
"%Y%m%d"))
147 image_slice.SetMetaData(
"0008|0013", time.strftime(
"%H%M%S"))
149 image_slice.SetMetaData(
152 map(str, filtered_image.TransformIndexToPhysicalPoint((0, 0, i)))
156 image_slice.SetMetaData(
"0020|0013", str(i))
160 writer.SetFileName(os.path.join(sys.argv[2], str(i) +
".dcm"))
161 writer.Execute(image_slice)