After the multi-step registration you should have a single composite transform in hand, comprised of the rigid, affine, displacement. Save it to a single file (sitk.WriteTransform). Do not use .tfm which is ASCII, readable for human but very slow IO for displacement field. Instead use a binary format, the extension .hdf. You won’t be able to look at the file with an editor but the format is much more appropriate for IO of displacement fields.
could you give some code example on how to read a saved transformation and apply it to different images?
The way I am doing is not working:
outTxFile = os.path.join(dataFold, 'saved_outTx.hdf')
outTx = sitk.ReadTransform(outTxFile)
fixed_image = sitk.Cast(sitk.GetImageFromArray(theFixedImageWhichGotOutTx), sitk.sitkFloat32)
moving_image = sitk.Cast(sitk.GetImageFromArray(newImageToApplyOutTx), sitk.sitkFloat32)
resampler = sitk.ResampleImageFilter()
resampler.SetInterpolator(sitk.Linear) # linear or NN, outTx was achieved by NN but
#moving image is not labeled segmentation.
out = resampler.Execute(moving_image)
displayImage(sitk.GetArrayFromImage(out), Title_='transformed ion image')
One thing is I didn’t create a composite transform as following:
One comment with respect to the SimpleITK API. When you need to perform a one time operation, we recommend using the procedural interface, it is more concise. When the operation is repeated multiple times use the object-oriented interface, so you create objects once and use them multiple times, potentially with different settings. The procedural interface creates new objects every time under the hood.
Resampling in this case becomes:
out = sitk.Resample(moving_image, fixed_image, outTx, sitk.Linear, 0)