Skip to content

Commit

Permalink
ENH: Add Python code for kernel creation examples
Browse files Browse the repository at this point in the history
Add Python code for kernel creation examples.
  • Loading branch information
jhlegarreta committed Jul 20, 2020
1 parent 97b4ca6 commit be2ebf0
Show file tree
Hide file tree
Showing 17 changed files with 252 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Core/Common/CreateDerivativeKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ install(FILES Code.cxx CMakeLists.txt
enable_testing()
add_test(NAME CreateDerivativeKernelTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CreateDerivativeKernel)

if( ITK_WRAP_PYTHON )
add_test( NAME CreateDerivativeKernelTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()
30 changes: 30 additions & 0 deletions src/Core/Common/CreateDerivativeKernel/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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 itk

derivativeOperator = itk.DerivativeOperator[itk.F, 2]()
derivativeOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
derivativeOperator.CreateToRadius(radius)

print("Size: " + str(derivativeOperator.GetSize()))

print(derivativeOperator)

for i in range(9):
print(derivativeOperator.GetOffset(i) + " " + derivativeOperator.GetElement(i))
8 changes: 8 additions & 0 deletions src/Core/Common/CreateDerivativeKernel/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------

Expand Down
30 changes: 30 additions & 0 deletions src/Core/Common/CreateForwardDifferenceKernel/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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 itk

forwardDifferenceOperator = itk.ForwardDifferenceOperator[itk.F, 2]()
forwardDifferenceOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
forwardDifferenceOperator.CreateToRadius(radius)

print("Size: " + str(forwardDifferenceOperator.GetSize()))

print(forwardDifferenceOperator)

for i in range(9):
print(forwardDifferenceOperator.GetOffset(i) + " " + forwardDifferenceOperator.GetElement(i))
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Common/CreateGaussianDerivativeKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ enable_testing()
add_test(NAME CreateGaussianDerivativeKernelTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CreateGaussianDerivativeKernel)

if( ITK_WRAP_PYTHON )
add_test( NAME CreateGaussianDerivativeKernelTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()
30 changes: 30 additions & 0 deletions src/Core/Common/CreateGaussianDerivativeKernel/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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 itk

gaussianDerivativeOperator = itk.GaussianDerivativeOperator[itk.F, 2]()
gaussianDerivativeOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
gaussianDerivativeOperator.CreateToRadius(radius)

print("Size: " + str(gaussianDerivativeOperator.GetSize()))

print(gaussianDerivativeOperator)

for i in range(9):
print(gaussianDerivativeOperator.GetOffset(i) + " " + gaussianDerivativeOperator.GetElement(i))
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------

Expand Down
5 changes: 5 additions & 0 deletions src/Core/Common/CreateGaussianKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ enable_testing()
add_test(NAME CreateGaussianKernelTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CreateGaussianKernel)

if( ITK_WRAP_PYTHON )
add_test( NAME CreateGaussianKernelTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()
30 changes: 30 additions & 0 deletions src/Core/Common/CreateGaussianKernel/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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 itk

gaussianOperator = itk.GaussianOperator[itk.F, 2]()
gaussianOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
gaussianOperator.CreateToRadius(radius)

print("Size: " + str(gaussianOperator.GetSize()))

print(gaussianOperator)

for i in range(9):
print(gaussianOperator.GetOffset(i) + " " + gaussianOperator.GetElement(i))
7 changes: 7 additions & 0 deletions src/Core/Common/CreateGaussianKernel/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------
Expand Down
6 changes: 6 additions & 0 deletions src/Core/Common/CreateLaplacianKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ install(FILES Code.cxx CMakeLists.txt
enable_testing()
add_test(NAME CreateLaplacianKernelTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CreateLaplacianKernel)

if( ITK_WRAP_PYTHON )
add_test( NAME CreateLaplacianKernelTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()
29 changes: 29 additions & 0 deletions src/Core/Common/CreateLaplacianKernel/Code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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 itk

laplacianOperator = itk.LaplacianOperator[itk.F, 2]()
radius = itk.Size[2]()
radius.Fill(1)
laplacianOperator.CreateToRadius(radius)

print("Size: " + str(laplacianOperator.GetSize()))

print(laplacianOperator)

for i in range(laplacianOperator.GetSize()[0] * laplacianOperator.GetSize()[1]):
print(laplacianOperator.GetOffset(i) + " " + laplacianOperator.GetElement(i))
8 changes: 8 additions & 0 deletions src/Core/Common/CreateLaplacianKernel/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------

Expand Down
6 changes: 6 additions & 0 deletions src/Core/Common/CreateSobelKernel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ enable_testing()
add_test(NAME CreateSobelKernelTest
COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CreateSobelKernel)

if( ITK_WRAP_PYTHON )
add_test( NAME CreateSobelKernelTestPython
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py
)
endif()

28 changes: 28 additions & 0 deletions src/Core/Common/CreateSobelKernel/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 itk

sobelOperator = itk.SobelOperator[itk.F, 2]()
sobelOperator.SetDirection(0) # Create the operator for the X axis derivative
radius = itk.Size[2]()
radius.Fill(1)
sobelOperator.CreateToRadius(radius)

print(sobelOperator)

for i in range(9):
print(sobelOperator.GetElement(i))
8 changes: 8 additions & 0 deletions src/Core/Common/CreateSobelKernel/Documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ C++
.. literalinclude:: Code.cxx
:lines: 18-

Python
......

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


Classes demonstrated
--------------------

Expand Down

0 comments on commit be2ebf0

Please sign in to comment.