diff --git a/Documentation/Maintenance/Release.md b/Documentation/Maintenance/Release.md index c35bb770165..dff8e4fcc76 100644 --- a/Documentation/Maintenance/Release.md +++ b/Documentation/Maintenance/Release.md @@ -327,6 +327,22 @@ Add any new remote modules to nightly builds. Some builds may be difficult to ad due to third-party dependencies. +Update Remote Modules +--------------------- + +In order to have the latest versions for all remote modules, and have them use +the latest ITK tag, the following steps should be performed: + +1. Update the ITK tag used in the `azure-pipelines.yml` CI configuration and the +`setup.py` Python setup files using the [](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Utilities/Maintenance/) +script. This will involve merging a new pull request to each remote module +repository. + +2. Update the remote modules to their latest commits using the +[UpdateRemoteModules.sh](https://github.com/InsightSoftwareConsortium/ITK/tree/master/Utilities/Maintenance/UpdateRemoteModules.sh) +script. + + Create Tarballs --------------- diff --git a/Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt b/Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt index 92481c445fe..0f732ef309a 100644 --- a/Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt +++ b/Modules/Filtering/MathematicalMorphology/test/CMakeLists.txt @@ -524,6 +524,18 @@ itk_add_test(NAME itkRankImageFilterTest10 # some tests will fail if dim=2 and unsigned short are not wrapped list(FIND ITK_WRAP_IMAGE_DIMS 2 wrap_2_index) if(ITK_WRAP_unsigned_char AND wrap_2_index GREATER -1) + itk_python_add_test(NAME PythonFlatStructuringElementBall + TEST_DRIVER_ARGS + COMMAND FlatStructuringElementTest.py + Ball + 5 + ) + itk_python_add_test(NAME PythonFlatStructuringElementBox + TEST_DRIVER_ARGS + COMMAND FlatStructuringElementTest.py + Box + 5 + ) itk_python_add_test(NAME PythonGrayscaleDilateImageFilterTest TEST_DRIVER_ARGS --compare ${ITK_TEST_OUTPUT_DIR}/PythonGrayscaleDilateImageFilterTest.png diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/ImageToArray.py b/Modules/Filtering/MathematicalMorphology/test/FlatStructuringElementTest.py similarity index 62% rename from Wrapping/Generators/Python/Tests/notYetUsable/ImageToArray.py rename to Modules/Filtering/MathematicalMorphology/test/FlatStructuringElementTest.py index 66ef5aa2a3b..8c12ee086f6 100644 --- a/Wrapping/Generators/Python/Tests/notYetUsable/ImageToArray.py +++ b/Modules/Filtering/MathematicalMorphology/test/FlatStructuringElementTest.py @@ -16,28 +16,18 @@ # #==========================================================================*/ -from InsightToolkit import * -from numarray import * -from sys import argv - -reader = itkImageFileReaderUC2_New() - -connector = itkPyBufferUC2_New() - -reader.SetFileName(argv[1]) - -reader.Update() - -print "ready to convert image into array" - -buffer = connector.GetArrayFromImage(reader.GetOutput()) - -writer = itkImageFileWriterUC2_New() - -writer.SetFileName(argv[2]) - -print "ready to convert array into image" - -writer.SetInput(connector.GetImageFromArray(buffer)) - -writer.Update() +from __future__ import print_function + +import itk +from sys import argv, exit +itk.auto_progress(2) + +if argv[1] == "Ball": + print("Ball") + strel = itk.FlatStructuringElement[2].Ball(int(argv[2])) +elif argv[1] == "Box": + print("Box") + strel = itk.FlatStructuringElement[2].Box(int(argv[2])) +else: + print("invalid arguement: " + argv[1]) + exit(1) diff --git a/Modules/IO/ImageBase/include/itkImageFileReader.hxx b/Modules/IO/ImageBase/include/itkImageFileReader.hxx index ec6fdffcf2a..b7c1116fec4 100644 --- a/Modules/IO/ImageBase/include/itkImageFileReader.hxx +++ b/Modules/IO/ImageBase/include/itkImageFileReader.hxx @@ -26,6 +26,7 @@ #include "itkVectorImage.h" #include "itksys/SystemTools.hxx" +#include // For unique_ptr #include namespace itk @@ -388,87 +389,68 @@ void ImageFileReader< TOutputImage, ConvertPixelTraits > itkDebugMacro (<< "Setting imageIO IORegion to: " << m_ActualIORegion); m_ImageIO->SetIORegion(m_ActualIORegion); - char *loadBuffer = nullptr; // the size of the buffer is computed based on the actual number of // pixels to be read and the actual size of the pixels to be read // (as opposed to the sizes of the output) size_t sizeOfActualIORegion = m_ActualIORegion.GetNumberOfPixels() * ( m_ImageIO->GetComponentSize() * m_ImageIO->GetNumberOfComponents() ); - try + ImageIOBase::IOComponentType ioType = + ImageIOBase + ::MapPixelType< typename ConvertPixelTraits::ComponentType >::CType; + if ( m_ImageIO->GetComponentType() != ioType + || ( m_ImageIO->GetNumberOfComponents() != + ConvertPixelTraits::GetNumberOfComponents() ) ) { - ImageIOBase::IOComponentType ioType = - ImageIOBase - ::MapPixelType< typename ConvertPixelTraits::ComponentType >::CType; - if ( m_ImageIO->GetComponentType() != ioType - || ( m_ImageIO->GetNumberOfComponents() != - ConvertPixelTraits::GetNumberOfComponents() ) ) - { - // the pixel types don't match so a type conversion needs to be - // performed - itkDebugMacro( << "Buffer conversion required from: " - << m_ImageIO->GetComponentTypeAsString(m_ImageIO->GetComponentType()) - << " to: " - << m_ImageIO->GetComponentTypeAsString(ioType) - << " ConvertPixelTraits::NumComponents " - << ConvertPixelTraits::GetNumberOfComponents() - << " m_ImageIO->NumComponents " - << m_ImageIO->GetNumberOfComponents() ); - - loadBuffer = new char[sizeOfActualIORegion]; - m_ImageIO->Read( static_cast< void * >( loadBuffer ) ); - - // See note below as to why the buffered region is needed and - // not actualIOregion - this->DoConvertBuffer( static_cast< void * >( loadBuffer ), - output->GetBufferedRegion().GetNumberOfPixels() ); - } - else if ( m_ActualIORegion.GetNumberOfPixels() != - output->GetBufferedRegion().GetNumberOfPixels() ) - { - // NOTE: - // for the number of pixels read and the number of pixels - // requested to not match, the dimensions of the two regions may - // be different, therefore we buffer and copy the pixels - - itkDebugMacro(<< "Buffer required because file dimension is greater then image dimension"); + // the pixel types don't match so a type conversion needs to be + // performed + itkDebugMacro( << "Buffer conversion required from: " + << m_ImageIO->GetComponentTypeAsString(m_ImageIO->GetComponentType()) + << " to: " + << m_ImageIO->GetComponentTypeAsString(ioType) + << " ConvertPixelTraits::NumComponents " + << ConvertPixelTraits::GetNumberOfComponents() + << " m_ImageIO->NumComponents " + << m_ImageIO->GetNumberOfComponents() ); + + const std::unique_ptr loadBuffer(new char[sizeOfActualIORegion]); + m_ImageIO->Read( static_cast< void * >( loadBuffer.get() ) ); + + // See note below as to why the buffered region is needed and + // not actualIOregion + this->DoConvertBuffer( static_cast< void * >( loadBuffer.get() ), + output->GetBufferedRegion().GetNumberOfPixels() ); + } + else if ( m_ActualIORegion.GetNumberOfPixels() != + output->GetBufferedRegion().GetNumberOfPixels() ) + { + // NOTE: + // for the number of pixels read and the number of pixels + // requested to not match, the dimensions of the two regions may + // be different, therefore we buffer and copy the pixels - OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer(); + itkDebugMacro(<< "Buffer required because file dimension is greater then image dimension"); - loadBuffer = new char[sizeOfActualIORegion]; - m_ImageIO->Read( static_cast< void * >( loadBuffer ) ); + OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer(); - // we use std::copy here as it should be optimized to memcpy for - // plain old data, but still is oop - std::copy(reinterpret_cast< const OutputImagePixelType * >( loadBuffer ), - reinterpret_cast< const OutputImagePixelType * >( loadBuffer ) + output->GetBufferedRegion().GetNumberOfPixels(), - outputBuffer); - } - else - { - itkDebugMacro(<< "No buffer conversion required."); + const std::unique_ptr loadBuffer(new char[sizeOfActualIORegion]); + m_ImageIO->Read( static_cast< void * >( loadBuffer.get() ) ); - OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer(); - m_ImageIO->Read(outputBuffer); - } + // we use std::copy_n here as it should be optimized to memcpy for + // plain old data, but still is oop + std::copy_n(reinterpret_cast< const OutputImagePixelType * >( loadBuffer.get() ), + output->GetBufferedRegion().GetNumberOfPixels(), + outputBuffer); } - catch ( ... ) + else { - // if an exception is thrown catch it - - // clean up - delete[] loadBuffer; - loadBuffer = nullptr; + itkDebugMacro(<< "No buffer conversion required."); - // then rethrow - throw; + OutputImagePixelType *outputBuffer = output->GetPixelContainer()->GetBufferPointer(); + m_ImageIO->Read(outputBuffer); } this->UpdateProgress( 1.0f ); - - // clean up - delete[] loadBuffer; - loadBuffer = nullptr; } template< typename TOutputImage, typename ConvertPixelTraits > diff --git a/Utilities/Maintenance/UpdateRemoteModules.sh b/Utilities/Maintenance/UpdateRemoteModules.sh new file mode 100755 index 00000000000..fd2df2bf7f3 --- /dev/null +++ b/Utilities/Maintenance/UpdateRemoteModules.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +#========================================================================== +# +# Copyright Insight Software Consortium +# +# 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. +# +#==========================================================================*/ + + +# Make sure we are inside the repository +cd "${BASH_SOURCE%/*}" && + +remote_modules_path=$(cd ../../Modules/Remote && pwd) + +git_repository_tag_label='GIT_REPOSITORY' +git_tag_label='GIT_TAG' + +# Loop over the remote modules' CMake files +for filename in ${remote_modules_path}/*.cmake; do + + # Get the current commit hash + curr_commit_str=($(grep $git_tag_label $filename)) + curr_commit_hash=${curr_commit_str[1]} + + # Read the git repository information + repository_str=$(grep $git_repository_tag_label $filename) + + repository_arr=($(echo $repository_str | tr "/" " ")) + organization=${repository_arr[-2]} + repository_name=${repository_arr[-1]} + + # Get the latest git commit hash of the remote module. + # Remotes will usually not be tagged. + latest_commit_hash=$(git ls-remote git://github.com/$organization/$repository_name | \ + grep refs/heads/master | cut -f 1) + + # Sed the the latest commit hash in the CMake file + sed -i "s/${curr_commit_hash}/${latest_commit_hash}/g" $filename + +done diff --git a/Utilities/Maintenance/UpdateRequiredITKVersionInFiles.sh b/Utilities/Maintenance/UpdateRequiredITKVersionInFiles.sh new file mode 100755 index 00000000000..dba3dd6194a --- /dev/null +++ b/Utilities/Maintenance/UpdateRequiredITKVersionInFiles.sh @@ -0,0 +1,69 @@ +#!/bin/bash + +#========================================================================== +# +# Copyright Insight Software Consortium +# +# 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. +# +#==========================================================================*/ + + +program_name=$0 + +function usage { + echo "Usage: ${program_name} " + echo " param1 Azure pipelines file path" + echo " param2 Setup.py file path" + exit 1 +} + +# Display usage +if [ ${#@} != 2 ]; then + usage +fi + +azure_pipelines_ci_filename=$1 +python_setup_filename=$2 + +# Get the latest ITK git tag +latest_git_tag=$(git ls-remote --tags --sort="v:refname" \ +git://github.com/InsightSoftwareConsortium/ITK.git | tail -n1 | \ +sed 's/.*\///; s/\^{}//') + +# Azure pipeline CI file +git_tag_label='ITKGitTag: ' + +# Read the ITK git tag information +curr_git_str=($(grep $git_tag_label $filename)) +curr_git_tag=${curr_git_str[1]} + +# Sed the latest ITK git tag in the Azure pipelines config file +sed -i "s/${curr_git_tag}/${latest_git_tag}/g" $azure_pipelines_ci_filename + +# Python setup file + +# Strip the "v" prefix +latest_git_tag=${latest_git_tag:1} + +git_install_req_tag_label='\install_requires=\[' + +# Read the ITK install requirement git tag information +git_install_req_tag_str=($(grep -A1 -P ${git_install_req_tag_label}$ $filename)) +git_install_req_tag=${git_install_req_tag_str[1]} + +git_install_req_tag_arr=($(echo $git_install_req_tag | tr "=" " ")) +curr_git_tag=${git_install_req_tag_arr[-1]} + +# Sed the latest ITK git tag in the Python setup file +sed -i "s/${curr_git_tag}/${latest_git_tag}/g" $python_setup_filename diff --git a/Wrapping/Generators/Python/Tests/CMakeLists.txt b/Wrapping/Generators/Python/Tests/CMakeLists.txt index fd38fec55f5..7ebf5874228 100644 --- a/Wrapping/Generators/Python/Tests/CMakeLists.txt +++ b/Wrapping/Generators/Python/Tests/CMakeLists.txt @@ -9,21 +9,9 @@ endif() itk_python_add_test(NAME PythonImageIOCoverage COMMAND wrappingCoverage.py -b ImageIO -e ${CMAKE_CURRENT_SOURCE_DIR}/exclude-imageio.txt ${ITK_INCLUDE_DIRS}) itk_python_add_test(NAME PythonTransformCoverage COMMAND wrappingCoverage.py -b Transform -e ${CMAKE_CURRENT_SOURCE_DIR}/exclude-transform.txt ${ITK_INCLUDE_DIRS}) -execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import numpy" - RESULT_VARIABLE _have_numpy_return_code - OUTPUT_QUIET - ERROR_QUIET - ) - -# These two tests can use up all of system memory when the are executed. -# TODO: find the root cause and re-enable them. See ITK-3006 on issues.itk.org. -#itk_python_add_test(PythonFindEmptyClasses findEmptyClasses.py) -if(_have_numpy_return_code EQUAL 0 AND ITK_BUILD_DEFAULT_MODULES) - # Currently unreliably fails. See Issue #96 - # itk_python_add_test(NAME PythonGetNameOfClass COMMAND getNameOfClass.py) - - itk_python_add_test(NAME PythonTiming COMMAND timing.py) -endif() +itk_python_add_test(NAME PythonFindEmptyClasses COMMAND findEmptyClasses.py) +itk_python_add_test(NAME PythonGetNameOfClass COMMAND getNameOfClass.py) +itk_python_add_test(NAME PythonTiming COMMAND timing.py) itk_python_add_test(NAME PythonVerifyGetOutputAPIConsistency COMMAND verifyGetOutputAPIConsistency.py) itk_python_add_test(NAME PythonVerifyTTypeAPIConsistency COMMAND verifyTTypeAPIConsistency.py) itk_python_add_test(NAME PythonComplex COMMAND complex.py) @@ -49,70 +37,13 @@ if(ITK_WRAP_unsigned_char AND WRAP_2) DATA{${WrapITK_SOURCE_DIR}/images/cthead1.png} 5 ) - if(_have_numpy_return_code EQUAL 0) - itk_python_add_test(NAME PythonExtrasTest - COMMAND extras.py - DATA{${WrapITK_SOURCE_DIR}/images/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/out.png ${ITK_TEST_OUTPUT_DIR} - ) - endif() + itk_python_add_test(NAME PythonExtrasTest + COMMAND extras.py + DATA{${WrapITK_SOURCE_DIR}/images/cthead1.png} ${ITK_TEST_OUTPUT_DIR}/out.png ${ITK_TEST_OUTPUT_DIR} + ) endif() - -# itk_python_add_test(NAME PythonStrelFromImageGrayscaleDilateImageFilter -# StrelFromImageGrayscaleDilateImageFilter.py -# DATA{${WrapITK_SOURCE_DIR}/images/cthead1.png} -# StrelFromImageGrayscaleDilateImageFilter.png -# DATA{${WrapITK_SOURCE_DIR}/images/StrelFromImage.png} -# --compare StrelFromImageGrayscaleDilateImageFilter.png DATA{${WrapITK_SOURCE_DIR}/images/StrelFromImageGrayscaleDilateImageFilter.png} -# ) - -# itk_python_add_test(NAME PythonFlatStructuringElementBall -# FlatStructuringElement.py -# Ball-5.png -# Ball -# 5 -# --compare Ball-5.png DATA{${WrapITK_SOURCE_DIR}/images/Ball-5.png} -# ) - -# itk_python_add_test(NAME PythonFlatStructuringElementBox -# FlatStructuringElement.py -# Box-5.png -# Box -# 5 -# --compare Box-5.png DATA{${WrapITK_SOURCE_DIR}/images/Box-5.png} -# ) - -# itk_python_add_test(NAME PythonFlatStructuringElementFromImage -# FlatStructuringElement.py -# StrelFromImage.png -# FromImage -# DATA{${WrapITK_SOURCE_DIR}/images/StrelFromImage.png} -# --compare StrelFromImage.png DATA{${WrapITK_SOURCE_DIR}/images/StrelFromImage.png} -# ) -endif() - -if(ITK_WRAP_float AND WRAP_2) -# itk_python_add_test(NAME PythonGeodesicActiveContourWhiteMatterTest -# --compare GeodesicActiveContourWhiteMatterTest.png -# DATA{${WrapITK_SOURCE_DIR}/images/GeodesicActiveContourWhiteMatterTest.png} -# -- -# GeodesicActiveContourImageFilter.py -# DATA{${WrapITK_SOURCE_DIR}/images/BrainProtonDensitySlice.png} -# GeodesicActiveContourWhiteMatterTest.png -# 56 92 5.0 1.0 -0.3 2.0 10.0 -# ) - -# itk_python_add_test(NAME PythonGeodesicActiveContourGrayMatterTest -# --compare GeodesicActiveContourGrayMatterTest.png -# DATA{${WrapITK_SOURCE_DIR}/images/GeodesicActiveContourGrayMatterTest.png} -# -- -# GeodesicActiveContourImageFilter.py -# DATA{${WrapITK_SOURCE_DIR}/images/BrainProtonDensitySlice.png} -# GeodesicActiveContourGrayMatterTest.png -# 40 90 5.0 .5 -0.3 2.0 10.0 -# ) endif() - UNIQUE(types "${WRAP_ITK_SCALAR};UC") # signed char can't be used to store an image with values up to 255 list(REMOVE_ITEM types SC) diff --git a/Wrapping/Generators/Python/Tests/FlatStructuringElement.py b/Wrapping/Generators/Python/Tests/FlatStructuringElement.py deleted file mode 100644 index 26b6c46b810..00000000000 --- a/Wrapping/Generators/Python/Tests/FlatStructuringElement.py +++ /dev/null @@ -1,53 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -from __future__ import print_function - -import itk -from sys import argv, exit -itk.auto_progress(2) - -if argv[2] == "Ball": - print("Ball") - strel = itk.FlatStructuringElement[2].Ball(int(argv[3])) -elif argv[2] == "Box": - print("Box") - strel = itk.FlatStructuringElement[2].Box(int(argv[3])) -elif argv[2] == "FromImage": - print("FromImage") - reader = itk.ImageFileReader.IUC2.New(FileName=argv[3]) - strel = itk.FlatStructuringElement[2].FromImageUC(reader.GetOutput()) -else: - print("invalid arguement: " + argv[2]) - exit(1) - -img = strel.GetImageUC() -size = itk.size(img) -for y in range(0, size.GetElement(1)): - for x in range(0, size.GetElement(0)): - if img.GetPixel([x, y]): - print("X") - else: - print(" ") - print("\n") - -itk.write(img, argv[1]) - -# writer = itk.ImageFileWriter.IUC2.New(FileName=argv[1], Input=img ) -# itk.echo(writer) -# writer.Update() diff --git a/Wrapping/Generators/Python/Tests/OldStyleBinaryDilateImageFilter.py b/Wrapping/Generators/Python/Tests/OldStyleBinaryDilateImageFilter.py deleted file mode 100644 index bb01f4ffea9..00000000000 --- a/Wrapping/Generators/Python/Tests/OldStyleBinaryDilateImageFilter.py +++ /dev/null @@ -1,37 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -# -# Example on the use of the BinaryDilateImageFilter -# - -from InsightToolkit import * -from sys import argv - -reader = itkImageFileReaderIUC2.New() -reader.SetFileName(argv[1]) -kernel = itkFlatStructuringElement2.Ball(5) -filter = itkBinaryDilateImageFilterIUC2IUC2SE2.New() -filter.SetInput(reader.GetOutput()) -filter.SetDilateValue(200) -filter.SetKernel(kernel) -writer = itkImageFileWriterIUC2.New() -writer.SetInput(filter.GetOutput()) -writer.SetFileName(argv[2]) - -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/StrelFromImageGrayscaleDilateImageFilter.py b/Wrapping/Generators/Python/Tests/StrelFromImageGrayscaleDilateImageFilter.py deleted file mode 100644 index 758828e8336..00000000000 --- a/Wrapping/Generators/Python/Tests/StrelFromImageGrayscaleDilateImageFilter.py +++ /dev/null @@ -1,40 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -# -# Example on the use of the GrayscaleDilateImageFilter -# and Box strucutring element -# - -import itk -from sys import argv -itk.auto_progress(2) - -dim = 2 -IType = itk.Image[itk.US, dim] -OIType = itk.Image[itk.UC, dim] - -reader = itk.ImageFileReader[IType].New(FileName=argv[1]) -reader2 = itk.ImageFileReader[OIType].New(FileName=argv[3]) -kernel = itk.FlatStructuringElement[dim].FromImageUC(reader2.GetOutput()) -grayscaleFilter = itk.GrayscaleDilateImageFilter[IType, IType, kernel] -grayscaleFilter = grayscaleFilter.New(reader, Kernel=kernel) -cast = itk.CastImageFilter[IType, OIType].New(grayscaleFilter) -writer = itk.ImageFileWriter[OIType].New(cast, FileName=argv[2]) - -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/exclude-filters.txt b/Wrapping/Generators/Python/Tests/exclude-filters.txt index 4addb8a8a69..8ad66df0227 100644 --- a/Wrapping/Generators/Python/Tests/exclude-filters.txt +++ b/Wrapping/Generators/Python/Tests/exclude-filters.txt @@ -3,7 +3,6 @@ ReconstructionImageFilter ObjectMorphologyImageFilter MovingHistogramDilateImageFilter MovingHistogramErodeImageFilter -MovingHistogramImageFilter MovingHistogramMorphologicalGradientImageFilter MovingHistogramMorphologyImageFilter MorphologyImageFilter @@ -37,9 +36,7 @@ MiniPipelineSeparableImageFilter VanHerkGilWermanDilateImageFilter VanHerkGilWermanErodeDilateImageFilter VanHerkGilWermanErodeImageFilter -InterpolateImageFilter MaskedMovingHistogramImageFilter -MeshToMeshFilter VectorFuzzyConnectednessImageFilter WarpJacobianDeterminantFilter MatrixIndexSelectionImageFilter diff --git a/Wrapping/Generators/Python/Tests/findEmptyClasses.py b/Wrapping/Generators/Python/Tests/findEmptyClasses.py index 93b3d677030..b75e319b7c9 100644 --- a/Wrapping/Generators/Python/Tests/findEmptyClasses.py +++ b/Wrapping/Generators/Python/Tests/findEmptyClasses.py @@ -19,110 +19,70 @@ from __future__ import print_function import itk -import re import sys -# itk.auto_progress(True) - from itkTemplate import itkTemplate -# sets are not in builtin with python older than 2.4 -import sets -set = sets.Set - -# dirty but easier: a global var to count the empty classes -empty = set() - - -def exploreTpl(tpl): - for cl in tpl.itervalues(): - print(cl) - exploreMethods(cl) - # try to instanciate the class - try: - obj = cl.New() - exploreMethods(obj) - except: - pass - try: - exploreMethods(cl()) - except: - pass - - -def exploreMethods(obj): - global count - excludeList = ['this', 'thisown'] - attrNameList = [i for i in dir( - obj) if isinstance(i, str) and i[0].isupper() and i not in excludeList] - if attrNameList == []: - empty.add(obj) - - -excluded = set([ - "PeriodicBoundaryCondition", - "BandNode", - "DefaultDynamicMeshTraits", - "DefaultStaticMeshTraits", - "NormalBandNode", - "ZeroFluxNeumannBoundaryCondition", - "SparseFieldLevelSetNode", - "ParallelSparseFieldLevelSetNode", - "PySwigIterator", - "SwigPyIterator", - "COLORS", - "VECTOR_REALS", - "SCALARS", - "ALL_TYPES", - "COMPLEX_REALS", - "RGBS", - "RGBAS", - "REALS", - "USIGN_INTS", - "DIMS", - "SIGN_INTS", - "VECTORS", - "INTS", - "COV_VECTOR_REALS", - "FFTComplexToComplexImageFilter", - "QuadEdgeMeshCellTraitsInfo", - "QuadEdgeMeshTraits", - "OnesMatrixCoefficients", - "ConformalMatrixCoefficients", - "InverseEuclideanDistanceMatrixCoefficients", - "AuthalicMatrixCoefficients", - "IntrinsicMatrixCoefficients", - "InverseEuclideanDistanceMatrixCoefficients", - "OnesMatrixCoefficients", - "ConformalMatrixCoefficients", - "AuthalicMatrixCoefficients", - "MatrixCoefficients", -]) - - -attrNameList = set( - [i for i in dir(itk) if i[0].isupper() and len(i) > 2]) - excluded - -for name in attrNameList: - # use it because of lazy loading - exec "attr = itk." + name - print("-----------", name, "-----------") - if isinstance(attr, itkTemplate): - exploreTpl(attr) - else: - exploreMethods(attr) - try: - exploreMethods(cl.New()) - except: - pass - try: - exploreMethods(cl()) - except: - pass - -print() -print() -print(len(empty), "empty classes found") -for c in empty: - print(c) - -sys.exit(len(empty)) +itk.auto_progress(2) + +itk.force_load() + +def isEmpty(o): + for i in dir(o): + if i[0].isupper(): + return False + return True + + +exclude = ["AuthalicMatrixCoefficients", + "MatrixCoefficients", + "OnesMatrixCoefficients", + "IntrinsicMatrixCoefficients", + "HarmonicMatrixCoefficients", + "ConformalMatrixCoefficients", + "InverseEuclideanDistanceMatrixCoefficients", + "BandNode", + "NormalBandNode", + "CellTraitsInfo", + "DefaultDynamicMeshTraits", + "DefaultStaticMeshTraits", + "ParallelSparseFieldLevelSetNode", + "SparseFieldLevelSetNode", + "QuadEdgeMeshCellTraitsInfo", + "QuadEdgeMeshTraits", + "complex", + "list", + "map", + "numeric_limits", + "set", + "vector", + "vnl_c_vector", + "vnl_diag_matrix", + "vnl_matrix", + "vnl_matrix_fixed", + "vnl_matrix_fixed_ref", + "vnl_matrix_fixed_ref_const", + "vnl_matrix_ref", + "vnl_vector", + "vnl_vector_ref", + "vnl_file_matrix", + "vnl_file_vector", + "vnl_fortran_copy", + ] + +total = 0 +empty = 0 + +for t in dir(itk): + if t not in exclude: + T = itk.__dict__[t] + if isinstance(T, itkTemplate): + for I in T.values(): + total += 1 + if isEmpty(I): + empty += 1 + print("%s: empty class" % I) + +print("%s classes checked." % total) +if empty: + print("%s empty classes found" % empty, file=sys.stderr) + sys.exit(1) diff --git a/Wrapping/Generators/Python/Tests/getNameOfClass.py b/Wrapping/Generators/Python/Tests/getNameOfClass.py index 2af8c297233..01799e1d36b 100644 --- a/Wrapping/Generators/Python/Tests/getNameOfClass.py +++ b/Wrapping/Generators/Python/Tests/getNameOfClass.py @@ -28,6 +28,15 @@ itk.force_load() # itk.ImageToImageFilter + +def wrongClassName(cl, name): + o = cl.New() + # be sure that the type of the instantiated object is the same + # than the one of the class. It can be different if the class + # is an "abstract" one and don't provide any New() method. + # In that case, the one of the superclass is used. + return o.GetNameOfClass() != name and itk.class_(o) == cl + # a list of classes to exclude. Typically, the classes with a custom New() # method, which return a subclass of the current class exclude = ["ForwardFFTImageFilter", @@ -39,7 +48,9 @@ "templated_class", "HalfHermitianToRealInverseFFTImageFilter", "RealToHalfHermitianForwardFFTImageFilter", - "CustomColormapFunction"] + "CustomColormapFunction", + "ScanlineFilterCommon" # Segfault + ] wrongName = 0 totalName = 0 @@ -54,31 +65,19 @@ i = T.values()[0] # GetNameOfClass() is a virtual method of the LightObject class, # so we must instantiate an object with the New() method - if 'New' in dir(i): - I = i.New() - # be sure that the type of the instantiated object is the same - # than the one of the class. It can be different if the class - # is an "abstract" one and don't provide any New() method. - # In that case, the one of the superclass is used. - if 'GetNameOfClass' in dir(I): - # print("Checking", t) - totalName += 1 - n = I.GetNameOfClass() - if n != t and itk.class_(I) == i: - msg = "%s: wrong class name: %s" % (t, n) - print(msg, file=sys.stderr) - wrongName += 1 + if 'New' in dir(i) and 'GetNameOfClass' in dir(i): + totalName += 1 + if wrongClassName(i, t): + msg = "%s: wrong class name: %s" % (t, n) + print(msg, file=sys.stderr) + wrongName += 1 else: - if 'New' in dir(T): - I = T.New() - if 'GetNameOfClass' in dir(I): - # print("Checking", t) - totalName += 1 - n = I.GetNameOfClass() - if n != t and itk.class_(I) == T: - msg = "%s: wrong class name: %s" % (t, n) - print(msg, file=sys.stderr) - wrongName += 1 + if 'New' in dir(T) and 'GetNameOfClass' in dir(T): + totalName += 1 + if wrongClassName(T, t): + msg = "%s: wrong class name: %s" % (t, n) + print(msg, file=sys.stderr) + wrongName += 1 print("%s classes checked." % totalName) if wrongName: diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/DicomSliceRead.py b/Wrapping/Generators/Python/Tests/notYetUsable/DicomSliceRead.py deleted file mode 100644 index 5df27985121..00000000000 --- a/Wrapping/Generators/Python/Tests/notYetUsable/DicomSliceRead.py +++ /dev/null @@ -1,50 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -# -# Example on the use of DicomImageIO for reading a single DICOM slice, rescale -# the intensities and save it in a different file format. -# - -from InsightToolkit import * - -from sys import argv - -# -# Reads an image in 16bits/pixel -# and save it as 8bits/pixel -# -reader = itkImageFileReaderUS2_New() -writer = itkImageFileWriterUC2_New() - -dicomIO = itkDicomImageIO_New() - -reader.SetImageIO(dicomIO) - -filter = itkRescaleIntensityImageFilterUS2UC2_New() - -filter.SetOutputMinimum(0) -filter.SetOutputMaximum(255) - -filter.SetInput(reader.GetOutput()) -writer.SetInput(filter.GetOutput()) - -reader.SetFileName(argv[1]) -writer.SetFileName(argv[2]) - -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration3.py b/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration3.py deleted file mode 100644 index 4caa99a81db..00000000000 --- a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration3.py +++ /dev/null @@ -1,136 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -from InsightToolkit import * - -from sys import argv - - -# -# Read the fixed and moving images using filenames -# from the command line arguments -# -fixedImageReader = itkImageFileReaderF2_New() -movingImageReader = itkImageFileReaderF2_New() - -fixedImageReader.SetFileName(argv[1]) -movingImageReader.SetFileName(argv[2]) - -fixedImageReader.Update() -movingImageReader.Update() - -fixedImage = fixedImageReader.GetOutput() -movingImage = movingImageReader.GetOutput() - - -# -# Instantiate the classes for the registration framework -# -registration = itkImageRegistrationMethodF2F2_New() -imageMetric = itkMeanSquaresImageToImageMetricF2F2_New() -transform = itkTranslationTransform2_New() -optimizer = itkRegularStepGradientDescentOptimizer_New() -interpolator = itkLinearInterpolateImageFunctionF2D_New() - - -registration.SetOptimizer(optimizer) -registration.SetTransform(transform) -registration.SetInterpolator(interpolator) -registration.SetMetric(imageMetric) -registration.SetFixedImage(fixedImage) -registration.SetMovingImage(movingImage) - -registration.SetFixedImageRegion(fixedImage.GetBufferedRegion()) - -transform.SetIdentity() -initialParameters = transform.GetParameters() - -registration.SetInitialTransformParameters(initialParameters) - -# -# Iteration Observer -# - - -def iterationUpdate(): - currentParameter = transform.GetParameters() - print "M: %f P: %f %f " % (optimizer.GetValue(), - currentParameter.GetElement(0), - currentParameter.GetElement(1)) - -iterationCommand = itkPyCommand_New() -iterationCommand.SetCommandCallable(iterationUpdate) -optimizer.AddObserver(itkIterationEvent(), iterationCommand.GetPointer()) - - -# -# Define optimizer parameters -# -optimizer.SetMaximumStepLength(4.00) -optimizer.SetMinimumStepLength(0.01) -optimizer.SetNumberOfIterations(200) - - -print "Starting registration" - -# -# Start the registration process -# - -registration.Update() - - -# -# Get the final parameters of the transformation -# -finalParameters = registration.GetLastTransformParameters() - -print "Final Registration Parameters " -print "Translation X = %f" % (finalParameters.GetElement(0),) -print "Translation Y = %f" % (finalParameters.GetElement(1),) - - -# -# Now, we use the final transform for resampling the -# moving image. -# -resampler = itkResampleImageFilterF2F2_New() -resampler.SetTransform(transform) -resampler.SetInput(movingImage) - -region = fixedImage.GetLargestPossibleRegion() - -resampler.SetSize(region.GetSize()) - -resampler.SetOutputSpacing(fixedImage.GetSpacing()) -resampler.SetOutputOrigin(fixedImage.GetOrigin()) -resampler.SetDefaultPixelValue(100) - -outputCast = itkRescaleIntensityImageFilterF2US2_New() -outputCast.SetOutputMinimum(0) -outputCast.SetOutputMaximum(65535) -outputCast.SetInput(resampler.GetOutput()) - -# -# Write the resampled image -# -writer = itkImageFileWriterUS2_New() - -writer.SetFileName(argv[3]) -writer.SetInput(outputCast.GetOutput()) -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration4.py b/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration4.py deleted file mode 100644 index b6616c5b45c..00000000000 --- a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration4.py +++ /dev/null @@ -1,139 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -from InsightToolkit import * - -from sys import argv - - -# -# Read the fixed and moving images using filenames -# from the command line arguments -# -fixedImageReader = itkImageFileReaderF2_New() -movingImageReader = itkImageFileReaderF2_New() - -fixedImageReader.SetFileName(argv[1]) -movingImageReader.SetFileName(argv[2]) - -fixedImageReader.Update() -movingImageReader.Update() - -fixedImage = fixedImageReader.GetOutput() -movingImage = movingImageReader.GetOutput() - - -# -# Instantiate the classes for the registration framework -# -registration = itkImageRegistrationMethodF2F2_New() -imageMetric = itkMattesMutualInformationImageToImageMetricF2F2_New() -transform = itkTranslationTransform2_New() -optimizer = itkRegularStepGradientDescentOptimizer_New() -interpolator = itkLinearInterpolateImageFunctionF2D_New() - - -imageMetric.SetNumberOfHistogramBins(20) -imageMetric.SetNumberOfSpatialSamples(10000) - -registration.SetOptimizer(optimizer) -registration.SetTransform(transform) -registration.SetInterpolator(interpolator) -registration.SetMetric(imageMetric) -registration.SetFixedImage(fixedImage) -registration.SetMovingImage(movingImage) - -registration.SetFixedImageRegion(fixedImage.GetBufferedRegion()) - -transform.SetIdentity() -initialParameters = transform.GetParameters() - -registration.SetInitialTransformParameters(initialParameters) - -# -# Iteration Observer -# - - -def iterationUpdate(): - currentParameter = transform.GetParameters() - print "M: %f P: %f %f " % (optimizer.GetValue(), - currentParameter.GetElement(0), - currentParameter.GetElement(1)) - -iterationCommand = itkPyCommand_New() -iterationCommand.SetCommandCallable(iterationUpdate) -optimizer.AddObserver(itkIterationEvent(), iterationCommand.GetPointer()) - - -# -# Define optimizer parameters -# -optimizer.SetMaximumStepLength(4.00) -optimizer.SetMinimumStepLength(0.01) -optimizer.SetNumberOfIterations(200) - - -print "Starting registration" - -# -# Start the registration process -# - -registration.Update() - - -# -# Get the final parameters of the transformation -# -finalParameters = registration.GetLastTransformParameters() - -print "Final Registration Parameters " -print "Translation X = %f" % (finalParameters.GetElement(0),) -print "Translation Y = %f" % (finalParameters.GetElement(1),) - - -# -# Now, we use the final transform for resampling the -# moving image. -# -resampler = itkResampleImageFilterF2F2_New() -resampler.SetTransform(transform) -resampler.SetInput(movingImage) - -region = fixedImage.GetLargestPossibleRegion() - -resampler.SetSize(region.GetSize()) - -resampler.SetOutputSpacing(fixedImage.GetSpacing()) -resampler.SetOutputOrigin(fixedImage.GetOrigin()) -resampler.SetDefaultPixelValue(100) - -outputCast = itkRescaleIntensityImageFilterF2US2_New() -outputCast.SetOutputMinimum(0) -outputCast.SetOutputMaximum(65535) -outputCast.SetInput(resampler.GetOutput()) - -# -# Write the resampled image -# -writer = itkImageFileWriterUS2_New() - -writer.SetFileName(argv[3]) -writer.SetInput(outputCast.GetOutput()) -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration5.py b/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration5.py deleted file mode 100644 index 651b43b1d5f..00000000000 --- a/Wrapping/Generators/Python/Tests/notYetUsable/ImageRegistration5.py +++ /dev/null @@ -1,189 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -# - -from InsightToolkit import * - -from sys import argv - -# -# Read the fixed and moving images using filenames -# from the command line arguments -# -fixedImageReader = itkImageFileReaderF2_New() -movingImageReader = itkImageFileReaderF2_New() - -fixedImageReader.SetFileName(argv[1]) -movingImageReader.SetFileName(argv[2]) - -fixedImageReader.Update() -movingImageReader.Update() - -fixedImage = fixedImageReader.GetOutput() -movingImage = movingImageReader.GetOutput() - -# -# Instantiate the classes for the registration framework -# -registration = itkImageRegistrationMethodF2F2_New() -imageMetric = itkMeanSquaresImageToImageMetricF2F2_New() -transform = itkCenteredRigid2DTransform_New() -optimizer = itkRegularStepGradientDescentOptimizer_New() -interpolator = itkLinearInterpolateImageFunctionF2D_New() - -registration.SetOptimizer(optimizer) -registration.SetTransform(transform) -registration.SetInterpolator(interpolator) -registration.SetMetric(imageMetric) -registration.SetFixedImage(fixedImage) -registration.SetMovingImage(movingImage) -registration.SetFixedImageRegion(fixedImage.GetBufferedRegion()) - - -# -# Initial transform parameters -# -transform.SetAngle(0.0) - -# center of the fixed image -fixedSpacing = fixedImage.GetSpacing() -fixedOrigin = fixedImage.GetOrigin() -fixedSize = fixedImage.GetLargestPossibleRegion().GetSize() - -centerFixed = ( - fixedOrigin.GetElement(0) + fixedSpacing.GetElement(0) * - fixedSize.GetElement(0) / 2.0, - fixedOrigin.GetElement(1) + fixedSpacing.GetElement(1) * - fixedSize.GetElement(1) / 2.0) - -# center of the moving image -movingSpacing = movingImage.GetSpacing() -movingOrigin = movingImage.GetOrigin() -movingSize = movingImage.GetLargestPossibleRegion().GetSize() - -centerMoving = ( - movingOrigin.GetElement(0) + movingSpacing.GetElement(0) * - movingSize.GetElement(0) / 2.0, - movingOrigin.GetElement(1) + movingSpacing.GetElement(1) * - movingSize.GetElement(1) / 2.0) - -# transform center -center = transform.GetCenter() -center.SetElement(0, centerFixed[0]) -center.SetElement(1, centerFixed[1]) - -# transform translation -translation = transform.GetTranslation() -translation.SetElement(0, centerMoving[0] - centerFixed[0]) -translation.SetElement(1, centerMoving[1] - centerFixed[1]) - -initialParameters = transform.GetParameters() - -print "Initial Parameters: " -print "Angle: %f" % (initialParameters.GetElement(0), ) -print "Center: %f, %f" % (initialParameters.GetElement(1), - initialParameters.GetElement(2)) -print "Translation: %f, %f" % (initialParameters.GetElement(3), - initialParameters.GetElement(4)) - -registration.SetInitialTransformParameters(initialParameters) - -# -# Define optimizer parameters -# - -# optimizer scale -translationScale = 1.0 / 1000.0 - -optimizerScales = itkArrayD(transform.GetNumberOfParameters()) -optimizerScales.SetElement(0, 1.0) -optimizerScales.SetElement(1, translationScale) -optimizerScales.SetElement(2, translationScale) -optimizerScales.SetElement(3, translationScale) -optimizerScales.SetElement(4, translationScale) - -optimizer.SetScales(optimizerScales) -optimizer.SetMaximumStepLength(0.1) -optimizer.SetMinimumStepLength(0.001) -optimizer.SetNumberOfIterations(200) - -# -# Iteration Observer -# - - -def iterationUpdate(): - currentParameter = transform.GetParameters() - print "M: %f P: %f %f %f %f %f " % (optimizer.GetValue(), - currentParameter.GetElement(0), - currentParameter.GetElement(1), - currentParameter.GetElement(2), - currentParameter.GetElement(3), - currentParameter.GetElement(4)) - -iterationCommand = itkPyCommand_New() -iterationCommand.SetCommandCallable(iterationUpdate) -optimizer.AddObserver(itkIterationEvent(), iterationCommand.GetPointer()) - -print "Starting registration" - -# -# Start the registration process -# - -registration.Update() - -# -# Get the final parameters of the transformation -# -finalParameters = registration.GetLastTransformParameters() - -print "Final Registration Parameters " -print "Angle in radians = %f" % finalParameters.GetElement(0) -print "Rotation Center X = %f" % finalParameters.GetElement(1) -print "Rotation Center Y = %f" % finalParameters.GetElement(2) -print "Translation in X = %f" % finalParameters.GetElement(3) -print "Translation in Y = %f" % finalParameters.GetElement(4) - -# Now, we use the final transform for resampling the moving image. -resampler = itkResampleImageFilterF2F2_New() - -resampler.SetTransform(transform) -resampler.SetInput(movingImage) - -region = fixedImage.GetLargestPossibleRegion() - -resampler.SetSize(region.GetSize()) -resampler.SetOutputSpacing(fixedImage.GetSpacing()) -resampler.SetOutputOrigin(fixedImage.GetOrigin()) -resampler.SetDefaultPixelValue(100) - -# -# Cast for output -# -outputCast = itkRescaleIntensityImageFilterF2US2_New() -outputCast.SetInput(resampler.GetOutput()) -outputCast.SetOutputMinimum(0) -outputCast.SetOutputMaximum(65535) - -writer = itkImageFileWriterUS2_New() - -writer.SetFileName(argv[3]) -writer.SetInput(outputCast.GetOutput()) -writer.Update() diff --git a/Wrapping/Generators/Python/Tests/notYetUsable/VoronoiSegmentation.py b/Wrapping/Generators/Python/Tests/notYetUsable/VoronoiSegmentation.py deleted file mode 100644 index 4b8f655c9c9..00000000000 --- a/Wrapping/Generators/Python/Tests/notYetUsable/VoronoiSegmentation.py +++ /dev/null @@ -1,49 +0,0 @@ -#========================================================================== -# -# Copyright Insight Software Consortium -# -# 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. -# -#==========================================================================*/ - -# -# Example on the use of the VoronoiSegmentationImageFilter. -# - -from InsightToolkit import * - -from sys import argv - - -readerInput = itkImageFileReaderUC2_New() -readerPrior = itkImageFileReaderUC2_New() - -readerInput.SetFileName(argv[1]) -readerPrior.SetFileName(argv[2]) - -readerInput.Update() -readerPrior.Update() - -filter = itkVoronoiSegmentationImageFilterUC2UC2UC2_New() - -filter.SetInput(readerInput.GetOutput()) -filter.TakeAPrior(readerPrior.GetOutput()) - -filter.SetMeanPercentError(eval(argv[4])) -filter.SetSTDPercentError(eval(argv[5])) - -writer = itkImageFileWriterUC2_New() -writer.SetFileName(argv[3]) -writer.SetInput(filter.GetOutput()) - -writer.Update()