Skip to content

Commit 62407af

Browse files
kian-weimerdzenanz
authored andcommitted
ENH: Added RescaleIntensity Python script
1 parent 59473cb commit 62407af

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

src/Filtering/ImageIntensity/RescaleIntensity/CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,25 @@ install( FILES Code.cxx CMakeLists.txt
1919
)
2020

2121
enable_testing()
22+
23+
set( input_image ${CMAKE_CURRENT_BINARY_DIR}/Gourds.png )
24+
set( output_image Output.png )
25+
2226
add_test( NAME RescaleIntensityTest
2327
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/RescaleIntensity
24-
${CMAKE_CURRENT_BINARY_DIR}/Gourds.png
25-
Output.png
28+
${input_image}
29+
${output_image}
2630
0
2731
255
2832
)
33+
34+
if( ITK_WRAP_PYTHON )
35+
string( REPLACE . "Python." output_image "${output_image}" )
36+
add_test( NAME RescaleIntensityTestPython
37+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
38+
${input_image}
39+
${output_image}
40+
0
41+
255
42+
)
43+
endif()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import itk
5+
6+
if len(sys.argv) != 5:
7+
print(
8+
"Usage: "
9+
+ sys.argv[0]
10+
+ " <InputFileName> <OutputFileName> <OutputMin> <OutputMax>"
11+
)
12+
sys.exit(1)
13+
14+
input_image = sys.argv[1]
15+
output_image = sys.argv[1]
16+
output_minimum = int(sys.argv[3])
17+
output_maximum = int(sys.argv[4])
18+
19+
image = itk.imread(sys.argv[1])
20+
21+
image = itk.rescale_intensity_image_filter(
22+
image, output_minimum=output_minimum, output_maximum=output_maximum
23+
)
24+
25+
itk.imwrite(image, sys.argv[2])

src/Filtering/ImageIntensity/RescaleIntensity/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ Results
3232
Code
3333
----
3434

35+
Python
36+
......
37+
38+
.. literalinclude:: Code.py
39+
:language: python
40+
:lines: 1, 16-
41+
3542
C++
3643
...
3744

0 commit comments

Comments
 (0)