# Interpolate between two segmentations

**URL:** <https://discourse.slicer.org/t/interpolate-between-two-segmentations/26837>\
**Category:** Support\
**Created:** [December 20, 2022, 3:00am UTC](https://discourse.slicer.org/t/interpolate-between-two-segmentations/26837 "2022-12-20T03:00:26Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![ifried01](https://avatars.discourse-cdn.com/v4/letter/i/b9bd4f/32.png) [@ifried01](https://discourse.slicer.org/u/ifried01)\
**Post date:** [December 20, 2022, 10:19pm UTC](https://discourse.slicer.org/t/interpolate-between-two-segmentations/26837/3 "2022-12-20T22:19:49Z")

</div>

Thanks for the pointer. I used Elastix to get the displacement values (and referred to [this post](https://discourse.slicer.org/t/calculating-the-displacement-between-two-models/4012) and [this post](https://discourse.slicer.org/t/computing-airway-motion-from-4dct/12971) 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](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#get-volume-voxel-coordinates-from-markup-control-point-ras-coordinates) 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?

> [@lassoan](#):
>
> What information would you like to get from these images?

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.

---

_[View the full topic](https://discourse.slicer.org/t/interpolate-between-two-segmentations/26837)._
