Skip to content

Commit 522eb5f

Browse files
committed
doc: Update the Quick start guide for ITK 5.0
1 parent f194dee commit 522eb5f

File tree

7 files changed

+79
-58
lines changed

7 files changed

+79
-58
lines changed

docs/Quick_start_guide.rst

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@ Installation
99

1010
To install the ITK Python package::
1111

12-
$ python -m pip install --upgrade pip
13-
$ python -m pip install itk
14-
15-
If a pre-compiled wheel package is not found for your Python distribution, then it will
16-
attempt to build from source.
17-
18-
.. note::
19-
20-
On Windows machines, the source path cannot be greater than 50 characters or
21-
issues will occur during build time due to filename truncation in Visual
22-
Studio. If you must compile from source, clone this repository in a short
23-
directory, like *C:/IPP*. Then, run `setup.py` within the repository via the
24-
command line.
12+
$ pip install itk
2513

2614

2715
Usage
@@ -36,22 +24,22 @@ Here is a simple python script that reads an image, applies a median image filte
3624

3725
There are two ways to instantiate filters with ITKPython:
3826

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

4129
.. literalinclude:: code/ImplicitInstantiation.py
4230
:lines: 8-
4331

44-
- Explicit: This can be useful if a filter cannot automatically select the type information (e.g. `CastImageFilter`), or to detect type mismatch errors which can lead to cryptic error messages.
32+
- *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.
4533

46-
Explicit instantiation of median image filter:
34+
Explicit instantiation of a median image filter:
4735

48-
.. literalinclude:: code/ImplicitInstantiation.py
36+
.. literalinclude:: code/ExplicitInstantiation.py
4937
:lines: 8-
5038

5139
Explicit instantiation of cast image filter:
5240

5341
.. literalinclude:: code/CastImageFilter.py
54-
:lines: 9-
42+
:lines: 9-23
5543

5644
ITK Python types
5745
................
@@ -68,7 +56,7 @@ ITK Python types
6856
| std::complex<float> | itk.complex[itk.F] |
6957
+---------------------+--------------------+
7058

