Adjusting demons algorism parameters

Hello guys,

Our lab is using the Demons algorithm through SimpleITK to register some microscopy images to a template. Right now the alignment take up up to 130 gigs of ram for 2 gig images and is rather slow. Also alignment results do not seem to improve beyond registering at the lowest resolution down sampling by a factor of four.

I am wondering if you have any intuition on how to adjust the parameter of the algorithm to achieve the results below:
1. reduce RAM usage.
2. decrease computation time.   
3. increase alignment accuracy.

Thanks a lot!

Hello @madwilliam,

Welcome to SimpleITK!

Not sure all of that is achievable, but here goes:

  1. You are using a multiscale approach? Sounds like it, but not sure. Multiscale helps with dealing with large deformations and often speeds things along. See this jupyter notebook for sample code. To reduce the memory footprint that code uses a function generator, so the whole pyramid is never in memory (implementation “trick”).
  2. Demons specific settings - select elastic (SmoothDisplacementFieldOn smaller deformations ) or viscous (SmoothUpdateFieldOn larger deformations).
  3. As registration is highly dependent on a good initialization, this may be an issue too, not sure how far are corresponding points in your data. Possibly have an initial global registration step prior to the demons?

The following microscopy registration code/data may be of interest:

  1. registration approach
  2. frontend for registration approach + bunch of other stuff
  3. dataset 1, dataset 2
1 Like

Hello @zivy

Thank you for pointing me to theses intriguing directions!

Yes we are using multi-scale but we are using the built-in function. Do you know if it has the memory trick as well?

The elastic and viscous settings are very useful to know.

right now we are using a simple translation to align the center of the two images. Other approaches might be helpful. The samples we have have relatively few deformations and the variation largely comes from sample to sample variations. I would say from looking at them they look pretty modest to me.

Another issue we are facing right now is that the transformation save files seems to be pretty big: much larger than the image itself. I am wondering if optimization parameters are included in the save file produced by write_transform and if so is there a way to extract the displacement field.

Really appreciate your insight and expertise!

Hello @madwilliam,

I don’t know if the ImageRegistrationMethod's DemonsMetric is using any memory efficient approach (the framework is very different from the standalone Demons filters).

With respect to file size of a DisplacementFieldTransform, this depends on the file format. The only data saved is the displacement field itself. A 3D displacement field uses 3*sizeof(float64) bytes per voxel, so it will be at least three times the size of your original image. When saving to disk do not use a text based format. For fast reading/writing and for minimal disk space use a binary format, for example hdf5:

sitk.WriteTransform(displacement_field_transform, "displacement.hdf")