# Setting the I-S range for a MarkupsROI

**URL:** <https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357>\
**Category:** Support\
**Created:** [October 20, 2023, 9:12pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357 "2023-10-20T21:12:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 20, 2023, 9:12pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357/1 "2023-10-20T21:12:22Z")

</div>

Hello all,

I’m looking for python Get and Set methods for the ROI Settings in markups. In the picture below, I am trying to retrieve the current value of the lower bound of the I-S range (-26.52 here) and then set it to 0. All I can find information on is getting and setting Control Point center/radius.

 ![discourse_q](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/5/f53dae3243d6f8cc6e5a99a1c1351924b36bbdc0.png)

Thanks in advance for any help

---

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 23, 2023, 5:26pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357/2 "2023-10-23T17:26:35Z")

</div>

I have found out how to retrieve the values (although they are mysteriously slightly off from the GUI values) but I still cannot figure out how to set new ranges.

sz = [0,0,0,0,0,0]  
roiNode.GetBounds(sz) #stores the dimensions of my ROI into sz

This [documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#write-markup-roi-to-json-file) seems to imply that even if I load in a markup roi from a file it will need to simply be the center and size rather than specified bounds. There has to be a way to do this, right?

Best,

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [October 23, 2023, 6:34pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357/3 "2023-10-23T18:34:19Z")

</div>

It looks to me like the two ways to control the position and range of a MarkupsROI are the `SetCenter()` and `SetSize()` methods. Those don’t provide a convenience method for setting the range on one dimension exactly, but it’s not too hard to do the calculations you would need. You can get the current center (`GetCenter()`, and then change the 3rd element to the middle of your new desired I-S range, and get the current size (`GetSize()`) and change the 3rd element to your new desired range (or half your new desired range, I can’t tell right off whether the size is like a radius or a diameter…)

---

<div class="post-metadata">

**Author:** ![wesselk](https://avatars.discourse-cdn.com/v4/letter/w/ac8455/32.png) [@wesselk](https://discourse.slicer.org/u/wesselk)\
**Post date:** [October 23, 2023, 6:45pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357/4 "2023-10-23T18:45:02Z")

</div>

Thanks Mike, I was just in the middle of responding with my solution when you commented. The only issue I’m still having is the inaccuracy of the GetBounds() method, see below:

 ![getBounds_errors](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/9/897f28bdad3f2d0988d83d6327216a35808b2370.png)

I don’t know if this warrants a bug report, it reduces my precision but I am still getting good results.

## My Solution

I have written 2 functions, getCenterfromBounds() and getSizefromBounds(). I think I need this slightly more involved approach to edit the ROI to account for skewed volumes. To set a new lower bound, it looks like this:

```auto
bounds = [0,0,0,0,0,0]
roiNode.GetBounds(bounds)
newLower = getNewLowerBound(bounds[5],bounds[4])
bounds[4] = newLower
newCenter = getCenterFromBounds(bounds)
newSize = getSizeFromBounds(bounds)
roiNode.SetCenter(newCenter)
roiNode.SetSize(newSize)

```

---

<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 24, 2023, 1:45pm UTC](https://discourse.slicer.org/t/setting-the-i-s-range-for-a-markupsroi/32357/5 "2023-10-24T13:45:18Z")

</div>

I don’t think there is a bug in the bounds computation. Both `GetRASBounds()` and `GetBounds()` methods return accurate results. The difference is that one returns the extents in the world coordinate system while the other in the markup’s own coordinate system.
