Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up ImageFullSampler, ImageGridSampler, and ImageRandomSamplerSparseMask, using a local sampleVector variable #960

Merged
merged 8 commits into from
Sep 13, 2023

Conversation

N-Dekker
Copy link
Member

@N-Dekker N-Dekker commented Sep 8, 2023

Did speed up ImageFullSampler, ImageGridSampler, and ImageRandomSamplerSparseMask by doing the push_back's of samples to a local std::vector of samples (instead of directly to the sample container), and then eventually swapping the vector "into" the sample container.

When using ImageFullSampler on a 4096 x 4096 input image, a sampler.Update() call originally took more than 0.38 seconds, but it went down to almost 0.20 seconds with this commit, as observed using Visual C++ 2019 (Release configuration).

This pull request also includes various coding style improvements of the implementation of the samplers.

Avoided redundant `this->GetCroppedInputImageRegion()` calls.
Nicely declared those `iter` variables in the _init-statement_ of the corresponding `for` loops.

Note that the constructor of `itk::ImageRegionConstIteratorWithIndex' already places the iterator at the begin of the specified image region.
Prefer Standard C++ library functions to hand-made functions, if the functionality is basically the same.
For consistency between ImageGridSampler and ImageFullSampler.
Did speed up `ImageFullSampler`, `ImageGridSampler`, and `ImageRandomSamplerSparseMask` by doing the `push_back`'s of samples to a local `std::vector` of samples (instead of directly to the sample container), and then eventually swapping the vector "into" the sample container.

When using `ImageFullSampler` on a 4096 x 4096 input image, a `sampler.Update()` call originally took more than 0.38 seconds, but it went down to almost 0.20 seconds with this commit, as observed using Visual C++ 2019 (Release configuration).
@N-Dekker N-Dekker merged commit 4d028f7 into main Sep 13, 2023
@N-Dekker N-Dekker deleted the ImageSamplerRestyling branch September 13, 2023 18:26
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request Sep 15, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
N-Dekker added a commit to N-Dekker/ITKElastix that referenced this pull request Sep 18, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
dzenanz pushed a commit to InsightSoftwareConsortium/ITKElastix that referenced this pull request Sep 19, 2023
Supports passing a transform retrieved by `GetCombinationTransform()` or
`GetNthTransform(n)` to `ConvertToItkTransform`, when an _external_ initial
transform was specified before running the registration.

Also including various performance improvements.

Including:

  pull request SuperElastix/elastix#946
  commit SuperElastix/elastix@7bcb2b3
  ENH: Write external initial transforms to ITK transform file

  pull request SuperElastix/elastix#949
  commit SuperElastix/elastix@601f465
  ENH: `ConvertToItkTransform` should support external initial transform

  pull request SuperElastix/elastix#950
  commit SuperElastix/elastix@7e883bf
  ENH: Add GetInitialTransform() and GetExternalInitialTransform()

  pull request SuperElastix/elastix#959
  commit SuperElastix/elastix@3979978
  PERF: Speed up ComputeJacobianTerms access to `vnl_sparse_matrix`

  pull request SuperElastix/elastix#960
  commit SuperElastix/elastix@4d028f7
  PERF: Speed up full, grid, sparse mask samplers by a local sampleVector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant