Interpolate between two segmentations

Thanks for the pointer. I used Elastix to get the displacement values (and referred to this post and this post for additional tips). I also tried the SegmentRegistration module directly on the segmentations, but the Elastix output on cropped versions of the original images looks better.

I am able to apply the displacement vectors, but am getting stuck downstream. Here is my current workflow:

(a) I get the KJI coordinates of my segmented object from timestep1 (airway at expiration)
(b) I convert to IJK and then to RAS using the IJK-to-RAS matrix from timestep1’s labelVolmeNode
(c) I apply the deformation displacement to each voxel from its corresponding voxel in the displacement field
(d) I convert the transformed RAS coordinates to IJK using the RAS-to-IJK matrix from timestep2’s volume (airway at inspiration)
(e) I convert to KJI and write the matrix as an image (with some modification to handle Q1 below)

Q1: Some of the values I am getting from step (e) for the KJI coordinates are outside the boundary of timestep2’s image. Why would this be happening? When I convert from RAS to IJK using timestep1’s RAS-to-IJK matrix they are also outside the boundary (with some negative KJI indices).

Q2: I am following the code from the script page to convert from RAS to IJK, but the conversion to int causes my image to get chopped up between slices. I can recover the segmentation by filling holes, but is this expected?

I want to create intermediate instances of the deforming airway between the inspiratory and expiratory airway segmentation instances.

I hope that all makes sense. Thanks for your help, I really appreciate it.