19 from __future__
import print_function
21 import SimpleITK
as sitk
28 print(
"Usage: python " + __file__ +
29 " <input_directory_with_DICOM_series> <output_directory>")
34 data_directory = sys.argv[1]
35 series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory)
37 print(
"ERROR: given directory \"" + data_directory +
38 "\" does not contain a DICOM series.")
40 series_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(
41 data_directory, series_IDs[0])
44 series_reader.SetFileNames(series_file_names)
51 series_reader.MetaDataDictionaryArrayUpdateOn()
52 series_reader.LoadPrivateTagsOn()
53 image3D = series_reader.Execute()
68 writer.KeepOriginalImageUIDOn()
72 tags_to_copy = [
"0010|0010",
83 modification_time = time.strftime(
"%H%M%S")
84 modification_date = time.strftime(
"%Y%m%d")
91 direction = filtered_image.GetDirection()
93 (k, series_reader.GetMetaData(0, k))
95 if series_reader.HasMetaDataKey(0, k)] + \
96 [(
"0008|0031", modification_time),
97 (
"0008|0021", modification_date),
98 (
"0008|0008",
"DERIVED\\SECONDARY"),
99 (
"0020|000e",
"1.2.826.0.1.3680043.2.1125." +
100 modification_date +
".1" + modification_time),
103 '\\'.join(map(str, (direction[0], direction[3],
106 direction[1], direction[4],
109 series_reader.GetMetaData(0,
"0008|103e")
110 +
" Processed-SimpleITK")]
112 for i
in range(filtered_image.GetDepth()):
113 image_slice = filtered_image[:, :, i]
115 for tag, value
in series_tag_values:
116 image_slice.SetMetaData(tag, value)
119 image_slice.SetMetaData(
"0008|0012", time.strftime(
"%Y%m%d"))
121 image_slice.SetMetaData(
"0008|0013", time.strftime(
"%H%M%S"))
123 image_slice.SetMetaData(
"0020|0032",
'\\'.join(
124 map(str, filtered_image.TransformIndexToPhysicalPoint((0, 0, i)))))
126 image_slice.SetMetaData(
"0020|0013", str(i))
130 writer.SetFileName(os.path.join(sys.argv[2], str(i) +
'.dcm'))
131 writer.Execute(image_slice)