Skip to content

Commit

Permalink
ENH: Added ThinImage Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
kian-weimer committed Jun 1, 2021
1 parent 29859a9 commit 60f1ff8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ install(FILES Code.cxx CMakeLists.txt
enable_testing()
add_test(NAME ThinImageTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ThinImage)

if(ITK_WRAP_PYTHON)
add_test(NAME ThinImageTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py)
endif()
41 changes: 41 additions & 0 deletions src/Filtering/BinaryMathematicalMorphology/ThinImage/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python

import sys
import itk

PixelType = itk.UC
Dimension = 2
ImageType = itk.Image[PixelType, Dimension]

if len(sys.argv) == 2:
image = itk.imread(sys.argv[1])

else:
# Create an image
start = itk.Index[Dimension]()
start.Fill(0)

size = itk.Size[Dimension]()
size.Fill(100)

region = itk.ImageRegion[Dimension]()
region.SetIndex(start)
region.SetSize(size)

image = ImageType.New(Regions=region)
image.Allocate()
image.FillBuffer(0)

# Draw a 5 pixel wide line
image[50:55, 20:80] = 255

# Write Image
itk.imwrite(image, "input.png")

image = itk.binary_thinning_image_filter(image)

# Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
image = itk.rescale_intensity_image_filter(image, output_minimum=0, output_maximum=255)

# Write Image
itk.imwrite(image, "outputPython.png")
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ Results
Code
----

Python
......

.. literalinclude:: Code.py
:language: python
:lines: 1, 16-

C++
...

Expand Down

0 comments on commit 60f1ff8

Please sign in to comment.