Skip to content

Commit 0c6e1af

Browse files
authored
Merge branch 'master' into image-moments
2 parents 22f432f + 62407af commit 0c6e1af

File tree

10 files changed

+144
-3
lines changed

10 files changed

+144
-3
lines changed

.github/workflows/build-test-publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ jobs:
258258
- os: ubuntu-18.04
259259
c-compiler: "gcc"
260260
cxx-compiler: "g++"
261-
itk-git-tag: "7548a390d71dc25b80e792703ee3cfea17853a99"
261+
itk-git-tag: "v5.2.0"
262262
cmake-build-type: "Release"
263263

264264
steps:

src/Filtering/BinaryMathematicalMorphology/ThinImage/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@ install(FILES Code.cxx CMakeLists.txt
2323
enable_testing()
2424
add_test(NAME ThinImageTest
2525
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ThinImage)
26+
27+
if(ITK_WRAP_PYTHON)
28+
add_test(NAME ThinImageTestPython
29+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py)
30+
endif()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import itk
5+
6+
PixelType = itk.UC
7+
Dimension = 2
8+
ImageType = itk.Image[PixelType, Dimension]
9+
10+
if len(sys.argv) == 2:
11+
image = itk.imread(sys.argv[1])
12+
13+
else:
14+
# Create an image
15+
start = itk.Index[Dimension]()
16+
start.Fill(0)
17+
18+
size = itk.Size[Dimension]()
19+
size.Fill(100)
20+
21+
region = itk.ImageRegion[Dimension]()
22+
region.SetIndex(start)
23+
region.SetSize(size)
24+
25+
image = ImageType.New(Regions=region)
26+
image.Allocate()
27+
image.FillBuffer(0)
28+
29+
# Draw a 5 pixel wide line
30+
image[50:55, 20:80] = 255
31+
32+
# Write Image
33+
itk.imwrite(image, "input.png")
34+
35+
image = itk.binary_thinning_image_filter(image)
36+
37+
# Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
38+
image = itk.rescale_intensity_image_filter(image, output_minimum=0, output_maximum=255)
39+
40+
# Write Image
41+
itk.imwrite(image, "outputPython.png")

src/Filtering/BinaryMathematicalMorphology/ThinImage/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ Results
2929
Code
3030
----
3131

32+
Python
33+
......
34+
35+
.. literalinclude:: Code.py
36+
:language: python
37+
:lines: 1, 16-
38+
3239
C++
3340
...
3441

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

src/IO/ImageBase/WriteAnImage/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ install( FILES Code.cxx CMakeLists.txt
2121
enable_testing()
2222
add_test( NAME WriteAnImageTest
2323
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WriteAnImage )
24+
25+
if(ITK_WRAP_PYTHON)
26+
add_test(NAME WriteAnImageTestPython
27+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py)
28+
endif()

src/IO/ImageBase/WriteAnImage/Code.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
import itk
5+
6+
if len(sys.argv) > 1:
7+
output_filename = sys.argv[1]
8+
else:
9+
output_filename = "testPython.png"
10+
11+
pixel_type = itk.UC
12+
dimension = 2
13+
image_type = itk.Image[pixel_type, dimension]
14+
15+
start = itk.Index[dimension]()
16+
start.Fill(0)
17+
18+
size = itk.Size[dimension]()
19+
size[0] = 200
20+
size[1] = 300
21+
22+
region = itk.ImageRegion[dimension]()
23+
region.SetIndex(start)
24+
region.SetSize(size)
25+
26+
image = image_type.New(Regions=region)
27+
image.Allocate()
28+
29+
itk.imwrite(image, output_filename)

src/IO/ImageBase/WriteAnImage/Documentation.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ Results
2626
Code
2727
----
2828

29+
Python
30+
......
31+
32+
.. literalinclude:: Code.py
33+
:language: python
34+
:lines: 1, 16-
35+
2936
C++
3037
...
3138

0 commit comments

Comments
 (0)