# .vtk export misalignment with CT scans

**URL:** <https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416>\
**Category:** Support\
**Created:** [July 5, 2023, 6:28pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416 "2023-07-05T18:28:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![William\_Kuo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_kuo/32/65525_2.png) [@William\_Kuo](https://discourse.slicer.org/u/William_Kuo)\
**Post date:** [July 5, 2023, 6:28pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/1 "2023-07-05T18:28:15Z")

</div>

Hi! I have been using Slicer for a while but I am still unfamiliar with some issues.

When I export my CT scans as a .vtk file and reimport them into Slicer and compare them with my CT scans, they don’t align. This is a problem because when I use the .vtk files in Bonemat, they don’t align with the mesh file I generate.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/a/4aaaf35df014016a30f448ce3bb964e9874e9bde.png)

I tried matching the images and was successful in orienting them. However, the slicer positioning in each axis was still off despite looking the same. I can keep editing these CT files, but I have dozens and it’s inconvenient to keep doing this. Is there a way to export .vtk files that match orientation in CT scans so I can use them in Bonemat without misalignment?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 5, 2023, 6:36pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/2 "2023-07-05T18:36:24Z")

</div>

.vtk format doesn’t preserve the image orientation information. If you really need to use this format for compatibility you should be able to reconstruct a valid geometry manually or ideally use tools that are aware of [orientations](https://www.slicer.org/wiki/Coordinate_systems).

---

<div class="post-metadata">

**Author:** ![William\_Kuo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_kuo/32/65525_2.png) [@William\_Kuo](https://discourse.slicer.org/u/William_Kuo)\
**Post date:** [July 5, 2023, 6:49pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/3 "2023-07-05T18:49:26Z")

</div>

Do you have any recommendation for what tools I should use?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 5, 2023, 7:03pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/4 "2023-07-05T19:03:07Z")

</div>

What are you trying to do?

---

<div class="post-metadata">

**Author:** ![William\_Kuo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/william_kuo/32/65525_2.png) [@William\_Kuo](https://discourse.slicer.org/u/William_Kuo)\
**Post date:** [July 5, 2023, 7:18pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/5 "2023-07-05T19:18:17Z")

</div>

Utilize Bonemat Batch Processing.

I require a .vtk file for the CT scans. But the .vtk file doesn’t align with the CT scans. I need the .vtk file to be axis-aligned to the CT scan, so my object (a bone) can utilize Bonemat that assigns material property to the bone based on the CT scan alignment.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [July 5, 2023, 8:25pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/6 "2023-07-05T20:25:54Z")

</div>

I don’t know if anyone here uses Bonemat (I don’t) but probably it makes assumptions about the image data (identity orientation maybe?) so you can use Slicer to resample your image data until it matches. I see that Bonemat has a restrictive non-commercial license so I’m not interested in learning more about it, but if it’s just assigning scalars to vertices of a mesh you can easily so that with Slicer using either VTK or numpy operations.

---

<div class="post-metadata">

**Author:** ![DaSt](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@DaSt](https://discourse.slicer.org/u/DaSt)\
**Post date:** [October 26, 2023, 7:23am UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/7 "2023-10-26T07:23:30Z")

</div>

Hi William,

I am using Bonemat and have similar issues. I am not exporting VTK files, but STL files derived from a segmentation in Slicer. For some of my DICOM series I see a missalignment in Bonemat between STL derived FE meshes and the DICOM series. This happens for DICOM series where the IJK to RAS Direction Matrix is not made up of solely zeros and ones.

I assume that bonemat does not read the orientation from the DICOM header but sets standard orientation. However I could not find anything in the documentation regarding this so I will dig into the code. Maybe this also helps you?

Best,  
Daniel

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 26, 2023, 1:35pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/8 "2023-10-26T13:35:00Z")

</div>

This error has been reported a few times here on the forum. The problem is that DICOM image import in Bonemat is implemented poorly.

I would recommend not to use Bonemat but instead use the corresponding features in Slicer - see more details here:

> [@Dicom to rectilinear grid vtk](https://discourse.slicer.org/t/dicom-to-rectilinear-grid-vtk/28289/9):
>
> By the way, it seems that [all that bonemat can do](http://www.bonemat.org/downloads/Bonemat_manual.pdf) you can already do in Slicer. For the parameter mapping from CT densities to mechanical properties you can use a few lines of Python code (or using [py\_bonemat\_abaqus](https://pypi.org/project/py_bonemat_abaqus/)). The license of bonemat is quite restrictive and you can do so much more in Slicer that I would recommend to consider using just Slicer for your workflow.

---

<div class="post-metadata">

**Author:** ![DaSt](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@DaSt](https://discourse.slicer.org/u/DaSt)\
**Post date:** [October 26, 2023, 2:06pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/9 "2023-10-26T14:06:34Z")

</div>

Hi Andras,

thank you, I will look into Slicers capability. I use Bonemat primarily because of its capability to map to Finite Element Meshes.

Best regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 26, 2023, 7:17pm UTC](https://discourse.slicer.org/t/vtk-export-misalignment-with-ct-scans/30416/10 "2023-10-26T19:17:53Z")

</div>

Slicer can map CTs to volumetric meshes, too. You can also do all the other steps (proper DICOM image import, segmentation, create FE mesh, sample CT image at mesh point positions, etc.). The only thing that may need some work is to find out what FE mesh file formats Slicer can export, what FE mesh formats your solver can load, and if there is no common format between them then use a converter or a different exporter in Slicer.
