Skip to content

Commit

Permalink
ENH: Test PathList interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Sep 30, 2024
1 parent 5627df0 commit 3f45090
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
23 changes: 23 additions & 0 deletions wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,26 @@ itk_python_add_test(NAME PythonANTsGroupwiseBrainSlices
-i DATA{${test_input_dir}/OASIS-TRT-20-19Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-20Slice121.nii.gz}
)

itk_python_add_test(NAME PythonANTsGroupwisePaths
TEST_DRIVER_ARGS
--compare
DATA{${test_baseline_dir}/PythonANTsGroupwiseBrainSlices.nrrd}
${ITK_TEST_OUTPUT_DIR}/PythonANTsGroupwisePaths.nrrd
--compareIntensityTolerance 10
--compareRadiusTolerance 5
--compareNumberOfPixelsTolerance 2000
COMMAND PythonANTsGroupwisePaths.py
-o ${ITK_TEST_OUTPUT_DIR}/PythonANTsGroupwisePaths.nrrd
-i DATA{${test_input_dir}/OASIS-TRT-20-10Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-11Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-12Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-13Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-14Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-15Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-16Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-17Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-18Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-19Slice121.nii.gz}
-i DATA{${test_input_dir}/OASIS-TRT-20-20Slice121.nii.gz}
)
66 changes: 66 additions & 0 deletions wrapping/test/PythonANTsGroupwisePaths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#==========================================================================
#
# 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
#
# https://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
import argparse

parser = argparse.ArgumentParser(description="Python groupwise registration test.")
parser.add_argument("-i", "--input-image", action="append", help="Input image(s)", required=True)
parser.add_argument("-t", "--initial-template", required=False)
parser.add_argument("-o", "--output-template", required=True)
args = parser.parse_args()

itk.auto_progress(2)

first_image = itk.imread(args.input_image[0])

PixelType = itk.template(first_image)[1][0]
Dimension = first_image.GetImageDimension()
ImageType = itk.Image[PixelType, Dimension]
assert ImageType == type(first_image)
TemplateImageType = itk.Image[itk.F, Dimension]

gwr = itk.ANTSGroupwiseRegistration[ImageType, TemplateImageType, itk.F].New()
# pairwise registration has different order of template parameters
pwr = itk.ANTSRegistration[TemplateImageType, ImageType, itk.F].New()

if args.initial_template is not None:
print(f"Reading initial template: {args.initial_template}")
initial_template = itk.imread(args.initial_template)
gwr.SetInitialTemplateImage(initial_template)

gwr.SetPathList(args.input_image)
gwr.SetIterations(4)
gwr.SetGradientStep(0.2)

pwr.SetTypeOfTransform("SyN")
pwr.SetSynMetric("CC")
pwr.SetSynIterations([100, 70, 50, 0])
pwr.SetRandomSeed(30101983) # improve reproducibility

gwr.SetPairwiseRegistration(pwr)
print(gwr)

print("Performing groupwise registration. This will take a while...")
gwr.Update()

print(f"Writing resulting template image into file: {args.output_template}")
itk.imwrite(gwr.GetOutput(), args.output_template, compression=False)

print("Test finished")

0 comments on commit 3f45090

Please sign in to comment.