changing origin bspline registration

hi,
i’m trying to change the domain origin of a bspline registration, but it seems to have no effect. this is part of the code:

def bspline_registration(fixed_image, moving_image, out_path, params):
    """
    bspline deformable registration
    :param fixed_image: sitk.Image fixe image
    :param moving_image: sitk.Image moving image
    :param out_path: path to save transformation
    :param params: parameters dictionary
    :return: transformation
    """
    registration_method = sitk.ImageRegistrationMethod()

    # Determine the number of BSpline control points using the physical
    # spacing we want for the finest resolution control grid.
    grid_physical_spacing = [50.0, 50.0, 50.0] # A control point every 5mm
    image_physical_size = [size*spacing for size,spacing in zip(fixed_image.GetSize(), fixed_image.GetSpacing())]
    mesh_size = [int(image_size/grid_spacing + 0.5) \
                 for image_size,grid_spacing in zip(image_physical_size,grid_physical_spacing)]
    # The starting mesh size will be 1/4 of the original, it will be refined by
    # the multi-resolution framework.
    mesh_size = [int(sz/4 + 0.5) for sz in mesh_size]

    initial_transform = sitk.BSplineTransformInitializer(image1=fixed_image,
                                                         transformDomainMeshSize=mesh_size, order=3)
    initial_transform.SetTransformDomainOrigin([-273, -208.2, 834.32])
    print(initial_transform.GetTransformDomainOrigin())
    # Instead of the standard SetInitialTransform we use the BSpline specific method which also
    # accepts the scaleFactors parameter to refine the BSpline mesh. In this case we start with
    # the given mesh_size at the highest pyramid level then we double it in the next lower level and
    # in the full resolution image we use a mesh that is four times the original size.
    registration_method.SetInitialTransformAsBSpline(initial_transform,
                                                     inPlace=False,
                                                     scaleFactors=[1,2,4])

    # registration_method.SetMetricAsMattesMutualInformation(numberOfHistogramBins=50)
    registration_method = set_metric_and_optimizer(registration_method, params)
    registration_method.SetInterpolator(sitk.sitkBSpline)

    registration_method.SetMetricSamplingStrategy(registration_method.RANDOM)
    registration_method.SetShrinkFactorsPerLevel(shrinkFactors=[4, 2, 1])
    registration_method.SetSmoothingSigmasPerLevel(smoothingSigmas=[2, 1, 0])
    registration_method.SmoothingSigmasAreSpecifiedInPhysicalUnitsOn()

    registration_method.AddCommand(sitk.sitkIterationEvent, lambda: command_iteration(registration_method))
    plot_metric(registration_method)

    final_transformation = registration_method.Execute(fixed_image, moving_image)
    exceute_metric_plot(registration_method, out_path, "Bspline")
    print('\nOptimizer\'s stopping condition, {0}'.format(registration_method.GetOptimizerStopConditionDescription()))
    return final_transformation

after registration i get the following information:
CoefficientImage: [ 0000023DCF5C20D0, 0000023DD1D925C0, 0000023DD1D952C0 ]
TransformDomainOrigin: [-273, -208.2, 587.32]
TransformDomainPhysicalDimensions: [499.023, 499.023, 252]
TransformDomainDirection: 1 0 0
0 1 0
0 0 1

 TransformDomainMeshSize: [12, 12, 4]
 GridSize: [15, 15, 7]
 GridOrigin: [-314.585, -249.785, 524.32]
 GridSpacing: [41.5853, 41.5853, 63]
 GridDirection: 1 0 0

0 1 0
0 0 1

what am i doing wrong?

thanks

ok I understood. The Image itself needs to be changed (SetOrigin())

1 Like