After inspecting in detail the combine_slices code, I found some optimization possibilities:
_sort_by_slice_position is called twice:
First in the voxels (_merge_slice_pixel_arrays),
Second in the affine (_ijk_to_patient_xyz_transform_matrix).
Obviously, it can be done once in the outer combine_slices function.
_slice_positions is called 4 times:
_validate_slices_form_uniform_grid - 1 time
_slice_spacing - 1 time
_sort_by_slice_position - 1 time, but _sort_by_slice_position is called twice --> 2 times
_extract_cosines is called 6 times:
_validate_image_orientation - 1 time
_ijk_to_patient_xyz_transform_matrix - 1 time
_slice_positions - 1 time, but _slice_positions is called 4 times --> 4 times
All these calls better be done once (and can be).
However,
- this may incorporate substantial redesign of the code,
- it will change the functionality of
_merge_slice_pixel_arrays and _ijk_to_patient_xyz_transform_matrix, which should not be used alone, but there are some special tests for _merge_slice_pixel_arrays.
Originally posted by @jond01 in #16 (comment)
After inspecting in detail the
combine_slicescode, I found some optimization possibilities:_sort_by_slice_positionis called twice:First in the voxels (
_merge_slice_pixel_arrays),Second in the affine (
_ijk_to_patient_xyz_transform_matrix).Obviously, it can be done once in the outer
combine_slicesfunction._slice_positionsis called 4 times:_validate_slices_form_uniform_grid- 1 time_slice_spacing- 1 time_sort_by_slice_position- 1 time, but_sort_by_slice_positionis called twice --> 2 times_extract_cosinesis called 6 times:_validate_image_orientation- 1 time_ijk_to_patient_xyz_transform_matrix- 1 time_slice_positions- 1 time, but_slice_positionsis called 4 times --> 4 timesAll these calls better be done once (and can be).
However,
_merge_slice_pixel_arraysand_ijk_to_patient_xyz_transform_matrix, which should not be used alone, but there are some special tests for_merge_slice_pixel_arrays.Originally posted by @jond01 in #16 (comment)