22 parser = argparse.ArgumentParser(description=
"Generate Slices From Volume.")
23 parser.add_argument(
"input_image")
24 parser.add_argument(
"output_image")
25 parser.add_argument(
"extension", nargs=
"?")
26 args = parser.parse_args()
29 extension = args.extension
33 fileNameFormat = args.output_image +
"-%d" + extension
38 InputImageType =
itk.Image[PixelType, Dimension]
41 reader = ReaderType.New()
42 reader.SetFileName(args.input_image)
44 OutputPixelType = itk.UC
45 RescaleImageType =
itk.Image[OutputPixelType, Dimension]
48 rescale = RescaleFilterType.New()
49 rescale.SetInput(reader.GetOutput())
50 rescale.SetOutputMinimum(0)
51 rescale.SetOutputMaximum(255)
52 rescale.UpdateLargestPossibleRegion()
54 region = reader.GetOutput().GetLargestPossibleRegion()
55 size = region.GetSize()
58 fnames.SetStartIndex(0)
59 fnames.SetEndIndex(size[2] - 1)
60 fnames.SetIncrementIndex(1)
61 fnames.SetSeriesFormat(fileNameFormat)
63 OutputImageType =
itk.Image[OutputPixelType, 2]
66 writer = WriterType.New()
67 writer.SetInput(rescale.GetOutput())
68 writer.SetFileNames(fnames.GetFileNames())