Skip to content

Commit

Permalink
ENH: Add Python tests for PhasedArray3DSpecialCoordinatesImage
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Jul 4, 2023
1 parent ce02933 commit 43179d3
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8fc8129454b6ec93fb5c133d9835f8a49df0ab14584d44b3454e1b36dee60ef92e29bb9e8c3b9a1340129877fc0ec81d7beb5022eaf3bcbbed8fa3ebab8e6c74
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cf4bac01a2692100f1c2b2445f3468b26c754e380f4d0119b466c079639f309ad18f775106f341a72c6126a7a636d55c494ed40edf441de262418ff65b2a792e
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6e589887b660f79513d1c09479cc70bd815e532e013fcb3bb185a21c641e417210d6a8286199a265b8e6b9159254e6237108539d0c5eb865a7bedb03d64cbf50
1 change: 1 addition & 0 deletions test/Input/ScanConvertPhasedArray3DTestInput.mha.sha512
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7d5e6c2b070107a279277c48ead400bab15edd7aaa1b1b2238a8437da1435c41f75c3b2323fdba17f6415d10ea37992ff053f52a5f6d7a0937f78cfaf1f3687a
54 changes: 53 additions & 1 deletion wrapping/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ itk_python_add_test(NAME PythonCurvilinearArraySpecialCoordinatesImageTemplateMe
COMMAND PythonCurvilinearArraySpecialCoordinatesImageTemplateMethodsTest.py
)

itk_python_expression_add_test(NAME PythonInstantiateGaussianInterpolateImageFunction
itk_python_expression_add_test(NAME PythonInstantiateGaussianInterpolateImageFunctionCASCI
EXPRESSION "iFunc = itk.GaussianInterpolateImageFunction[itk.CurvilinearArraySpecialCoordinatesImage[itk.UC, 2], itk.D].New()"
)

Expand All @@ -58,6 +58,58 @@ itk_python_add_test(NAME PythonCurvilinearResampleTest
--first-sample-distance 26.4
)

itk_python_expression_add_test(NAME PythonInstantiateGaussianInterpolateImageFunctionPA3DSCI
EXPRESSION "iFunc = itk.GaussianInterpolateImageFunction[itk.PhasedArray3DSpecialCoordinatesImage[itk.F], itk.D].New()"
)

itk_python_add_test(NAME PythonPhasedArray3DResampleNearestTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{${test_baseline_dir}/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha
COMMAND PythonPhasedArray3DResample.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKNearestNeighborTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
--interpolation-type nearest
)

itk_python_add_test(NAME PythonPhasedArray3DResampleLinearTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{${test_baseline_dir}/ScanConvertPhasedArray3DTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DTestOutput.mha
COMMAND PythonPhasedArray3DResample.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
# --interpolation-type linear # linear is the default
)

itk_python_add_test(NAME PythonPhasedArray3DResampleSincTest
TEST_DRIVER_ARGS
--compareIntensityTolerance 1
--compare
DATA{${test_baseline_dir}/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha}
${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha
COMMAND PythonPhasedArray3DResample.py
-i DATA{${test_input_dir}/ScanConvertPhasedArray3DTestInput.mha}
-o ${ITK_TEST_OUTPUT_DIR}/ScanConvertPhasedArray3DITKWindowedSincTestOutput.mha
--azimuth-angular-separation 0.0872665
--elevation-angular-separation 0.0174533
--radius-sample-size 0.2
--first-sample-distance 8.0
--interpolation-type sinc
)

itk_python_add_test(NAME PythonBackscatterImageFilterTest0
TEST_DRIVER_ARGS
--compareIntensityTolerance 0.01
Expand Down
75 changes: 75 additions & 0 deletions wrapping/test/PythonPhasedArray3DResample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#==========================================================================
#
# 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 math
import argparse

import itk

parser = argparse.ArgumentParser(description="Estimate three back-scatter coefficients.")
parser.add_argument("-i", "--input-image", required=True)
parser.add_argument("-o", "--output-image", required=True)
parser.add_argument("-a", "--azimuth-angular-separation", type=float, required=True)
parser.add_argument("-e", "--elevation-angular-separation", type=float, required=True)
parser.add_argument("-r", "--radius-sample-size", type=float, required=True)
parser.add_argument("-f", "--first-sample-distance", type=float, required=True)
parser.add_argument("-t", "--interpolation-type", choices=["nearest", "linear", "sinc"], default="linear")
args = parser.parse_args()

itk.auto_progress(2)

pixel_type = itk.UC
dimension = 3
image_type = itk.PhasedArray3DSpecialCoordinatesImage[pixel_type]
reader = itk.ImageFileReader[image_type].New()
reader.SetFileName(args.input_image)
reader.Update()
image = reader.GetOutput()
image.DisconnectPipeline()

image.SetAzimuthAngularSeparation(args.azimuth_angular_separation)
image.SetElevationAngularSeparation(args.elevation_angular_separation)
image.SetFirstSampleDistance(args.first_sample_distance)
image.SetRadiusSampleSize(args.radius_sample_size)
print(image)

print("Verify resampling works with PhasedArray3DSpecialCoordinatesImage input")
output_size = [128] * dimension
output_spacing = [0.2] * dimension
origin0 = -1 * output_spacing[0] * output_size[0] / 2.0
origin1 = -1 * output_spacing[1] * output_size[1] / 2.0
origin2 = 0.0;
output_origin = [origin0, origin1, origin2]

if args.interpolation_type == "nearest":
interpolator = itk.NearestNeighborInterpolateImageFunction.New(image)
elif args.interpolation_type == "linear":
interpolator = itk.LinearInterpolateImageFunction.New(image)
elif args.interpolation_type == "sinc":
window_type = itk.LanczosWindowFunction[dimension]
interpolator = itk.WindowedSincInterpolateImageFunction[type(image), dimension, window_type].New()

result = itk.resample_image_filter(
image,
size=output_size,
output_spacing=output_spacing,
output_origin=output_origin,
interpolator=interpolator,
)
itk.imwrite(result, args.output_image, compression=True)
print(f"Result image written to: {args.output_image}")

0 comments on commit 43179d3

Please sign in to comment.