File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
src/Filtering/BinaryMathematicalMorphology/ThinImage Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -23,3 +23,8 @@ install(FILES Code.cxx CMakeLists.txt
23
23
enable_testing ()
24
24
add_test (NAME ThinImageTest
25
25
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 ()
Original file line number Diff line number Diff line change
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" )
Original file line number Diff line number Diff line change @@ -29,6 +29,13 @@ Results
29
29
Code
30
30
----
31
31
32
+ Python
33
+ ......
34
+
35
+ .. literalinclude :: Code.py
36
+ :language: python
37
+ :lines: 1, 16-
38
+
32
39
C++
33
40
...
34
41
You can’t perform that action at this time.
0 commit comments