# How to get oblique 2d slice from volume (simpleITK)

**URL:** <https://discourse.itk.org/t/how-to-get-oblique-2d-slice-from-volume-simpleitk/6028>\
**Category:** Beginner Questions\
**Created:** [June 28, 2023, 8:34pm UTC](https://discourse.itk.org/t/how-to-get-oblique-2d-slice-from-volume-simpleitk/6028 "2023-06-28T20:34:07Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [June 29, 2023, 12:11pm UTC](https://discourse.itk.org/t/how-to-get-oblique-2d-slice-from-volume-simpleitk/6028/3 "2023-06-29T12:11:13Z")

</div>

Hello @zivy,

thank you very much for your reply.  
i made changes to the code and my function looked like this, for future readers:

```auto
import numpy as np
import SimpleITK as sitk
import time

def oblique_slice(self, theta_x_degrees:float, theta_y_degrees:float, theta_z_degrees:float, slice_size:list[int], slice_index:list[int]) -> np.array:
        """
        extrai um slice obliquo do volume e retorna em formato de array numpy
        """
        theta_x_radians = np.deg2rad(theta_x_degrees)
        theta_y_radians = np.deg2rad(theta_y_degrees)
        theta_z_radians = np.deg2rad(theta_z_degrees)
        rotation_matrix = sitk.Euler3DTransform()
        rotation_matrix.SetRotation(theta_x_radians, theta_y_radians, theta_z_radians)
        time1 = time.time()
        rotated_volume = sitk.Resample(self.volume, rotation_matrix)
        time2 = time.time()
        print(f"resample timer = {time2 - time1}")
        slice_extraction = sitk.Extract(rotated_volume, slice_size, slice_index)
        return sitk.GetArrayFromImage(slice_extraction)

```

With this parrameters i will be able to implement mpr function.  
I am trying to optimize this code because Resample are taking too much time, approximately 0.04/0.045 seconds, which gives me 20 frames per second.  
In my MainSettings i set:

> sitk.ProcessObject.SetGlobalDefaultNumberOfThreads(multiprocessing.cpu\_count())

And now i’m trying to use gpu with pytorch or tensorflow, after reading this:

> [@Is it possible to use GPU for resample filter in simpleITK and Windows?](https://discourse.itk.org/t/is-it-possible-to-use-gpu-for-resample-filter-in-simpleitk-and-windows/4357):
>
> Is it possible to use GPU for image resample in simpleITK or ITK? I checked the previous post, in that, one of the answers was to use the “itk-elastic-opencl” But it seems like work only on Linux Is there any other way to accelerate the resample filter on Windows? And my final goal is that getting a resample result of less than 0.5 s Is it also possible?

which by coincidence you answered too, lol!  
I will bring news in case I get something.

---

_[View the full topic](https://discourse.itk.org/t/how-to-get-oblique-2d-slice-from-volume-simpleitk/6028)._
