1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22"""
23These examples are used in the I/O documentation page. The IO.rst file
24pulls the code examples based their line numbers in this file. So any
25change in the line numbers of the code below will break the I/O page.
26"""
27
28import sys
29
30
31
32def example1(inputImageFileName, outputImageFileName):
33 """ A Simple Image Input/Output Example """
34
35 import SimpleITK as sitk
36
38 reader.SetImageIO("PNGImageIO")
39 reader.SetFileName(inputImageFileName)
40 image = reader.Execute()
41
43 writer.SetFileName(outputImageFileName)
44 writer.Execute(image)
45
46
47
48
49def example2(inputImageFileName, outputImageFileName):
50 """ A Simple Procedural Image Input/Output Example """
51
52 import SimpleITK as sitk
53
56
57
58
59
60def example3():
61 """ A Simple Transform Input/Output Example """
62
63 import SimpleITK as sitk
64
66 basic_transform.SetTranslation((2, 3))
67
70
72
73
74if __name__ == "__main__":
75
76 if len(sys.argv) < 3:
77 print("Usage: SimpleIO <input> <output>")
78 sys.exit(1)
79
80 example1(sys.argv[1], sys.argv[2])
81 example2(sys.argv[1], sys.argv[2])
82 example3()
83 sys.exit(0)
Read an image file and return a SimpleITK Image.
Write out a SimpleITK image to the specified file location.
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
SITKIO_EXPORT void WriteImage(const Image &image, const PathType &fileName, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageFileWriter. class which is convenient for many image...
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const PathType &filename)
SITKCommon_EXPORT Transform ReadTransform(const PathType &filename)