22 parser = argparse.ArgumentParser(description=
"Process Image Chunks.")
23 parser.add_argument(
"input_image")
24 parser.add_argument(
"output_image")
25 args = parser.parse_args()
35 ImageType =
itk.Image[PixelType, Dimension]
38 reader = ReaderType.New()
39 reader.SetFileName(args.input_image)
40 reader.UpdateOutputInformation()
41 fullRegion = reader.GetOutput().GetLargestPossibleRegion()
42 fullSize = fullRegion.GetSize()
51 median = MedianType.New()
52 median.SetInput(reader.GetOutput())
56 writer = WriterType.New()
57 writer.SetFileName(args.output_image)
66 start[2] = int(fullSize[2] * float(z) / zDiv)
67 end[2] = int(fullSize[2] * (z + 1.0) / zDiv)
68 size[2] = end[2] - start[2]
71 start[1] = int(fullSize[1] * float(y) / yDiv)
72 end[1] = int(fullSize[1] * (y + 1.0) / yDiv)
73 size[1] = end[1] - start[1]
76 start[0] = int(fullSize[0] * float(x) / xDiv)
77 end[0] = int(fullSize[0] * (x + 1.0) / xDiv)
78 size[0] = end[0] - start[0]
81 region.SetIndex(start)
85 median.GetOutput().SetRequestedRegion(region)
87 result = median.GetOutput()
90 result.DisconnectPipeline()
94 writer.SetInput(result)
98 ioRegion.SetIndex(0, start[0])
99 ioRegion.SetIndex(1, start[1])
100 ioRegion.SetIndex(2, start[2])
101 ioRegion.SetSize(0, region.GetSize()[0])
102 ioRegion.SetSize(1, region.GetSize()[1])
103 ioRegion.SetSize(2, region.GetSize()[2])
105 writer.SetIORegion(ioRegion)
109 except Exception
as e:
110 print(
"Exception for chunk:", x, y, z,
"\n", e)