Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Added RescaleIntensity Python script #288

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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