71-
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/html/Book1/ITKSoftwareGuide-Book1ch9.html#x48-1530009.5>`_.
59+
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>`_.
7260

7361
Types can also be obtained from their name in the C programming language:
7462

@@ -101,7 +89,7 @@ The following script shows how to integrate NumPy and ITK:
10189
:lines: 8-33
10290

10391

104-
Similar functions are available to work with VNL vector and matrices:
92+
Similar functions are available to work with `itk.Matrix`, VNL vectors and matrices:
10593

10694
.. literalinclude:: code/MixingITKAndNumPy.py
10795
:lines: 35-

docs/code/CastImageFilter.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
input_dimension = image.GetImageDimension()
1313
# Select float as output pixel type
1414
OutputType = itk.Image[itk.UC, input_dimension]
15-
castFilter = itk.CastImageFilter[InputType, OutputType].New()
16-
castFilter.SetInput(image)
17-
itk.imwrite(castFilter, output_filename)
15+
16+
# Functional interface
17+
casted = itk.cast_image_filter(image, ttype=(InputType, OutputType))
18+
19+
# Object-oriented interface
20+
cast_filter = itk.CastImageFilter[InputType, OutputType].New()
21+
cast_filter.SetInput(image)
22+
cast_filter.Update()
23+
casted = cast_filter.GetOutput()
24+
25+
# imwrite calls .Update()
26+
itk.imwrite(cast_filter, output_filename)

docs/code/ExplicitInstantiation.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55

66
input_filename = sys.argv[1]
77

8-
ImageType = itk.Image[itk.F,2]
9-
reader = itk.ImageFileReader[ImageType].New(FileName = input_filename)
8+
PixelType = itk.F
9+
ImageType = itk.Image[PixelType,2]
10+
11+
# Functional interface
12+
image = itk.imread(input_filename, PixelType)
13+
smoothed = itk.median_image_filter(image, ttype=(ImageType, ImageType))
14+
15+
# Object-oriented interface
16+
reader = itk.ImageFileReader[ImageType].New(FileName=input_filename)
1017
median = itk.MedianImageFilter[ImageType, ImageType].New()
1118
median.SetInput(reader.GetOutput())
12-
19+
median.Update()
20+
smoothed = median.GetOutput()

docs/code/ImplicitInstantiation.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,29 @@
55

66
input_filename = sys.argv[1]
77

8-
# Use `ImageFileReader` instead of the wrapping function `imread` to illustrate this example.
8+
image = itk.imread(input_filename)
9+
# Use ITK's functional, Pythonic interface. The filter type is implied by the
10+
# type of the input image. The filter is eagerly executed, and the output image
11+
# is directly returned.
12+
smoothed = itk.median_image_filter(image)
13+
14+
# Alternatively, create filter objects. These filter objects can be connected in
15+
# a pipeline to stream-process large datasets. To generate the output of the
16+
# pipeline, .Update() must explicitly be called on the last filter of the
17+
# pipeline.
18+
#
19+
# We can implicitly instantiate the filter object based on the type
20+
# of the input image in multiple ways.
21+
22+
# Use itk.ImageFileReader instead of the wrapping function,
23+
# itk.imread to illustrate this example.
924
reader = itk.ImageFileReader.New(FileName=input_filename)
1025
# Here we specify the filter input explicitly
1126
median = itk.MedianImageFilter.New(Input=reader.GetOutput())
12-
# Same as above but shortened. `Input` does not have to be specified.
27+
# Same as above but shortened. Input does not have to be specified.
1328
median = itk.MedianImageFilter.New(reader.GetOutput())
14-
# Same as above. `.GetOutput()` does not have to be specified.
29+
# Same as above. .GetOutput() does not have to be specified.
1530
median = itk.MedianImageFilter.New(reader)
31+
32+
median.Update()
33+
smoothed = median.GetOutput()

docs/code/MixingITKAndNumPy.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,40 @@
1414
# Run filters on itk.Image
1515

1616
# View only of itk.Image, data is not copied
17-
np_view = itk.GetArrayViewFromImage(itk_image)
17+
np_view = itk.array_view_from_image(itk_image)
1818

1919
# Copy of itk.Image, data is copied
20-
np_copy = itk.GetArrayFromImage(itk_image)
20+
np_copy = itk.array_from_image(itk_image)
2121

2222

23-
# Do numpy stuff
23+
# Do NumPy stuff...
2424

2525

26-
# Convert back to itk, view only, data is not copied
27-
itk_np_view = itk.GetImageViewFromArray(np_copy)
26+
# Convert back to ITK, view only, data is not copied
27+
itk_np_view = itk.image_view_from_array(np_copy)
2828

29-
# Convert back to itk, data is copied
30-
itk_np_copy = itk.GetImageFromArray(np_copy)
29+
# Convert back to ITK, data is copied
30+
itk_np_copy = itk.image_from_array(np_copy)
3131

3232
# Save result
3333
itk.imwrite(itk_np_view, output_filename)
3434

35-
# Vnl matrix from array
35+
# VNL matrix from array
3636
arr = np.zeros([3,3], np.uint8)
37-
matrix = itk.GetVnlMatrixFromArray(arr)
37+
matrix = itk.vnl_matrix_from_array(arr)
3838

39-
# Array from Vnl matrix
40-
arr = itk.GetArrayFromVnlMatrix(matrix)
39+
# Array from VNL matrix
40+
arr = itk.array_from_vnl_matrix(matrix)
4141

42-
# Vnl vector from array
42+
# VNL vector from array
4343
vec = np.zeros([3], np.uint8)
44-
vnl_vector = itk.GetVnlVectorFromArray(vec)
44+
vnl_vector = itk.vnl_vector_from_array(vec)
4545

46-
# Array from Vnl vector
47-
vec = itk.GetArrayFromVnlVector(vnl_vector)
46+
# Array from VNL vector
47+
vec = itk.array_from_vnl_vector(vnl_vector)
48+
49+
# itk.Matrix from array
50+
mat = itk.matrix_from_array(np.eye(3))
51+
52+
# array from itk.Matrix
53+
arr = itk.array_from_matrix(mat)

docs/code/ReadMedianWrite.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@
77
output_filename = sys.argv[2]
88

99
image = itk.imread(input_filename)
10-
median = itk.MedianImageFilter.New(image, Radius = 2)
10+
11+
median = itk.median_image_filter(image, radius=2)
12+
1113
itk.imwrite(median, output_filename)

docs/index.rst

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@ infrastructure to build ITK external module Python wheels.
88

99
To install the stable ITK Python package::
1010

11-
python -m pip install --upgrade pip
12-
python -m pip install itk
11+
$ pip install itk
1312

14-
The Python packages are built daily. To install the latest build from the ITK
15-
Git *master* branch::
16-
17-
python -m pip install --upgrade pip numpy
18-
python -m pip install itk --upgrade --no-index \
19-
-f https://github.com/InsightSoftwareConsortium/ITKPythonPackage/releases/tag/latest
20-
21-
22-
For more information on ITK's Python wrapping, see `an introduction in the ITK
23-
Software Guide
24-
<https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch3.html#x32-420003.7>`_.
13+
For more information on ITK's Python wrapping, see `an introduction in the
14+
Book 1, Chapter 3 of the ITK Software Guide <https://itk.org/ItkSoftwareGuide.pdf>`_.
2515
There are also many `downloadable examples documented in Sphinx
2616
<https://itk.org/ITKExamples/search.html?q=Python>`_.
2717

0 commit comments

Comments
 (0)