Memory consumption transformix

From elastix
Jump to: navigation, search

The typical size of clinical images increases as a function of time. Therefore, memory efficiency will become more of an issue. transformix is by default not very efficient with resources.

Default memory consumption of transformix

For resampling an image several components need memory:

  1. The moving image, i.e. the image that is to be deformed. This is stored with an InternalImagePixelType, which can be set by the user in the TransformParameter file.
  2. The interpolator. The BSplineInterpolateImageFunction precomputes some coefficients, which are stored in a double image the size of the moving image.
  3. The resampled image itself, usually of the size of the fixed image. This is again stored with an InternalImagePixelType. To get a user-defined pixel type one can set the ResultImagePixelType. If this is different from the InternalImagePixelType a cast is performed between the types, consuming another piece of memory.

For example: Say we have a 512^3 short image as input, which is resampled to a 512^3 short image. So both images are 512^3 x 2 byte = 256 MB. Then the memory consumption is given:

what how much Setting 1 Setting 2 Setting 3 Setting 4
internal = short,
interpolator 1
internal = float,
interpolator 1
internal = short,
interpolator 2
internal = short,
interpolator 3
moving image 1 x moving size x internal 256 MB 512 MB 256 MB 256 MB
interpolator 1 1 x moving size x double 1024 MB 1024 MB
interpolator 2 1 x moving size x float 512 MB
interpolator 3 0 0 MB
resampled image 1 x fixed image x internal 256 MB 512 MB 256 MB 256 MB
output image 1 x fixed image x output type 0* MB 256 MB 0* MB 0* MB
total 1.5 GB 2.25 GB 1.0 GB 0.5 GB

* If the resampled image and the output image are of the same type no casting is performed
interpolator 1 = B-spline interpolator with a double coefficient image internally
interpolator 2 = B-spline interpolator with a float coefficient image internally
interpolator 3 = A nearest neighbour or linear interpolator, which uses no internal coefficient image

Improvements

  • Priority: a value in {1,2,3,4} ~ {high, medium, low, not going to do}.
  • Status: a value from 0-100%, where 100% means that the feature has been implemented and well documented.
Item Description Priority Status Comment
1 The B-spline interpolator is the main consumer. In transformix we have hard-coded it to use doubles. We could add a float version, then consumption would go down by 512 MB for the example. 1 100% Added and documented
2 Add other interpolators, not based on B-splines, such as a "LinearInterpolator" and a "NearestNeighborInterpolator". These do not need to decompose the image into B-spline-coefficients and, thus, memory consumption would go down by 1GB for the example. 1 100% Both are added and documented.
3 As soon as the interpolator has calculated some internal stuff, we could in principle remove the moving image. For the example that would save us 256 or 512 MB for the major part of the runtime. 2 This might be a bit harder to implement. Note: the moving image only has to be removed for transformix, not for elastix
4 Instead of resampling to the internal type, we could immediately resample to the desired output type. This would save 256 MB for the example. 4 This is too much work for a little gain

With item 2 implemented, the total memory use can be as small as 2 times the size of the input image in shorts (with linear interpolation, a short internal pixel type, and a short result image output pixel type). Note that linear interpolation degrades the results a little, compared to cubic B-spline interpolation.

What you can do to save memory?

  1. Change the InternalImagePixelType from float to short. This saves you 3 times a short image, i.e. 0.75 GB in the example.
  2. Change the interpolator type. Going from the double B-spline interpolator to the float version saves you 512 MB for the example. The linear or nearest neighbour interpolators saves you another 512 MB, so 1 GB in total.
Personal tools