Skip to content

Commit b0d97d4

Browse files
committed
Merge branch 'release'
2 parents f7fb031 + f2436d4 commit b0d97d4

30 files changed

+272
-175
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ venv-*
1111
ITK-*
1212
libpython-not-needed-symbols-exported-by-interpreter
1313
tools/
14+
ninja/
1415

1516
# back-up files when conflicts occur
1617
*.orig

docs/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# You can set these variables from the command line.
55
SPHINXOPTS =
6-
SPHINXBUILD = python -msphinx
6+
SPHINXBUILD = sphinx-build
77
SPHINXPROJ = ITKPythonPackage
88
SOURCEDIR = .
99
BUILDDIR = _build
@@ -17,4 +17,4 @@ help:
1717
# Catch-all target: route all unknown targets to Sphinx using the new
1818
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
1919
%: Makefile
20-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/Quick_start_guide.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ Here is a simple python script that reads an image, applies a median image filte
2222

2323
.. literalinclude:: code/ReadMedianWrite.py
2424

25-
There are two ways to instantiate filters with ITKPython:
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:
2628

27-
- *Implicit (recommended)*: ITK type information is automatically detected from the data. Typed filter objects and images are implicitly created.
29+
- *Implicit (recommended)*: Type information is automatically detected from the data. Typed filter objects and images are implicitly created.
2830

2931
.. literalinclude:: code/ImplicitInstantiation.py
3032
:lines: 8-
@@ -38,23 +40,23 @@ Explicit instantiation of a median image filter:
3840

3941
Explicit instantiation of cast image filter:
4042

41-
.. literalinclude:: code/CastImageFilter.py
42-
:lines: 9-23
43+
.. literalinclude:: code/Cast.py
44+
:lines: 10-18
4345

4446
ITK Python types
4547
................
4648

47-
+---------------------+--------------------+
48-
| C++ type | Python type |
49-
+=====================+====================+
50-
| float | itk.F |
51-
+---------------------+--------------------+
52-
| double | itk.D |
53-
+---------------------+--------------------+
54-
| unsigned char | itk.UC |
55-
+---------------------+--------------------+
56-
| std::complex<float> | itk.complex[itk.F] |
57-
+---------------------+--------------------+
49+
+---------------------+--------------------+--------------------+
50+
| C++ type | Python type | NumPy dtype |
51+
+=====================+====================+====================+
52+
| float | itk.F | np.float32 |
53+
+---------------------+--------------------+--------------------+
54+
| double | itk.D | np.float64 |
55+
+---------------------+--------------------+--------------------+
56+
| unsigned char | itk.UC | np.uint8 |
57+
+---------------------+--------------------+--------------------+
58+
| std::complex<float> | itk.complex[itk.F] | np.complex64 |
59+
+---------------------+--------------------+--------------------+
5860

5961
This list is not exhaustive and is only presented to illustrate the type names. The complete list of types can be found in the `ITK Software Guide <https://itk.org/ItkSoftwareGuide.pdf>`_.
6062

@@ -90,7 +92,7 @@ ITK filter parameters can be specified in the following ways:
9092
Mixing ITK and NumPy
9193
--------------------
9294

93-
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 numpy special purpose hacking provides a great tool for rapid prototyping.
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.
9496

9597
The following script shows how to integrate NumPy and ITK:
9698

@@ -107,4 +109,4 @@ Similar functions are available to work with `itk.Matrix`, VNL vectors and matri
107109
Examples
108110
--------
109111

110-
Examples can be found in the `ITKExamples project <https://itk.org/ITKExamples/src/index.html>`_.
112+
Examples can be found in the `ITKSphinxExamples project <https://itk.org/ITKExamples/src/index.html>`_.

docs/code/Cast.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env python3
2+
3+
import numpy as np
4+
import itk
5+
import sys
6+
7+
input_filename = sys.argv[1]
8+
output_filename = sys.argv[2]
9+
10+
image = itk.imread(input_filename)
11+
12+
# Cast to an unsigned char pixel type
13+
cast_image = image.astype(itk.UC)
14+
15+
# Equivalent
16+
cast_image = image.astype(np.uint8)
17+
18+
itk.imwrite(cast_image, output_filename)

docs/code/CastImageFilter.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

docs/code/CompareITKTypes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import itk
44

docs/code/CreateBaseline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import itk
44
import sys

docs/code/ExplicitInstantiation.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import itk
44
import sys
55

66
input_filename = sys.argv[1]
77

8+
# An apriori ImageType
89
PixelType = itk.F
910
ImageType = itk.Image[PixelType,2]
11+
image = itk.imread(input_filename, PixelType)
12+
13+
# An image type dynamically determined from the type on disk
14+
image = itk.imread(input_filename)
15+
ImageType = type(image)
1016

1117
# Functional interface
12-
image = itk.imread(input_filename, PixelType)
18+
# The `ttype` keyword argument specifies the filter type.
1319
smoothed = itk.median_image_filter(image, ttype=(ImageType, ImageType))
1420

1521
# Object-oriented interface
16-
reader = itk.ImageFileReader[ImageType].New(FileName=input_filename)
22+
reader = itk.ImageFileReader[ImageType].New(file_name=input_filename)
1723
median = itk.MedianImageFilter[ImageType, ImageType].New()
1824
median.SetInput(reader.GetOutput())
1925
median.Update()

docs/code/FilterParameters.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import itk
44
import sys
@@ -11,15 +11,13 @@
1111
#
1212
# number_of_iterations
1313
#
14-
smoothed = itk.anti_alias_binary_image_filter(image,
15-
number_of_iterations=3)
14+
smoothed = itk.anti_alias_binary_image_filter(image, number_of_iterations=3)
1615

1716
# CamelCase keyword arguments:
1817
#
1918
# NumberOfIterations
2019
#
21-
smoother = itk.AntiAliasBinaryImageFilter.New(image,
22-
NumberOfIterations=3)
20+
smoother = itk.AntiAliasBinaryImageFilter.New(image, NumberOfIterations=3)
2321
smoother.Update()
2422
smoothed = smoother.GetOutput()
2523

docs/code/ImplicitInstantiation.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22

33
import itk
44
import sys
55

66
input_filename = sys.argv[1]
77

88
image = itk.imread(input_filename)
9+
910
# Use ITK's functional, Pythonic interface. The filter type is implied by the
1011
# type of the input image. The filter is eagerly executed, and the output image
1112
# is directly returned.
@@ -21,9 +22,10 @@
2122

2223
# Use itk.ImageFileReader instead of the wrapping function,
2324
# itk.imread to illustrate this example.
24-
reader = itk.ImageFileReader.New(FileName=input_filename)
25+
ImageType = itk.Image[itk.UC, 2]
26+
reader = itk.ImageFileReader[ImageType].New(FileName=input_filename)
2527
# Here we specify the filter input explicitly
26-
median = itk.MedianImageFilter.New(Input=reader.GetOutput())
28+
median = itk.MedianImageFilter.New(reader.GetOutput())
2729
# Same as above but shortened. Input does not have to be specified.
2830
median = itk.MedianImageFilter.New(reader.GetOutput())
2931
# Same as above. .GetOutput() does not have to be specified.

0 commit comments

Comments
 (0)