# Howto get imageDirections from a ROI?

**URL:** <https://discourse.slicer.org/t/howto-get-imagedirections-from-a-roi/25713>\
**Category:** Development\
**Tags:** dicom, python\
**Created:** [October 15, 2022, 1:56am UTC](https://discourse.slicer.org/t/howto-get-imagedirections-from-a-roi/25713 "2022-10-15T01:56:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [October 15, 2022, 1:56am UTC](https://discourse.slicer.org/t/howto-get-imagedirections-from-a-roi/25713/1 "2022-10-15T01:56:20Z")

</div>

I want to create a volume from a ROI:

```python
nodeName = "MyNewVolume"
imageSize = list(map(int, dim)) # the size of the ROI
voxelType=vtk.VTK_UNSIGNED_CHAR
imageOrigin = cn[0] # the origin of the ROI
imageSpacing = [1.0, 1.0, 1.0]
imageDirections = drts # the drts is directs of the ROI
fillVoxelValue = 0

# Create an empty image volume, filled with fillVoxelValue
imageData = vtk.vtkImageData()
imageData.SetDimensions(imageSize)
imageData.AllocateScalars(voxelType, 1)
imageData.GetPointData().GetScalars().Fill(fillVoxelValue)
# Create volume node
volumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLScalarVolumeNode", nodeName)
volumeNode.SetOrigin(imageOrigin)
volumeNode.SetSpacing(imageSpacing)
volumeNode.SetIJKToRASDirections(imageDirections)
volumeNode.SetAndObserveImageData(imageData)
volumeNode.CreateDefaultDisplayNodes()
volumeNode.CreateDefaultStorageNode()

```

but I got 👇:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/b/ab59a7ba06a43182c19647444bc36c7920f79a8d.png)

I guess it’s because of the problem of ‘imageDirections’, so–  
Howto get imageDirections from a ROI?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [October 16, 2022, 5:11am UTC](https://discourse.slicer.org/t/howto-get-imagedirections-from-a-roi/25713/2 "2022-10-16T05:11:17Z")

</div>

You can get the image axis directions from the top-left 3x3 submatrix of the [ObjectToWorldMatrix](https://apidocs.slicer.org/master/classvtkMRMLMarkupsROINode.html#a540216cdf23db6e5766b84238e638996).
