From f7c20d4ce21d343ab828afa028321ca2c0a4a111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Sun, 19 Jul 2020 11:50:13 -0400 Subject: [PATCH] ENH: Add Python code for `DuplicateAnImage` example Add Python code for `DuplicateAnImage` example. --- .../Common/DuplicateAnImage/CMakeLists.txt | 6 ++++ src/Core/Common/DuplicateAnImage/Code.py | 29 +++++++++++++++++++ .../Common/DuplicateAnImage/Documentation.rst | 7 +++++ 3 files changed, 42 insertions(+) create mode 100755 src/Core/Common/DuplicateAnImage/Code.py diff --git a/src/Core/Common/DuplicateAnImage/CMakeLists.txt b/src/Core/Common/DuplicateAnImage/CMakeLists.txt index fdcf4bc92..f45cbf5d4 100644 --- a/src/Core/Common/DuplicateAnImage/CMakeLists.txt +++ b/src/Core/Common/DuplicateAnImage/CMakeLists.txt @@ -21,3 +21,9 @@ install( FILES Code.cxx CMakeLists.txt enable_testing() add_test( NAME DuplicateAnImageTest COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/DuplicateAnImage ) + +if( ITK_WRAP_PYTHON ) + add_test( NAME DuplicateAnImageTestPython + COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/Code.py + ) +endif() diff --git a/src/Core/Common/DuplicateAnImage/Code.py b/src/Core/Common/DuplicateAnImage/Code.py new file mode 100755 index 000000000..f20d5d604 --- /dev/null +++ b/src/Core/Common/DuplicateAnImage/Code.py @@ -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 + +Dimension = 2 +PixelType = itk.UC + +ImageType = itk.Image[PixelType, Dimension] + +randomImageSource = itk.RandomImageSource[ImageType]() +randomImageSource.SetNumberOfWorkUnits(1) # to produce non-random results + +image = randomImageSource.GetOutput() + +clonedImage = itk.image_duplicator(image) diff --git a/src/Core/Common/DuplicateAnImage/Documentation.rst b/src/Core/Common/DuplicateAnImage/Documentation.rst index c595a4f49..3e7c964d1 100644 --- a/src/Core/Common/DuplicateAnImage/Documentation.rst +++ b/src/Core/Common/DuplicateAnImage/Documentation.rst @@ -24,6 +24,13 @@ C++ .. literalinclude:: Code.cxx :lines: 18- +Python +...... + +.. literalinclude:: Code.py + :language: python + :lines: 1, 16- + Classes demonstrated --------------------