Skip to content

Commit 09e4aae

Browse files
authored
Merge pull request #56 from dpshamonin/master
ENH: added benchmark for ITK ResampleImageFilter
2 parents 651f17c + dab6e8f commit 09e4aae

File tree

2 files changed

+1451
-1
lines changed

2 files changed

+1451
-1
lines changed

examples/Filtering/CMakeLists.txt

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,113 @@ ExternalData_Add_Test(ITKBenchmarksData
9090
)
9191
set_property(TEST MinMaxCurvatureFlowBenchmark APPEND PROPERTY LABELS Filtering)
9292

93-
## performance tests should not be run in parallel
93+
add_executable(ResampleBenchmark ResampleBenchmark.cxx)
94+
target_link_libraries(ResampleBenchmark ${ITK_LIBRARIES})
95+
96+
macro(add_resample_benchmark interpolator extrapolator transforms use_composite_transform)
97+
# Extra parameters variable
98+
set(extra_parameters "")
99+
100+
# ITK does not support the 1D Euler or Similarity transforms.
101+
# Check if transforms has Euler or Similarity, then skip the benchmark for 1D image.
102+
set(transforms_contains_euler_or_similarity FALSE)
103+
foreach(transform ${transforms})
104+
if(${transform} STREQUAL "Euler" OR ${transform} STREQUAL "Similarity")
105+
set(transforms_contains_euler_or_similarity TRUE)
106+
break()
107+
endif()
108+
endforeach()
109+
110+
# Check if use_composite_transform is enabled
111+
if(${use_composite_transform})
112+
set(extra_parameters ${extra_parameters} "-c")
113+
set(composite_name Composite)
114+
endif()
115+
116+
# Check if extrapolator required by the benchmark
117+
if(NOT ${extrapolator} STREQUAL "None")
118+
set(extra_parameters ${extra_parameters} "-e" ${extrapolator})
119+
endif()
120+
121+
# Construct the benchmark configuration name
122+
set(benchmark_config_name "${interpolator}_${extrapolator}_${composite_name}")
123+
124+
foreach(transform ${transforms})
125+
set(benchmark_config_name ${benchmark_config_name}${transform})
126+
endforeach()
127+
128+
# List of images sizes for Resample benchmarking
129+
set(benchmark_image_sizes "8192;4096 4096;512 512 256")
130+
131+
foreach(benchmark_image_size ${benchmark_image_sizes})
132+
string(REPLACE " " "x" benchmark_image_size_name ${benchmark_image_size})
133+
string(REPLACE " " ";" benchmark_image_size_list ${benchmark_image_size})
134+
135+
# Check if input image is 1D and transforms contains Euler or Similarity
136+
set(skip_benchmark FALSE)
137+
if(${benchmark_image_size} EQUAL "8192" AND ${transforms_contains_euler_or_similarity})
138+
set(skip_benchmark TRUE)
139+
endif()
140+
141+
# Construct the benchmark name
142+
set(benchmark_command "ResampleBenchmark")
143+
set(benchmark_name "${benchmark_command}_${benchmark_config_name}_${benchmark_image_size_name}")
144+
145+
# Add the benchmark
146+
if(NOT ${skip_benchmark})
147+
add_test(
148+
NAME ${benchmark_name}
149+
COMMAND ${benchmark_command}
150+
-tf ${BENCHMARK_RESULTS_OUTPUT_DIR}/__DATESTAMP__${benchmark_name}.json
151+
-is ${benchmark_image_size_list}
152+
-i ${interpolator}
153+
-t ${transforms}
154+
-out ${TEST_OUTPUT_DIR}/${benchmark_name}.mha
155+
-iterations 1
156+
${extra_parameters}
157+
)
158+
159+
# Set the benchmark properties
160+
set_property(TEST ${benchmark_name} APPEND PROPERTY LABELS Filtering)
161+
set_tests_properties(${benchmark_name} PROPERTIES RUN_SERIAL true)
162+
endif()
163+
endforeach()
164+
endmacro()
165+
166+
# Resample with Affine transform
167+
add_resample_benchmark(Nearest None Affine FALSE)
168+
add_resample_benchmark(Linear None Affine FALSE)
169+
add_resample_benchmark(BSpline None Affine FALSE)
170+
171+
# Resample with BSpline transform
172+
add_resample_benchmark(Nearest None BSpline FALSE)
173+
add_resample_benchmark(Linear None BSpline FALSE)
174+
add_resample_benchmark(BSpline None BSpline FALSE)
175+
176+
# Resample with Affine transform in composite transform
177+
add_resample_benchmark(Nearest None Affine TRUE)
178+
add_resample_benchmark(Linear None Affine TRUE)
179+
add_resample_benchmark(BSpline None Affine TRUE)
180+
181+
# Resample with BSpline transform in composite transform
182+
add_resample_benchmark(Nearest None BSpline TRUE)
183+
add_resample_benchmark(Linear None BSpline TRUE)
184+
add_resample_benchmark(BSpline None BSpline TRUE)
185+
186+
# Resample with multiple transforms Affine and BSpline
187+
add_resample_benchmark(Nearest None "Affine;BSpline" TRUE)
188+
add_resample_benchmark(Linear None "Affine;BSpline" TRUE)
189+
add_resample_benchmark(BSpline None "Affine;BSpline" TRUE)
190+
191+
# Resample with all transforms and extrapolator
192+
add_resample_benchmark(Nearest Nearest "Translation;Affine;BSpline;Euler;Similarity" TRUE)
193+
add_resample_benchmark(Linear Nearest "Translation;Affine;BSpline;Euler;Similarity" TRUE)
194+
add_resample_benchmark(BSpline Nearest "Translation;Affine;BSpline;Euler;Similarity" TRUE)
195+
196+
# Resample with multiple BSplines and extrapolator
197+
add_resample_benchmark(Nearest Nearest "Translation;Affine;BSpline;BSpline;BSpline" TRUE)
198+
add_resample_benchmark(Linear Nearest "Translation;Affine;BSpline;BSpline;BSpline" TRUE)
199+
add_resample_benchmark(BSpline Nearest "Translation;Affine;BSpline;BSpline;BSpline" TRUE)
200+
201+
# performance tests should not be run in parallel
94202
set_tests_properties(MedianBenchmark BinaryAddBenchmark UnaryAddBenchmark GradientMagnitudeBenchmark MinMaxCurvatureFlowBenchmark PROPERTIES RUN_SERIAL TRUE)

0 commit comments

Comments
 (0)