Skip to content

Commit c1ca53f

Browse files
kian-weimerdzenanz
authored andcommitted
ENH: Added ThinImage Python script
1 parent 29859a9 commit c1ca53f

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/Filtering/BinaryMathematicalMorphology/ThinImage/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ install(FILES Code.cxx CMakeLists.txt
2323
enable_testing()
2424
add_test(NAME ThinImageTest
2525
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ThinImage)
26+
27+
if(ITK_WRAP_PYTHON)
28+
add_test(NAME ThinImageTestPython
29+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py)
30+
endif()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import itk
5+
6+
PixelType = itk.UC
7+
Dimension = 2
8+
ImageType = itk.Image[PixelType, Dimension]
9+
10+
if len(sys.argv) == 2:
11+
image = itk.imread(sys.argv[1])
12+
13+
else:
14+
# Create an image
15+
start = itk.Index[Dimension]()
16+
start.Fill(0)
17+
18+
size = itk.Size[Dimension]()
19+
size.Fill(100)
20+
21+
region = itk.ImageRegion[Dimension]()
22+
region.SetIndex(start)
23+
region.SetSize(size)
24+
25+
image = ImageType.New(Regions=region)
26+
image.Allocate()
27+
image.FillBuffer(0)
28+
29+
# Draw a 5 pixel wide line
30+
image[50:55, 20:80] = 255
31+
32+
# Write Image
33+
itk.imwrite(image, "input.png")
34+
35+
image = itk.binary_thinning_image_filter(image)
36+
37+
# Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
38+
image = itk.rescale_intensity_image_filter(image, output_minimum=0, output_maximum=255)
39+
40+
# Write Image
41+
itk.imwrite(image, "outputPython.png")

src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ Results
2929
Code
3030
----
3131

32+
Python
33+
......
34+
35+
.. literalinclude:: Code.py
36+
:language: python
37+
:lines: 1, 16-
38+
3239
C++
3340
...
3441

0 commit comments

Comments
 (0)