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)
sys.exit(1)
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)
sys.exit(1)
series_file_names2 = sitk.ReadImage(B)
def command_iteration(method, bspline_transform):
if method.GetOptimizerIteration() == 0:
print(bspline_transform)
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.SetMetricAsCorrelation()
R.SetOptimizerAsLBFGSB(gradientConvergenceTolerance=1e-5, numberOfIterations=100)
R.SetInterpolator(sitk.sitkLinear)
R.SetMetricSamplingStrategy(R.RANDOM)
R.SetMetricSamplingPercentage(0.01)
R.SetInitialTransform(tx)
R.SetShrinkFactorsPerLevel([4,2,1])
R.SetSmoothingSigmasPerLevel([2,1,0])
R.AddCommand(sitk.sitkIterationEvent, lambda: command_iteration(R, tx))
R.AddCommand(sitk.sitkMultiResolutionIterationEvent, lambda: command_multi_iteration(R))
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()
resampler.SetReferenceImage(fixed);
resampler.SetInterpolator(sitk.sitkLinear)
resampler.SetDefaultPixelValue(100)
resampler.SetTransform(R_finale)
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")