SuperElastix / SimpleElastix

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

Register a 2D slice to a 3D volume #331

Open pollackscience opened 4 years ago

pollackscience commented 4 years ago

I'm trying to take a single 2D image and compare it to a 3D volume. The goal is to identify the slice of the 3D volume that best matches the 2D slice. Would this be possible using SimpleElastix? I've used it extensively for both 2D and 3D registration, but not for mixing dimensions like this case.

Thanks!

pollackscience commented 4 years ago

So for now, I'm attempting something like this:

Generate 0'd out padding slices (or whatever init value I want):

pad = np.full((256, 256), 0, np.int16)
pad = sitk.GetImageFromArray(pad)

Combine padding and the 2D slice to make a 3D volume:

moving_3d = sitk.JoinSeries([pad]*52 + [moving_2d] + [pad]*33)

Then I copy over the info from the fixed image and start registering. This works ok... but it helps if I add lopsided padding (like in the example, 52 empty slices in the front, 33 in the back) since the ideal location is not centered. Trying to plot the output was a hassle as well, partially due to the explicit change from dtype int16 to dtype float32 after the registration is executed. This also works in cases where I have very different volume sizes (fixed: 512x512x88, moving 256x256x4). In that case, I do something like:

moving_3d = sitk.JoinSeries([pad]*50 + [moving1] + [pad]*4 + [moving2] + [pad]*4 + [moving3] + [pad]*4 + [moving4] + [pad]*30)

I'm using either affine or rigid, since i don't really care if the slices match exactly, but I need to be able to align these moving slices with the fixed volume.

Still, this works ok only if I tweak the number of pads to give the registration a better initialization. If there is a less janky way to do this, feel free to chime in!

alexeytopolnitskiy commented 3 years ago

Hi @pollackscience ! Did you find the proper way to implement 2D slice to 3D registration. I have the same task and I am still seeking for a solution?

pollackscience commented 3 years ago

This is still my current setup, more or less. I have additional phases in which after I do this 2D to 3D reg, I extract the index of the 3D slice that best matches my 2D input. From there, I perform a 2D-2D registration to further refine the agreement. Full support for this type of problem would be much appreciated.