# How to properly create a volumeNode after registration using SITK ?

**URL:** <https://discourse.slicer.org/t/how-to-properly-create-a-volumenode-after-registration-using-sitk/27989>\
**Category:** Support\
**Created:** [February 22, 2023, 10:30pm UTC](https://discourse.slicer.org/t/how-to-properly-create-a-volumenode-after-registration-using-sitk/27989 "2023-02-22T22:30:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mwoon](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mwoon/32/18537_2.png) [@Mwoon](https://discourse.slicer.org/u/Mwoon)\
**Post date:** [February 22, 2023, 10:30pm UTC](https://discourse.slicer.org/t/how-to-properly-create-a-volumenode-after-registration-using-sitk/27989/1 "2023-02-22T22:30:09Z")

</div>

The question is basic, but I don’t know what is failing.  
Here is the code :

```auto
resampled = sitk.Resample(moving_image, fixed_image, final_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())
volume = self.sitk_to_vtk(resampled)
self.transfer_volume_metadate(volume, volume)
self.add_volume(volume)

    def transfer_volume_metadate(self, original_volume, moved_volume) -> None:
        spacing = original_volume.GetSpacing()
        origin = original_volume.GetOrigin()
        ijk_to_ras_direction_matrix = vtk.vtkMatrix4x4()
        original_volume.GetIJKToRASDirectionMatrix(ijk_to_ras_direction_matrix)

        # Apply the metadata to the target volume.
        moved_volume.SetSpacing(spacing)
        moved_volume.SetOrigin(origin)
        moved_volume.SetIJKToRASDirectionMatrix(ijk_to_ras_direction_matrix)

    def add_volume(self, volume) -> None:
        volume.SetName(self.volume_name_edit.text)
        mrmlScene.AddNode(volume)
        slicer.util.setSliceViewerLayers(volume, fit=True)

```

Here is what I obtain with those parameters :

 ![first_registration.PNG](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/ecef19489b65c1c15e0ae91eceb302109dc51e0d.jpeg)  
The stopping condition is :

```auto
Optimizer stop condition: GradientDescentOptimizerv4Template: Convergence checker passed at iteration 38.
 Iteration: 38
 Metric value: -0.40111932866211414

```

If I change in the function transfer\_metadata the first parameter by fixedImageData, I obtain something more coherent

 ![second_registration.PNG](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/7/877dafef05b1be08780bb1cc766c002c9e1f5701.jpeg)  
 ![second_registration_with_fixed_image.PNG](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/a/4a5b4b5e741d6b16a49ad50d2dbc8a291f4b70b7.jpeg)

```auto
Optimizer stop condition: GradientDescentOptimizerv4Template: Convergence checker passed at iteration 72.
 Iteration: 72
 Metric value: -0.40737172935316895

```

Well, I don’t know which one is the correct way to construct the final registered volume, and from the registration something is happening, it stops before 100 steps.  
Any kind heart to help me with this ?
