22 parser = argparse.ArgumentParser(description=
"Read DICOM Series And Write 3D Image.")
26 help=
"If DicomDirectory is not specified, current directory is used",
28 parser.add_argument(
"output_image", nargs=
"?")
29 parser.add_argument(
"series_name", nargs=
"?")
30 args = parser.parse_args()
34 if args.dicom_directory:
35 dirName = args.dicom_directory
37 PixelType = itk.ctype(
"signed short")
40 ImageType =
itk.Image[PixelType, Dimension]
43 namesGenerator.SetUseSeriesDetails(
True)
44 namesGenerator.AddSeriesRestriction(
"0008|0021")
45 namesGenerator.SetGlobalWarningDisplay(
False)
46 namesGenerator.SetDirectory(dirName)
48 seriesUID = namesGenerator.GetSeriesUIDs()
50 if len(seriesUID) < 1:
51 print(
"No DICOMs in: " + dirName)
54 print(
"The directory: " + dirName)
55 print(
"Contains the following DICOM Series: ")
61 seriesIdentifier = uid
63 seriesIdentifier = args.series_name
65 print(
"Reading: " + seriesIdentifier)
66 fileNames = namesGenerator.GetFileNames(seriesIdentifier)
70 reader.SetImageIO(dicomIO)
71 reader.SetFileNames(fileNames)
72 reader.ForceOrthogonalDirectionOff()
75 outFileName = os.path.join(dirName, seriesIdentifier +
".nrrd")
77 outFileName = args.output_image
78 writer.SetFileName(outFileName)
79 writer.UseCompressionOn()
80 writer.SetInput(reader.GetOutput())
81 print(
"Writing: " + outFileName)