21 from distutils.version
import StrictVersion
as VS
24 print(
"ITK 4.8.0 is required (see example documentation).")
27 parser = argparse.ArgumentParser(description=
"Create A Custom Colormap.")
28 parser.add_argument(
"input_image")
29 parser.add_argument(
"output_image")
30 args = parser.parse_args()
35 ImageType =
itk.Image[PixelType, Dimension]
38 RGBImageType =
itk.Image[RGBPixelType, Dimension]
41 reader = ReaderType.New()
42 reader.SetFileName(args.input_image)
44 ColormapType = itk.CustomColormapFunction[PixelType, RGBPixelType]
45 colormap = ColormapType.New()
47 random = itk.MersenneTwisterRandomVariateGenerator.New()
55 redChannel.append(random.GetUniformVariate(0.0, 1.0))
56 greenChannel.append(random.GetUniformVariate(0.0, 1.0))
57 blueChannel.append(random.GetUniformVariate(0.0, 1.0))
59 colormap.SetRedChannel(redChannel)
60 colormap.SetGreenChannel(greenChannel)
61 colormap.SetBlueChannel(blueChannel)
64 colormapFilter1 = ColormapFilterType.New()
66 colormapFilter1.SetInput(reader.GetOutput())
67 colormapFilter1.SetColormap(colormap)
70 writer = WriterType.New()
71 writer.SetFileName(args.output_image)
72 writer.SetInput(colormapFilter1.GetOutput())