# How to GetIJKToRASDirections from a volume node

**URL:** <https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651>\
**Category:** Support\
**Created:** [October 2, 2019, 7:49pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651 "2019-10-02T19:49:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 2, 2019, 7:49pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/1 "2019-10-02T19:49:46Z")

</div>

Dear all,

I would like to get IJKToRASDirections from a node and set IJKToRASDirections to another in python script. But I do not think I get correct one.

```auto
    dirs = [[0] * 3] * 3
    body_roi_labelmap_node.GetIJKToRASDirections(dirs)
    print(dirs)
    copied_labelmap_node.SetIJKToRASDirections(dirs)

```

The dirs I got is [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]. The value is same for the three directions.

The corresponding C++ code:

```auto
//----------------------------------------------------------------------------
void vtkMRMLVolumeNode::CopyOrientation(vtkMRMLVolumeNode *node)
{
  double dirs[3][3];
  node->GetIJKToRASDirections(dirs);

  int disabledModify = this->StartModify();
  this->SetIJKToRASDirections(dirs);
  this->SetOrigin(node->GetOrigin());
  this->SetSpacing(node->GetSpacing());
  this->EndModify(disabledModify);
}

```

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 2, 2019, 8:13pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/2 "2019-10-02T20:13:33Z")

</div>

> [@Guangshan\_Chen](#):
>
> But I do not think I get correct one

Can you explain why you think that it should not be identity?

If it’s because you put it under a transform, then it’s normal, because the volume itself still has identity directions. You can either set the same transform as parent of the other volume, or you can harden the transform, which will “burn” the matrix in the volume directions and then you can use it the way you want. However, we typically simply use the transform hierarchy and the convenience functions to get the transform between objects when necessary.

---

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 2, 2019, 9:29pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/3 "2019-10-02T21:29:08Z")

</div>

it is not identity. The returned value is:  
0 0 1  
0 0 1  
0 0 1

---

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 2, 2019, 9:35pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/4 "2019-10-02T21:35:46Z")

</div>

In python script, I could not reproduce the result of  
copied\_labelmap\_node.CopyOrientation(body\_roi\_labelmap\_node) with:

```auto
disableModify = copied_labelmap_node.StartModify()
dirs = [[0] * 3] * 3
body_roi_labelmap_node.GetIJKToRASDirections(dirs)
print(dirs)
copied_labelmap_node.SetIJKToRASDirections(dirs)
copied_labelmap_node.SetOrigin(body_roi_labelmap_node.GetOrigin())
copied_labelmap_node.SetSpacing(body_roi_labelmap_node.GetSpacing())
copied_labelmap_node.EndModify(disableModify)

```

The above code is identical to the C++ code of CopyOrientation.  
So the only place could be wrong is where getting GetIJKToRASDirections and SetIJKToRASDirections.

---

<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 3, 2019, 11:46am UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/5 "2019-10-03T11:46:23Z")

</div>

> [@Guangshan\_Chen](#):
>
> dirs = [[0] \* 3] \* 3

This creation of a “matrix” caused the unexpected output: a list was created that referred _to the same list_ 3 times. Effectively, the code did this: `dirs = [v,v,v]`.

Instead, you need to provide unique values for all the 3x3 values in the matrix. Probably the simplest is to create it as a numpy array: `dirs = np.eye(3)`.

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [October 3, 2019, 12:13pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/6 "2019-10-03T12:13:27Z")

</div>

I think what he needs is a zero matrix in which case is `dirs = np.zeros([3, 3])`

---

<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 3, 2019, 12:55pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/7 "2019-10-03T12:55:44Z")

</div>

Values will be overwritten anyway by calling `GetIJKToRASDirections`, so in this specific example, either `np.zeros` or `np.eye` works.

However, since a null-matrix is not a valid direction matrix, it is not good practice to store it in a variable called “direction”, even temporarily. `np.eye` creates an identity matrix, which is what you want as a default direction matrix; and its syntax is a bit simpler than `np.zeros`, too.

---

<div class="post-metadata">

**Author:** ![Guangshan\_Chen](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/guangshan_chen/32/4832_2.png) [@Guangshan\_Chen](https://discourse.slicer.org/u/Guangshan_Chen)\
**Post date:** [October 3, 2019, 1:45pm UTC](https://discourse.slicer.org/t/how-to-getijktorasdirections-from-a-volume-node/8651/8 "2019-10-03T13:45:30Z")

</div>

> [@lassoan](#):
>
> dirs = np.eye(3)

Thank you very much. This works.
