# Using vtkImagePermute on vtkImageData with multiple scalars

**URL:** https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714
**Category:** Development
**Created:** [February 27, 2020, 8:26pm UTC](https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714 "2020-02-27T20:26:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Patrick\_Avery](https://discourse.vtk.org/user_avatar/discourse.vtk.org/patrick_avery/32/429_2.png) [@Patrick\_Avery](https://discourse.vtk.org/u/Patrick_Avery)
#### Post date: [February 27, 2020, 8:26pm UTC](https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714/1 "2020-02-27T20:26:19Z")

</div>

We have been using `vtkImagePermute` to swap two axes on `vtkImageData` in Tomviz. We have also recently been adding support for the `vtkImageData` to have multiple scalars associated with it (i. e., `image->GetPointData()->GetNumberOfArrays() > 1`).

However, I noticed that the permute is only applied to the active scalars.

I currently have a semi-complicated workaround for this, which involves creating a `vtkImageData` for each of the scalars, performing a `vtkImagePermute` on each, and then putting the scalars back into the original `vtkImageData`.

But I was wondering, is there any interest in getting `vtkImagePermute` to work on all of the scalars? I think one option could be to loop through all of the scalars [in vtkImageReslice](https://gitlab.kitware.com/vtk/vtk/blob/96f506a418ab6d4ea505d61fc6d14e5fb6263378/Imaging/Core/vtkImageReslice.cxx#L3026), and perform the operation on each of the scalars. However, `vtkImageReslice` does call some functions that work with the active scalars. We might would either need to change these function calls, or change the active scalars in each iteration of the loop via `SetActiveScalars` (and I’m not sure if that’s desirable).

---

<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: [February 27, 2020, 8:56pm UTC](https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714/2 "2020-02-27T20:56:19Z")

</div>

This is interesting. I’ve always assumed that vtkImageData only allowed to have one scalar array. Does any of the image filters or mappers can do anything with the non-active scalar arrays?

Since VTK now supports oriented image data, you can encode any voxel-\>physical coordinate system mapping in the vtkImageData. There should be no (or very limited) need for vtkImagePermute anymore.

---

<div class="post-metadata">

### Author: ![Patrick\_Avery](https://discourse.vtk.org/user_avatar/discourse.vtk.org/patrick_avery/32/429_2.png) [@Patrick\_Avery](https://discourse.vtk.org/u/Patrick_Avery)
#### Post date: [February 27, 2020, 9:30pm UTC](https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714/3 "2020-02-27T21:30:42Z")

</div>

I am personally not aware of any image filters or mappers that work with non-active scalar arrays. We only display the active scalars, but we allow the user to switch the active scalars via a panel.

I can look into the physical coordinate system mapping.

---

<div class="post-metadata">

### Author: ![Patrick\_Avery](https://discourse.vtk.org/user_avatar/discourse.vtk.org/patrick_avery/32/429_2.png) [@Patrick\_Avery](https://discourse.vtk.org/u/Patrick_Avery)
#### Post date: [February 28, 2020, 12:34am UTC](https://discourse.vtk.org/t/using-vtkimagepermute-on-vtkimagedata-with-multiple-scalars/2714/4 "2020-02-28T00:34:32Z")

</div>

I think the main reason we are swapping the axes, though, is to make a particular axis (the “tilt axis” for our tilt series) to be the fast axis, so that it will be fast to loop through that axis.
