Registration on CT and phantom

Hello itk community,
My goals is to create a code in simple itk to perform registration on an whole body phantom and on a CT of a patient (from head to chest)
CT: 1x1x3.3mm^3
phantom: 1x1x5mm^3

At first, I write a code de register 2 phantoms to see if my code works well, and it did.
But when I put patient’s CT, it did not register the two image.
Can you give me some advice or tell me how to do it, cause I haven’t found any article about that topic…
The code is the following.

A = “E:/phantom/11F06DD_Y5_M6_P50_”
series_IDs = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory)
if not series_IDs:
print("ERROR: Pas de DICOM dans ce dossier “” + data_directory)
series_file_names = sitk.ReadImage(A)
B = “E:/CT/11F06DD_Y6_M0_P99_”
series_IDs2 = sitk.ImageSeriesReader.GetGDCMSeriesIDs(data_directory2)
if not series_IDs2:
print("ERROR: Pas de DICOM dans ce dossier “” + data_directory2)
series_file_names2 = sitk.ReadImage(B)

def command_iteration(method, bspline_transform):
if method.GetOptimizerIteration() == 0:
print("{0:3} = {1:10.5f}".format(method.GetOptimizerIteration(), method.GetMetricValue()))

def command_multi_iteration(method):
if R.GetCurrentLevel() > 0:
print(“Optimizer stop condition: {0}”.format(R.GetOptimizerStopConditionDescription()))
print(" Iteration: {0}".format(R.GetOptimizerIteration()))
print(" Metric value: {0}".format(R.GetMetricValue()))

fixed = sitk.ReadImage(A, sitk.sitkFloat32)
moving = sitk.ReadImage(B, sitk.sitkFloat32)
grid_physical_spacing = [50.0, 50.0, 50.0]
image_physical_size = [size * spacing for size, spacing in zip(fixed.GetSize(), fixed.GetSpacing())]
mesh_size = [int(image_size / grid_spacing + 0.5) \ for image_size, grid_spacing in zip(image_physical_size, grid_physical_spacing)]
tx = sitk.BSplineTransformInitializer(fixed, mesh_size)

R = sitk.ImageRegistrationMethod()
R.SetOptimizerAsLBFGSB(gradientConvergenceTolerance=1e-5, numberOfIterations=100)
R.AddCommand(sitk.sitkIterationEvent, lambda: command_iteration(R, tx))
R.AddCommand(sitk.sitkMultiResolutionIterationEvent, lambda: command_multi_iteration®)
R_finale = R.Execute(fixed, moving)
sitk.WriteTransform(R_finale, ‘W:/MOEEZ2020/DICOMresultats/resultats.txt’)

if ( not “SITK_NOSHOW” in os.environ ):

resampler = sitk.ResampleImageFilter()
out = resampler.Execute(moving)

simg1 = sitk.Cast(sitk.RescaleIntensity(fixed), sitk.sitkUInt8)
simg2 = sitk.Cast(sitk.RescaleIntensity(out), sitk.sitkUInt8)
cimg = sitk.Compose(simg1, simg2, simg1//2.+simg2//2.)
sitk.Show(cimg, "Image Registration Composition")

Hello @moeez,

Welcome to the wonderful world of registration!

In order for us to help you “debug” your registration we need more details. Let us start with the initialization. Are the two images reasonably aligned? Not rotated by 180 degrees, and good overlap between corresponding regions?

If yes, then how does the similarity metric change during the registration. Looking at that graph often helps identify if the registration is going in the right direction.

Please take a look at the registration notebooks (6* series). Once you go over these you will have a better understanding of how to “debug” a failing registration.


Dear @zivy

I think indeed the 2 images are may not reasonably aligned… they are not rotated but there is not a good overlap between corresponding regions. I think that so, but I am not sure

The metric I use is SetMetricAsCorrelation

Hello @moeez,
The question was not which similarity metric you were using (saw it in the code), but how was it behaving. You need to see that the optimizer is working successfully (not bouncing around, overshooting…). Please go through the notebooks and you’ll get a good understanding of how to monitor this.

1 Like