# Irregular shaped ROI and conversion to mask

**URL:** <https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782>\
**Category:** Development\
**Created:** [July 30, 2020, 12:10am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782 "2020-07-30T00:10:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [July 30, 2020, 12:10am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/1 "2020-07-30T00:10:02Z")

</div>

How can I create a 3D ROI of irregular shape (not rectangular prism)? Is the Closed Curve option in the Create and Place menu the only way to do this?  
I also want to be able to use this sort of irregular 3D ROI to create a mask within a scripted module that has the same shape as the input image, and has value 0 inside the 3D ROI and 1 outside of it. What would be the syntax for doing this?  
Thanks,  
Rohan Nadkarni

---

<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:** [July 30, 2020, 12:29am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/2 "2020-07-30T00:29:43Z")

</div>

There are lots of options for defining 3D ROIs. What shape are you creating? What is your overall goal?

---

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [July 30, 2020, 5:14pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/3 "2020-07-30T17:14:54Z")

</div>

I would like some tool that gives the user a lot of flexibility about how to define the shape – irregular contour.  
For my application, the 3D ROI, which is defined using a vtkMRMLAnnotationROINode, may contain some unwanted parts of the body in addition to the tumor we are interested in. The irregular shaped 3D region should overlap with the ROI, and this overlapping region is the omit region. For all feature maps computed from the 3D ROI, voxels within the omit region should have a value of 0, so that the feature map doesn’t compute feature values for the unwanted body parts.

---

<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:** [July 30, 2020, 5:43pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/4 "2020-07-30T17:43:38Z")

</div>

Do you want to segment tumors? Then the most suitable tool is probably Segment Editor.

If there is visible brightness difference between the tumor and surrounding region then probably the fastest is to use “Grow from seeds” (see “Tumor segmentation” section of [Neurosurgical planning tutorial](https://www.slicer.org/wiki/Documentation/Nightly/Training#Slicer4_Neurosurgical_Planning_Tutorial) for step-by-step instructions).

You can also segment tumors fully automatically using Nvidia [AI-based segmentation tool](https://github.com/NVIDIA/ai-assisted-annotation-client/tree/master/slicer-plugin#nvidia-ai-assisted-annotation-aiaa-for-3d-slicer).

If you need quick, [intraoperative tumor segmentation on a touch screen](https://youtu.be/90l0T1ADe_Y?t=55) then you may use Surface Cut effect with a custom user interface (large buttons that makes it easy to use Slicer on a touchscreen).

There are many other tools and approaches implemented in Slicer. If you tell us more about what exactly you are trying to achieve then we can give more targeted advice.

---

<div class="post-metadata">

**Author:** ![rohan\_n](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rohan_n/32/78474_2.png) [@rohan\_n](https://discourse.slicer.org/u/rohan_n)\
**Post date:** [July 30, 2020, 6:18pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/5 "2020-07-30T18:18:08Z")

</div>

Thanks for the comment, but segmentation is not the issue I’m concerned with. In fact, the whole purpose of my module is to perform a specific method of tumor segmentation within the region that the user specifies as containing tumor.

The problem I’m concerned with is related to ROI selection. Specifically, how to define a smaller region within the ROI that should have a value of 0 within the tumor mask.

 ![tumorroiselection](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/7/77d305ba5b1c25a66e15aa838e4da488eb01315e.png)

Please look at this image. My module computes a tumor mask within the region defined by the vtkMRMLAnnotationROINode. However, if we do not have an “omit region”, the heart (in bottom left of ROI) will be labeled incorrectly as tumor (value 1) in the tumor mask created by my module. I want to allow the user to define an omit region (shown in the image as the red shape) so that the module knows that the region of overlap between the red shape and the vtkMRMLAnnotationROINode should have value of 0 in the tumor mask. I’m asking how to make a 3D omit region of arbitrary shape.

I hope this is clear now.

Thanks for your help,  
Rohan

---

<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:** [July 30, 2020, 7:19pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/6 "2020-07-30T19:19:48Z")

</div>

For quick approximate segmentation (to create include/exclude regions) you can use Surface Cut effect:

[![](https://img.youtube.com/vi/xZwyW6SaoM4/maxresdefault.jpg "New "Surface cut" and "Mask volume" tools for 3D Slicer segment editor") ](https://www.youtube.com/watch?v=xZwyW6SaoM4)

You can also add/remove entire regions using Scissors effect in slice views.

You may also be able to create mask from a single click, by combination of Thresholding and Island effects.

It all depends on what are your constraints. If you just need to create training data set for deep learning based segmentation then using a combination of effects in Segment Editor effects should be good. After you segmented a few dozen images, you should be able to create your mask within a minute using existing tools.

---

<div class="post-metadata">

**Author:** ![manjula](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/manjula/32/80981_2.png) [@manjula](https://discourse.slicer.org/u/manjula)\
**Post date:** [July 30, 2020, 11:05pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/7 "2020-07-30T23:05:59Z")

</div>

Is there a way that we can create a cylinder and a cube by defining points in slicer view like in the case,

> Manipulating objects in the slice viewer in the 3D slicer scrip repository which creates a sphere.

- How to define/edit a circular region of interest in a slice

---

<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:** [July 31, 2020, 12:29am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/8 "2020-07-31T00:29:06Z")

</div>

Yes, instead of a `vtkSphereSource`, you can use a `vtkCylinderSource` or `vtkCubeSource`.

---

<div class="post-metadata">

**Author:** ![mohammed\_alshakhas](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mohammed_alshakhas/32/10025_2.png) [@mohammed\_alshakhas](https://discourse.slicer.org/u/mohammed_alshakhas)\
**Post date:** [March 2, 2021, 9:23am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/10 "2021-03-02T09:23:00Z")

</div>

found this searching for the same exact point .  
i want to create ROI around a mandible " very irregular shape" so i can do different rendering for the mandible only , then segment a lesion within the mandible .

with the regular cube , i have to include maxilla and part of temporal bone .

if possible to create a ROI with a selection then render it as a volume would be great

 ![Screen Shot 2021-03-02 at 12.22.27](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/7/47d91d93c921c8947efbcea3a06be6cf7298c2d2.jpeg)

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 2, 2021, 12:40pm UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/11 "2021-03-02T12:40:10Z")

</div>

You should be able to use the Mask Volume effect for that:

> [@New segment editor effects: Mask volume and Surface cut](https://discourse.slicer.org/t/new-segment-editor-effects-mask-volume-and-surface-cut/699):
>
> See short demo video of the new “Mask volume” and “Surface cut” Segment editor effects here: These effects were developed by Kyle Macneil (Med-i Lab, Queen’s University; SPL, Brigham and Women’s Hospital), with help from @lassoan and @fedorov . Thank you for your contribution! Mask volume: Blanks out a segment or surrounding area in a volumetric image. Useful for quick removal of unwanted objects (such as CT table) or showing only a selected organ. It can also be used for creating a binary m…

---

<div class="post-metadata">

**Author:** ![slicer365](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/slicer365/32/67549_2.png) [@slicer365](https://discourse.slicer.org/u/slicer365)\
**Post date:** [March 7, 2021, 2:23am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/12 "2021-03-07T02:23:28Z")

</div>

How to replace it, I know a little about python

---

<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:** [March 7, 2021, 6:14am UTC](https://discourse.slicer.org/t/irregular-shaped-roi-and-conversion-to-mask/12782/13 "2021-03-07T06:14:52Z")

</div>

You don’t need to use Python, you can do everything via the graphical user interface.

To render the mandible differently, do as @pieper suggested above: go to Segment Editor module, segment the mandible, then use Mask volume effect to blank out (set to -1000) everything outside the mandible segment. You can then use volume rendering to display just the mandible.

Are you planning to resect tumor and reconstruct the mandible using fibula free flap?
