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
37
39 reader.SetImageIO("PNGImageIO")
40 reader.SetFileName(inputImageFileName)
41 image = reader.Execute()
42
44 writer.SetFileName(outputImageFileName)
45 writer.Execute(image)
46
47
48
49
50
51def example2(inputImageFileName, outputImageFileName):
52 """ A Simple Procedural Image Input/Output Example """
53
54 import SimpleITK as sitk
55
56
59
60
61
62
63
64def example3():
65 """ A Simple Transform Input/Output Example """
66
67 import SimpleITK as sitk
68
69
71 basic_transform.SetTranslation((2, 3))
72
73 file_name = "euler2D_py.tfm"
76
78
79
80
81if __name__ == "__main__":
82
83 if len(sys.argv) < 3:
84 print("Usage: SimpleIO <input> <output>")
85 sys.exit(1)
86
87 example1(sys.argv[1], sys.argv[2])
88 example2(sys.argv[1], sys.argv[2])
89 example3()
90 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)