# Oriented image data, vtkImageResliceMapper / vtkImageSlice in VTK 9.1.0?

**URL:** https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167
**Category:** Support
**Created:** [March 29, 2022, 12:53pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167 "2022-03-29T12:53:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.vtk.org/u/Sophonet)
#### Post date: [March 29, 2022, 12:53pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/1 "2022-03-29T12:53:58Z")

</div>

Hi everyone,

I would like to show oriented image data in “world” / DICOM coordinates. For that I am using vtkImageResliceMapper and need to set a user matrix from unrotated to rotated coordinates for vtkImageSlice (which uses the mapper). If I do not call vtkImageSlice-\>SetUserMatrix(unrotated\_to\_rotated), the slice is not displayed at the correct position.

However, in this case, bounds via vtkImageSlice are not computed correctly, since the vtkImageResliceMapper::GetBounds() considers data directions, and the residual code in vtkImageSlice::GetBounds() applies them again.

Is this a bug in VTK or do I need to change my code?

Thanks,

Sophonet

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.vtk.org/u/Sophonet)
#### Post date: [March 30, 2022, 7:06pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/2 "2022-03-30T19:06:49Z")

</div>

Hi everyone,

in the meantime I have tried to nail down the problem further and my current lead is this the following:

- I would think that with VTK9 on, vtkImageSlice shall not need a user matrix from unrotated to rotated coordinates, since the vtkImageData knows how to orient itself now.
- However, vtkOpenGLImageSliceMapper (which does the rendering in Render()) does not consider image directions as far as I can see, Render() only extracts DataSpacing and DataOrigin from imageData but not DataDirections. I would think that this is a bug in VTK.

Any specific hint how to correctly fix this? Is this assumption above correct? David Gobbi, can you maybe comment?

Thanks,

Sophonet

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [March 30, 2022, 9:10pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/3 "2022-03-30T21:10:48Z")

</div>

Hello,

I think it’s better to “summon” the wanted person by using the syntax `@<David Gobbi's moniker>`.

take care,

Paulo

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.vtk.org/u/Sophonet)
#### Post date: [March 31, 2022, 10:45am UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/4 "2022-03-31T10:45:56Z")

</div>

Thanks Paulo, let me try. @dgobbi, can you comment regarding my questions above and help fix an orientation problem in VTK 9.1.0? I think that the DirectionMatrix needs to be considered in vtkOpenGLSliceMapper, this is not yet the case.

Thanks and best regards, Sophonet

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [March 31, 2022, 1:30pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/5 "2022-03-31T13:30:37Z")

</div>

Hi Sophonet,

When I write DICOM software in VTK, the Spacing is the only thing that I store in the vtkImageData itself. I keep the orientation and position in a separate vtkMatrix4x4. The DirectionMatrix isn’t yet implemented everywhere in VTK. From what I’ve heard from other developers, it’s still a work in progress.

David

---

<div class="post-metadata">

### Author: ![Sophonet](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Sophonet](https://discourse.vtk.org/u/Sophonet)
#### Post date: [March 31, 2022, 8:20pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/6 "2022-03-31T20:20:47Z")

</div>

Hi David,

thanks for the quick reply! Too bad that the aspect of work in progress is not documented.

Best, Sophonet

---

<div class="post-metadata">

### Author: ![Ingmar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/cc9497/32.png) [@Ingmar](https://discourse.vtk.org/u/Ingmar)
#### Post date: [March 18, 2024, 9:30pm UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/7 "2024-03-18T21:30:49Z")

</div>

@dgobbi from your checkin [https://gitlab.kitware.com/vtk/vtk/-/commit/1ce55760f3731b7d0e93d894f75106cb9bb14a83](https://gitlab.kitware.com/vtk/vtk/-/commit/1ce55760f3731b7d0e93d894f75106cb9bb14a83) I assume that vtkImageResliceMapper would now correctly interpret the DirectionMatrix of the input vtkImageData? I guess that is also stored as the WorldToDataMatrix in [VTK: vtkImageResliceMapper Class Reference](https://vtk.org/doc/nightly/html/classvtkImageResliceMapper.html)?

I had tried to sample a 2D slice from an oriented 3D volume with vtkImageReslice, but realized it does not actually seem to support the DirectionMatrix (according to various Discourse threads)

---

<div class="post-metadata">

### Author: ![Ingmar](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/i/cc9497/32.png) [@Ingmar](https://discourse.vtk.org/u/Ingmar)
#### Post date: [March 19, 2024, 11:34am UTC](https://discourse.vtk.org/t/oriented-image-data-vtkimagereslicemapper-vtkimageslice-in-vtk-9-1-0/8167/9 "2024-03-19T11:34:09Z")

</div>

Indeed it actually starts working with version 9.3.0 (possibly also sth earlier) - thanks a lot! 🙂
