Skip to content

Commit

Permalink
Merge pull request #298 from kian-weimer/SobelEdgeDetectionImageFilter
Browse files Browse the repository at this point in the history
ENH: Added SobelEdgeDetectionImageFilter Python script
  • Loading branch information
thewtex authored Jun 8, 2021
2 parents 1c1318b + 5e4adf5 commit 942bd95
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ install( FILES Code.cxx CMakeLists.txt
)

enable_testing()

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

add_test( NAME SobelEdgeDetectionImageFilterTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/SobelEdgeDetectionImageFilter
${CMAKE_CURRENT_BINARY_DIR}/Gourds.png
Output.mha
${input_image}
${output_image}
)

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

# Copyright NumFOCUS
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys
import itk

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

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

image = itk.sobel_edge_detection_image_filter(image)

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

Python
......

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

C++
...

Expand Down

1 comment on commit 942bd95

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.