# How to get an oblique 2d image from a 3d ct-images using vtk via python

**URL:** https://discourse.vtk.org/t/how-to-get-an-oblique-2d-image-from-a-3d-ct-images-using-vtk-via-python/7174
**Category:** Support
**Created:** [November 15, 2021, 5:29am UTC](https://discourse.vtk.org/t/how-to-get-an-oblique-2d-image-from-a-3d-ct-images-using-vtk-via-python/7174 "2021-11-15T05:29:27Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Sara\_Tayyebi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sara_tayyebi/32/7087_2.png) [@Sara\_Tayyebi](https://discourse.vtk.org/u/Sara_Tayyebi)
#### Post date: [November 15, 2021, 5:29am UTC](https://discourse.vtk.org/t/how-to-get-an-oblique-2d-image-from-a-3d-ct-images-using-vtk-via-python/7174/1 "2021-11-15T05:29:27Z")

</div>

Hello.  
I want to get an oblique 2d image from a 3d ct-images using vtk via python. I want to extract a plane from my angle in coronal plane, that passes from spesific points, and access a specific oblique plane. I want that plane exactly pass from points. I used from vtkImageReslice and vtkMatrix4x4. Sorry for my English.

Grateful for any help.

For example,  
data = (512, 512, 173)  
In coronal plane, points \>\>\> p1 = [127, 234, 149], p2 = [145, 234, 128], p3 = [145, 236, 128]

I computed a-angle and created vtkMatrix4x4.  
I used from vtkImageReslice and vtkMatrix4x4, but I have some problems.

What does center of this matrix mean?  
How can I get the page I want?

This is my code:

import vtk

path = ‘F:/…/’

reader = vtk.vtkDICOMImageReader()  
reader.SetDirectoryName(path)  
reader.Update()

reslice = vtk.vtkImageReslice()  
reslice.SetInputConnection(reader.GetOutputPort())  
reslice.SetAutoCropOutput(True)  
reslice.SetOutputDimensionality(2)  
reslice.SetInterpolationModeToCubic()  
reslice.SetSlabNumberOfSlices(1)  
reslice.SetOutputSpacing(1.0,1.0,1.0)

center = [127, 234, 149]

axialElement = [  
0.76, 0, 0.65, center[0],  
0, 1, 0, center[1],  
-0.65, 0, 0.76, center[2],  
0, 0, 0, 1]

resliceAxes = vtk.vtkMatrix4x4()  
resliceAxes.DeepCopy(axialElement)  
reslice.SetResliceAxes(resliceAxes)  
reslice.Update()

reslicedImg = reslice.GetOutput()

imageActor = vtk.vtkImageActor()  
windowLevel = vtk.vtkImageMapToWindowLevelColors()  
imageActor.GetMapper().SetInputConnection(windowLevel.GetOutputPort())  
windowLevel.SetInputData(reslicedImg)  
windowLevel.Update()

ren = vtk.vtkRenderer()  
ren.AddActor(imageActor)  
ren.SetBackground(0.1, 0.2, 0.4)

renWin = vtk.vtkRenderWindow()  
renWin.AddRenderer(ren)  
renWin.SetSize(400, 400)

iren = vtk.vtkRenderWindowInteractor()  
iren.SetRenderWindow(renWin)  
renWin.Render()  
iren.Start()
