SuperElastix / SimpleElastix

Multi-lingual medical image registration library
http://simpleelastix.github.io
Apache License 2.0
511 stars 149 forks source link

Is there a way to disable multi-resolution pyramid strategy? #472

Closed Vathsan closed 2 years ago

Vathsan commented 2 years ago

Is there a way to run the registration with bspline parameter map with NumberOfResolutions = 0? I was referring to https://simpleelastix.readthedocs.io/ParameterMaps.html#important-parameters and trying to avoid multiple resolutions since my problem is simple.

splineMap = sitk.GetDefaultParameterMap("bspline")
splineMap['NumberOfResolutions'] = ['0']

When I execute the logic, I get the following error. Is there a way to overcome this?

Description: itk::ERROR: Image(0x2585610): A spacing of 0 is not allowed: Spacing is [0, 0, 0]

Error occurred during actual registration.
NHPatterson commented 2 years ago

I think you can set NumberOfResolutions to 1 rather than zero. It will only use the highest resolution in this case. You'll also need to make sure the pyramidal schedule is ['1','1','1'] for 3D data or ['1','1'] for 2D. See the docs on pyramid schedule parameters: https://elastix.lumc.nl/doxygen/parameter.html

Vathsan commented 2 years ago

@NHPatterson, thanks for the prompt response.

I tried your suggestion earlier with the following set of configurations,

splineMap = sitk.GetDefaultParameterMap("bspline")
splineMap['NumberOfResolutions'] = ['1']
splineMap['GridSpacingSchedule'] = ['1.0', '1.0', '1.0']
splineMap['MaximumNumberOfIterations'] = ['100']

but for some reason I see artifacts in the registered image.

Screenshot from 2022-06-23 15-48-06

It proportionally increases with the number of iterations. My understanding is that, this is because of the multi resolution strategy. Please let me know your thoughts on this.

NHPatterson commented 2 years ago

This is not an effect of the multi-resolution strategy, this is the bspline registration overfitting.. hence why more iterations (more iterations to make it bad!) makes it appear "squiggly" for lack of a better word.

Two things:

splineMap['GridSpacingSchedule'] = ['1.0', '1.0', '1.0']

It's important that you understand this is in physical spacing of your image (i.e., in mm or whatever unit your image is defined in) because all registrations are carried out in physical space, not pixel space. If your image spacing is not set appropriately this is problematic or if it is defaulted to (1.0,1.0,1.0) as it would be if converted from np.ndarray, then this means the grid will essentially be on every pixel which, in my experience, causes registrations like the one above. The elastix manual suggests the grid spacing be set to the size of a visible structure in the image.

You can verify your image spacing using

my_image.GetSpacing()

You can set spacing using:

my_image.SetSpacing((20.0,20.0,20.0))

Once you are assured the spacing is correct for the image, grid spacing should probably be lowered. You still risk overfitting in any scenario but you can also lower iterations at this point.

Vathsan commented 2 years ago

Hi @NHPatterson , thanks for the the input. I was able to get rid of the squiggly lines in the results after increasing the gridSpacingSchedule.