# how to adjust the volume position base on image slice

**URL:** https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512
**Category:** Support
**Created:** [January 29, 2020, 5:16am UTC](https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512 "2020-01-29T05:16:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [January 29, 2020, 5:16am UTC](https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512/1 "2020-01-29T05:16:02Z")

</div>

Hi,  
My program can render image slice(sagittal, coronal and axial orientation) from DICOM data and the volume base on the DICOM data in a window. But the volume position is not what I want. It’s outside of the slice bound range.

 ![2020-01-29_130210](https://discourse.vtk.org/uploads/default/original/2X/a/aab7d1ea4eb56c2e87fd3e5921095fce13ff4ac7.png)

I want to adjust the volume to the correct position like the demo show in the following picture:

 ![2020-01-29_130322](https://discourse.vtk.org/uploads/default/original/2X/3/33fb7993b28707cd8dca1c1df4802723ff36cf40.png)

I don’t want to adjust the position of the volume manually by setting matrix on UI. I want to my program can do this automatically. I have no idea to realize it. Can some one give me some tips or reference sourc code.  
Thanks in advance!

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 29, 2020, 5:45pm UTC](https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512/2 "2020-01-29T17:45:52Z")

</div>

If the images are two different scans then you can align them automatically using intensity-based image registration. You can use ITK or ITK-based registration libraries, such as Elastix.

---

<div class="post-metadata">

### Author: ![yuhuimoon](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/y/c6cbf5/32.png) [@yuhuimoon](https://discourse.vtk.org/u/yuhuimoon)
#### Post date: [April 6, 2020, 8:51am UTC](https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512/3 "2020-04-06T08:51:12Z")

</div>

I successfully adjust the position of the volume by using **GetSFormMatrix()** from the reader. The volume and the reslice are from the same image source.

```
//m_imgReader is an object of vtkNIFTIImageReader
vtkSmartPointer<vtkMatrix4x4> matImage = m_imgReader->GetSFormMatrix();
vtkSmartPointer<vtkTransform> transf = vtkSmartPointer<vtkTransform>::New();
transf->SetMatrix(matImage);
transf->PostMultiply();
transf->Concatenate(m_vtkVolume->GetMatrix());
m_vtkVolume->SetUserTransform(transf);

```

If they are from the different images, I use Elastix and it works well.  
Thanks! 😀

---

<div class="post-metadata">

### Author: ![kookoo9999](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kookoo9999/32/3701_2.png) [@kookoo9999](https://discourse.vtk.org/u/kookoo9999)
#### Post date: [July 26, 2021, 5:06am UTC](https://discourse.vtk.org/t/how-to-adjust-the-volume-position-base-on-image-slice/2512/4 "2021-07-26T05:06:42Z")

</div>

Great… Can I get the this Source Code??  
My program can render image slice… but as I add reslice actor to Volume , Image is broken like this Picture.  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/8d242b8b6c87f5e898bd3da23b39888f815ce1f6.png)
