# Flickering when using segmentation effects

**URL:** <https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380>\
**Category:** Support\
**Created:** [February 21, 2020, 1:14pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380 "2020-02-21T13:14:06Z")\
**Posts on this page:** 18\
**Page:** 1

<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:** [February 21, 2020, 1:14pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/1 "2020-02-21T13:14:06Z")

</div>

While the use of segmentation effects in python scripts in slicer works really well, it creates flickering in the Slicer GUI when using full screen mode in mac. Using windowed mode makes no flickering, only full screen mode is the problematic.

 ![capture](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/a/6aed616532bdf27e40040cc84a131fee9379ecb2.gif)

---

<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:** [February 21, 2020, 1:43pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/2 "2020-02-21T13:43:17Z")

</div>

It sounds interesting, but I don’t see anything on this “video”. Could you please upload a higher-quality screen capture video,upload it somewhere (dropbox, onedrive, youtube, …), and post the link?

---

<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:** [February 21, 2020, 2:00pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/3 "2020-02-21T14:00:48Z")

</div>

> **[capture.gif](https://drive.google.com/file/d/1MegCJzS2fSXPQFSZMOamos5dv4vsYKtW/view?usp=drive_open)**
>
> Google Drive file.

---

<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:** [February 21, 2020, 2:04pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/4 "2020-02-21T14:04:24Z")

</div>

It is difficult to make the video because the “bug” only happens in full screen mode in MAC.

---

<div class="post-metadata">

**Author:** ![hherhold](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/hherhold/32/12199_2.png) [@hherhold](https://discourse.slicer.org/u/hherhold)\
**Post date:** [February 21, 2020, 2:20pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/5 "2020-02-21T14:20:41Z")

</div>

Maybe a quick phone video? Flickering artifacts can be hard to capture on the device they’re happening on.

---

<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:** [February 21, 2020, 2:23pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/6 "2020-02-21T14:23:17Z")

</div>

I just recorded it with quickTime, then reprocess it to gif with ffmpeg. It was nasty but it worked out of the box.

---

<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:** [February 21, 2020, 2:31pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/7 "2020-02-21T14:31:55Z")

</div>

Still very bad quality recording. I don’t see any flickering, but just that the image quality of the recording is very bad. Maybe recording with your phone would be better. Replay of animated gifs is also very bad, as it is not easy to navigate the timeline (at least in the viewers that I have). It would also help if you did more things in different modules, just to see if the issue is specific to a particular module or mode.

---

<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:** [February 21, 2020, 2:47pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/8 "2020-02-21T14:47:54Z")

</div>

May you recommend me any other module that uses segment editor in python script. The video just shows that the Slicer starts creating things on the fly and then returns to original state. That does not happen in windowed mode.

---

<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:** [February 21, 2020, 2:52pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/9 "2020-02-21T14:52:50Z")

</div>

I’m not sure what you mean but Segment Editor module is a typical example of using segment editor widget in a scripted module.

Just wander around Slicer and use other modules (that behave normally) so that I can see what is normal (and just image compression artifact or bad image quality) and what is something else (a problem that you can only see in a specific module).

---

<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:** [February 21, 2020, 2:54pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/10 "2020-02-21T14:54:36Z")

</div>

Here is my code anyways, Ill try to upload a better video  
[https://gitlab.com/opendose/opendose4d/-/blob/calibration/Dosimetry4D/Calibration.py#L317](https://gitlab.com/opendose/opendose4d/-/blob/calibration/Dosimetry4D/Calibration.py#L317)

---

<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:** [February 21, 2020, 3:00pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/11 "2020-02-21T15:00:07Z")

</div>

here it is [https://drive.google.com/open?id=1uOnVNJFSrp0JG0W2HSpjV\_CjrEgRxXm2](https://drive.google.com/open?id=1uOnVNJFSrp0JG0W2HSpjV_CjrEgRxXm2)

---

<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:** [February 21, 2020, 3:12pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/12 "2020-02-21T15:12:11Z")

</div>

By “flickering” you mean that a window is shown for a second at 0:05, 0:15, and 0:30? I would comment out things first in the Python module then in the segment editor widget to see what exact step causes this.

---

<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:** [February 21, 2020, 3:17pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/13 "2020-02-21T15:17:44Z")

</div>

I have bisected the code and the specific line that causes the flickering is this one

```auto
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()

```

---

<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:** [February 21, 2020, 3:21pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/14 "2020-02-21T15:21:00Z")

</div>

OK, this is useful information. You need to continue commenting out code parts within the segment editor widget. It is more tedious, but it should lead us to the call that triggers this and then we should be able to fix it.

---

<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:** [February 21, 2020, 3:31pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/15 "2020-02-21T15:31:27Z")

</div>

> [@Alex\_Vergara](#):
>
> qMRMLSegmentEditorWidget

I have created this routine  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/2/42e039c28b938c2f6114dc689a830fd06bb2b17d.png)  
Thats everything I need to replicate the flickering. Again in windowed mode the bug does not show.

---

<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:** [February 21, 2020, 3:43pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/16 "2020-02-21T15:43:05Z")

</div>

OK. Now you need to continue commenting out code parts within the segment editor widget (in C++) to see what exactly triggers the behavior.

---

<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:** [February 21, 2020, 3:53pm UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/17 "2020-02-21T15:53:33Z")

</div>

OK, that call just do this

```auto
qMRMLSegmentEditorWidget::qMRMLSegmentEditorWidget(QWidget* _parent)
  : qMRMLWidget(_parent)
  , d_ptr(new qMRMLSegmentEditorWidgetPrivate(*this))
{
  Q_D(qMRMLSegmentEditorWidget);
  d->init();
}

```

and the init call do this

```auto
void qMRMLSegmentEditorWidgetPrivate::init()
{
  Q_Q(qMRMLSegmentEditorWidget);
  this->setupUi(q);
..........

```

So the UI is always generated even in the case we don’t need it at all. My nose tells me this is the thing but I can’t confirm without a build. I have left c++ because of this, I hate to build!

---

<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:** [February 25, 2020, 12:21am UTC](https://discourse.slicer.org/t/flickering-when-using-segmentation-effects/10380/18 "2020-02-25T00:21:15Z")

</div>

Instantiating a couple of widgets in `setupUi()` should be no problem.

We were debating when we designed segment editor if we should separate GUI and logic. Since an “editor” is inherently an interactive component, instantiating GUI classes has practically zero cost, segment editor effect classes are usually very small, and splitting classes would have resulted in many more classes, we chose not to split. That is why you always instantiate GUI widgets, even if you don’t need it.

Let us know what you find. You might even get some information without rebuilding, buy XCode Instrument, but probably you cannot avoid building Slicer if you want to experiment.
