You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -15,33 +15,58 @@ To install the ITK Python package::
15
15
Usage
16
16
-----
17
17
18
-
Basic examples
18
+
Basic example
19
19
..............
20
20
21
21
Here is a simple python script that reads an image, applies a median image filter (radius of 2 pixels), and writes the resulting image in a file.
22
22
23
23
.. literalinclude:: code/ReadMedianWrite.py
24
24
25
-
In `itk`, filters are optimized at compile time for each image pixel type and
26
-
image dimension. There are two ways to instantiate these filters with the `itk`
27
-
Python wrapping:
25
+
ITK and NumPy
26
+
.............
28
27
29
-
- *Implicit (recommended)*: Type information is automatically detected from the data. Typed filter objects and images are implicitly created.
28
+
A common use case for using ITK in Python is to mingle NumPy and ITK operations on raster data. ITK provides a large number of I/O image formats and several sophisticated image processing algorithms not available in any other packages. The ability to intersperse that with the SciPy ecosystem provides a great tool for rapid prototyping.
30
29
31
-
.. literalinclude:: code/ImplicitInstantiation.py
32
-
:lines: 8-
30
+
The following script shows how to integrate NumPy and ITK:
33
31
34
-
- *Explicit*: This can be useful if an appropriate type cannot be determined implicitly, e.g. with the `CastImageFilter`, and when a different filter type than the default is desired.
32
+
.. literalinclude:: code/MixingITKAndNumPy.py
33
+
:lines: 8-33
35
34
36
-
Explicit instantiation of a median image filter:
37
35
38
-
.. literalinclude:: code/ExplicitInstantiation.py
39
-
:lines: 8-
36
+
Similar functions are available to work with `itk.Matrix`, VNL vectors and matrices:
40
37
41
-
Explicit instantiation of cast image filter:
38
+
.. literalinclude:: code/MixingITKAndNumPy.py
39
+
:lines: 35-
42
40
43
-
.. literalinclude:: code/Cast.py
44
-
:lines: 10-18
41
+
ITK and Xarray
42
+
..............
43
+
44
+
An `itk.Image` can be converted to and from an `xarray.DataArray
45
+
<https://xarray.pydata.org/en/stable/generated/xarray.DataArray.html>`_ while
46
+
preserving metadata::
47
+
48
+
da = itk.xarray_from_image(image)
49
+
50
+
image = itk.image_from_xarray(da)
51
+
52
+
ITK and VTK
53
+
............
54
+
55
+
An `itk.Image` can be converted to and from a `vtk.vtkImageData
56
+
<https://vtk.org/doc/nightly/html/classvtkImageData.html>`_ while
57
+
preserving metadata::
58
+
59
+
vtk_image = itk.vtk_image_from_image(image)
60
+
61
+
image = itk.image_from_vtk_image(vtk_image)
62
+
63
+
ITK and napari
64
+
..............
65
+
66
+
An `itk.Image` can be converted to and from a `napari.layers.Image
67
+
<https://napari.org/api/stable/napari.layers.Image.html#napari.layers.Image>`_ while
68
+
preserving metadata with the `itk-napari-conversion package
ITK filter parameters can be specified in the following ways:
87
197
88
198
.. literalinclude:: code/FilterParameters.py
89
199
:lines: 10-
90
200
201
+
Filter types
202
+
............
203
+
204
+
In `itk`, filters are optimized at compile time for each image pixel type and
205
+
image dimension. There are two ways to instantiate these filters with the `itk`
206
+
Python wrapping:
207
+
208
+
- *Implicit (recommended)*: Type information is automatically detected from the data. Typed filter objects and images are implicitly created.
91
209
92
-
Mixing ITK and NumPy
93
-
--------------------
210
+
.. literalinclude:: code/ImplicitInstantiation.py
211
+
:lines: 8-
94
212
95
-
A common use case for using ITK in Python is to mingle NumPy and ITK operations on raster data. ITK provides a large number of I/O image formats and several sophisticated image processing algorithms not available in any other packages. The ability to intersperse that with the SciPy ecosystem provides a great tool for rapid prototyping.
213
+
- *Explicit*: This can be useful if an appropriate type cannot be determined implicitly or when a different filter type than the default is desired.
96
214
97
-
The following script shows how to integrate NumPy and ITK:
215
+
To specify the type of the filter, use the `ttype` keyword argument. Explicit instantiation of a median image filter:
98
216
99
-
.. literalinclude:: code/MixingITKAndNumPy.py
100
-
:lines: 8-33
217
+
.. literalinclude:: code/ExplicitInstantiation.py
218
+
:lines: 8-
101
219
220
+
Instantiate an ITK object
221
+
.........................
102
222
103
-
Similar functions are available to work with `itk.Matrix`, VNL vectors and matrices:
223
+
There are two types of ITK objects. Most ITK objects, such as images, filters, or adapters, are instantiated the following way:
104
224
105
-
.. literalinclude:: code/MixingITKAndNumPy.py
106
-
:lines:35-
225
+
.. literalinclude:: code/InstantiateITKObjects.py
226
+
:lines:6-8
107
227
228
+
Some objects, like a Matrix, Vector, or RGBPixel, do not require the attribute `.New()` to be added to instantiate them:
229
+
230
+
.. literalinclude:: code/InstantiateITKObjects.py
231
+
:lines: 11
232
+
233
+
In case of doubt, look at the attributes of the object you are trying to instantiate.
0 commit comments