-
Notifications
You must be signed in to change notification settings - Fork 118
Memory consumption in transformix
Sometimes you want to work on memory constrained systems, even with (medical) imaging data that is quire large.
This page gives an overview of the memory consumption of transformix
, and some tips on how to reduce it. Much of it also holds for elastix
.
For resampling an image several components need memory:
-
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 theTransformParameters
file. - The interpolator. The BSplineInterpolateImageFunction precomputes some coefficients, which are stored in a double image the size of the moving image.
-
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 theResultImagePixelType
in theTransformParameters
file. If this is different from theInternalImagePixelType
, 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 by:
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
-
The B-spline interpolator is the main consumer, because it uses an internal coefficients image of type double. You can instead select
(Interpolator "BSplineInterpolatorFloat")
, which stores this internal image in float format. This would reduce memory consumption by 512 MB for the example. -
If you were to use the
LinearInterpolator
orNearestNeighborInterpolator
the internal image is completely omitted. This would reduce memory consumption by 1 GB for the example. Note however that linear or nearest neighbor interpolation will degrade the results a little, compared to cubic B-spline interpolation. -
Change the
InternalImagePixelType
from float to short. This saves you 3 times a short image, i.e. 0.75 GB for the example. This will also result in a little degradation.