Skip to content

Commit

Permalink
ENH: Added WriteAnImage Python script
Browse files Browse the repository at this point in the history
  • Loading branch information
kian-weimer authored and dzenanz committed Jun 2, 2021
1 parent c1ca53f commit ce85585
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/IO/ImageBase/WriteAnImage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ install( FILES Code.cxx CMakeLists.txt
enable_testing()
add_test( NAME WriteAnImageTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WriteAnImage )

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

import sys
import itk

if len(sys.argv) > 1:
output_filename = sys.argv[1]
else:
output_filename = "testPython.png"

pixel_type = itk.UC
dimension = 2
image_type = itk.Image[pixel_type, dimension]

start = itk.Index[dimension]()
start.Fill(0)

size = itk.Size[dimension]()
size[0] = 200
size[1] = 300

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

image = image_type.New(Regions=region)
image.Allocate()

itk.imwrite(image, output_filename)
7 changes: 7 additions & 0 deletions src/IO/ImageBase/WriteAnImage/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ Results
Code
----

Python
......

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

C++
...

Expand Down

1 comment on commit ce85585

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.