I am trying to apply several transforms to an image, i.e. align a set of 2d image to the same space, when I apply the transforms it doesn’t appear to work even though the figures I generate before this operation appear to register correctly between the fixed and moving image.
basically I iterate through multiple pairs of images where the key value pair here is the (i, k), i is the fixed image and k is the moving image, and the value is the registration metric, following the approach implemented in poSSUm, creating a weighted directed graph.
then I need to compose the transformations between a reference image (I am using the first image for now, so 0) and the moving image (j). I use the shortest path between the reference index and the jth imag to get a reversed list of transforms to create a composite transform. however when done, this does not actually create a registered image as would have expected.
I tried using flatten transform, as I noticed that at earlier steps that after the initial k to i registration generates composite, transform and multi-transform information, but it appears either way, only the last transform from the composite is applied, but I am not 100% sure about that.
Its possible I messing up the directed graph, or don’t fully understand the composite transform.
I did see some comments about how the transform generated by the registration doesn’t include the initialization transform… but that seems confusing as when create resampled images comparing i to k the registration looks fine, but the composite doesn’t appear to work.
I need to update this snippet with the latest changes
for j in range(n_rows):
# j is the moving image
trans_list = _calculate_composite(G, reference_index, j)
# Instanciate composite transform which will handle all the partial
# transformations.
composite_transform = sitk.Transform(2, sitk.sitkEuler)
# Fill the composite transformation with the partial transformations:
for transform in trans_list:
composite_transform.AddTransform(transform)
reg_key = (reference_index, j)
if (reg_key in reg_n.keys()):
f_sitk, t_sitk = read_tiff_image(reg_n[reg_key], page_index=4)
new_image = resample_rgb(composite_transform,
f_sitk,
t_sitk,
mean=get_mean_edges(t_sitk)
)
resample_image = os.path.join(top_dir, resample_dir, "resample_affine_{0}.png".format(j))
writer = sitk.ImageFileWriter()
writer.SetFileName(resample_image)
writer.Execute(new_image)