# ImageReslice behave

**URL:** https://discourse.vtk.org/t/imagereslice-behave/12610
**Category:** vtk.js
**Created:** [November 3, 2023, 11:31am UTC](https://discourse.vtk.org/t/imagereslice-behave/12610 "2023-11-03T11:31:47Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Xoz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/xoz/32/5714_2.png) [@Xoz](https://discourse.vtk.org/u/Xoz)
#### Post date: [November 3, 2023, 11:31am UTC](https://discourse.vtk.org/t/imagereslice-behave/12610/1 "2023-11-03T11:31:47Z")

</div>

Hi everyone,  
I’ve met an issue when using ImageReslice, it’s like this, I have a cursor to control the resliceAxes of the resclice, when it is located at some position which makes the cutting plane be close to standard xyz axes, the quality of the image looks fine, like this(the brown and blue cross are the cutting planes):  
 ![standard_reslice_plane](https://discourse.vtk.org/uploads/default/original/2X/7/795b4a3f68d5438dae6385eb5faefe9496e3d546.jpeg)

![standard_tan](https://discourse.vtk.org/uploads/default/original/2X/6/61e4c399f03295a30c19233d79fa66ca5c7815d9.jpeg) ![standard_ortho](https://discourse.vtk.org/uploads/default/original/2X/c/c497641fb223257f60e03c4d216c28a4dc2a3a39.jpeg)

When the cursor is located at some shifted places, the quality of the images get much worse, like this:  
 ![shift_reslice_plane](https://discourse.vtk.org/uploads/default/original/2X/2/234feafab2fdfb53ed7fb4768fd36fe4bcbc01d3.jpeg)  
 ![shift_tan](https://discourse.vtk.org/uploads/default/original/2X/f/f4a26d3b336a91d49e01416dda5e82b579f3a0d8.jpeg) ![shift_ortho](https://discourse.vtk.org/uploads/default/original/2X/4/4eb94ed45a70b7c27aa42d082c48a7cf374d21b4.jpeg)

Should I change some params to avoid this? What I did on reslice is:

```auto
    reslice.setResliceAxes(cursorMatrix)
    reslice.setSlabMode(options.slabMode)
    reslice.setSlabNumberOfSlices(1)
    reslice.setTransformInputSampling(false)
    reslice.setAutoCropOutput(true)
    reslice.setOutputDimensionality(2)

```

Interpolation type is set to linear in the imageSlice property.

Thanks in advance

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [November 3, 2023, 12:27pm UTC](https://discourse.vtk.org/t/imagereslice-behave/12610/2 "2023-11-03T12:27:13Z")

</div>

Only [nearest-neighbor interpolation](https://github.com/Kitware/vtk-js/blob/master/Sources/Imaging/Core/ImageReslice/index.js#L1080) exists so far in vtkImageReslice.

You would need to check, what is missing in vtkImageReslice/index.js to support LINEAR interpolation. You can do so by comparing with vtkImageReslice.cxx in VTK C++.

Please contribute a pull request (or externalize the work if you have funding).

Hth,  
Julien.

---

<div class="post-metadata">

### Author: ![Xoz](https://discourse.vtk.org/user_avatar/discourse.vtk.org/xoz/32/5714_2.png) [@Xoz](https://discourse.vtk.org/u/Xoz)
#### Post date: [November 9, 2023, 9:37am UTC](https://discourse.vtk.org/t/imagereslice-behave/12610/3 "2023-11-09T09:37:02Z")

</div>

Hi Julien,  
I finished a demo with that but since it’s still using cpu to calculate, the trilinear interpolation method takes too much time(about 5ms for a 500 \* 500 \* 300 imageData), which means if there are 3 reslices(axial, coronal and sagittal), it’s hard to get the whole render framerate to 60fps with more calculations for some other functions, so I changed the vtkImageReslice to a vtkImageResliceMapper instance which uses gpu to do the interpolation and it performs good.

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [November 9, 2023, 1:13pm UTC](https://discourse.vtk.org/t/imagereslice-behave/12610/4 "2023-11-09T13:13:40Z")

</div>

Hi Xoz,

If you have something working it would be great if you could contribute it upstream with a PR.

I have the following 2 comments:

- vtkImageResliceMapper is GPU, hence it means that currently (can change in the future), the 3D volume must be uploaded onto the GPU as many times as there are renderwindows.
- In most cases, (e.g. you scroll only 1 view), there should be only 1 slice recomputation. If you rotate a view while keep axes orthogonal, you may have 2 views to refresh. So there is some optimization that can be done to not have the 3 views always recomputed.
