# Configure ROI to match volume through code

**URL:** <https://discourse.slicer.org/t/configure-roi-to-match-volume-through-code/39695>\
**Category:** Support\
**Created:** [October 14, 2024, 3:20pm UTC](https://discourse.slicer.org/t/configure-roi-to-match-volume-through-code/39695 "2024-10-14T15:20:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shai-ikko](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/shai-ikko/32/15765_2.png) [@shai-ikko](https://discourse.slicer.org/u/shai-ikko)\
**Post date:** [October 14, 2024, 3:20pm UTC](https://discourse.slicer.org/t/configure-roi-to-match-volume-through-code/39695/1 "2024-10-14T15:20:40Z")

</div>

Hi,

I’m trying to use a ROI markup to designate a rotation transform (I don’t want an actual transform because reasons). I initially configure the ROI as [recommended in the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#fit-markups-roi-to-volume). The problem is that this seems to create a “fragile” ROI – there is something funny going on between its `ObjectToNodeMatrix` and `ObjectToWorldMatrix`, and as a result, any further attempt to modify it via code throws it aside (the image origin is not at 0,0,0).

More details:

Right after running the code from the repository, if I pick up the ROI:

```auto
>>> nodes = slicer.mrmlScene.GetNodesByClass("vtkMRMLMarkupsROINode")
>>> roi = nodes.GetItemAsObject(0)

```

And look at its matrices (some unimportant details removed)

```auto
>>> print(roi.GetObjectToNodeMatrix())
    1 0 0 -64.8817 
    0 1 0 -65.6043 
    0 0 1 81.1599 
    0 0 0 1 
>>> print(roi.GetObjectToWorldMatrix())
    1 0 0 -64.8817 
    0 1 0 -65.6043 
    0 0 1 81.1599 
    0 0 0 1 

```

But if now I trigger computations (which apparently should have happened) – without otherwise touching anything –

```auto
>>> roi.GetObjectToNodeMatrix().Modified()

```

Then I can already see the ROI jump. If I now repeat the above, the `ObjectToNodeMatrix` looks the same, but

```auto
>>> print(roi.GetObjectToWorldMatrix())
    1 0 0 0 
    0 1 0 0 
    0 0 1 0 
    0 0 0 1 

```

Is this as intended? Am I doing something wrong?

(Just to be on the safe side – in my code, I also set up two display nodes for the ROI, and turn interaction controls on and off, but I don’t think that should affect the translation matrices in any way)

Thanks!
