Skip to content

Commit 942bd95

Browse files
authored
Merge pull request #298 from kian-weimer/SobelEdgeDetectionImageFilter
ENH: Added SobelEdgeDetectionImageFilter Python script
2 parents 1c1318b + 5e4adf5 commit 942bd95

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/CMakeLists.txt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ 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.mha )
25+
2226
add_test( NAME SobelEdgeDetectionImageFilterTest
2327
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/SobelEdgeDetectionImageFilter
24-
${CMAKE_CURRENT_BINARY_DIR}/Gourds.png
25-
Output.mha
28+
${input_image}
29+
${output_image}
2630
)
31+
32+
if( ITK_WRAP_PYTHON )
33+
string( REPLACE . "Python." output_image "${output_image}" )
34+
add_test( NAME SobelEdgeDetectionImageFilterTestPython
35+
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
36+
${input_image}
37+
${output_image}
38+
)
39+
endif()
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright NumFOCUS
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0.txt
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import sys
18+
import itk
19+
20+
if len(sys.argv) != 3:
21+
print("Usage: " + sys.argv[0] + " <InputFileName> <OutputFileName>")
22+
sys.exit(1)
23+
24+
image = itk.imread(sys.argv[1], pixel_type=itk.F)
25+
26+
image = itk.sobel_edge_detection_image_filter(image)
27+
28+
itk.imwrite(image, sys.argv[2])

src/Filtering/ImageFeature/SobelEdgeDetectionImageFilter/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

0 commit comments

Comments
 (0)