Skip to content

Commit

Permalink
ENH: Added RescaleIntensity 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 19753ec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Filtering/ImageIntensity/RescaleIntensity/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,25 @@ install( FILES Code.cxx CMakeLists.txt
)

enable_testing()

set( input_image ${CMAKE_CURRENT_BINARY_DIR}/Gourds.png )
set( output_image Output.png )

add_test( NAME RescaleIntensityTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/RescaleIntensity
${CMAKE_CURRENT_BINARY_DIR}/Gourds.png
Output.png
${input_image}
${output_image}
0
255
)

if( ITK_WRAP_PYTHON )
string( REPLACE . "Python." output_image "${output_image}" )
add_test( NAME RescaleIntensityTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
${input_image}
${output_image}
0
255
)
endif()
25 changes: 25 additions & 0 deletions src/Filtering/ImageIntensity/RescaleIntensity/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python

import sys
import itk

if len(sys.argv) != 5:
print(
"Usage: "
+ sys.argv[0]
+ " <InputFileName> <OutputFileName> <OutputMin> <OutputMax>"
)
sys.exit(1)

input_image = sys.argv[1]
output_image = sys.argv[1]
output_minimum = int(sys.argv[3])
output_maximum = int(sys.argv[4])

image = itk.imread(sys.argv[1])

image = itk.rescale_intensity_image_filter(
image, output_minimum=output_minimum, output_maximum=output_maximum
)

itk.imwrite(image, sys.argv[2])
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ Results
Code
----

Python
......

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

C++
...

Expand Down

0 comments on commit 19753ec

Please sign in to comment.