# SlicerMorph Animator yellow highlight on gif images

**URL:** <https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653>\
**Category:** Support\
**Created:** [May 17, 2021, 3:48pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653 "2021-05-17T15:48:30Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![tsehrhardt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tsehrhardt/32/18470_2.png) [@tsehrhardt](https://discourse.slicer.org/u/tsehrhardt)\
**Post date:** [May 17, 2021, 3:48pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/1 "2021-05-17T15:48:30Z")

</div>

I am getting this yellow highlighting when I make a gif in SlicerMorph Animator–it does not appear when I save an mp4 and I don’t see it in the Preview window.

 ![2021-05-17_11-42-59](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/3/13e16490843f07de591f9de48b7aa7f2231d57c5.jpeg)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 3:58pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/2 "2021-05-17T15:58:25Z")

</div>

I can confirm that this happens on my end too, and does not happen when I choose the gif output on screen capture. I opened a [bug](https://github.com/SlicerMorph/SlicerMorph/issues/160) for @pieper to take a quick look.

---

<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:** [May 17, 2021, 4:22pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/3 "2021-05-17T16:22:13Z")

</div>

I would say this is probably an artifact of the limited color space for gif images (only 256 distinct colors per-frame (see [this description](https://en.wikipedia.org/wiki/GIF)). I’m not sure we have a lot of control over that. Perhaps using a different background color would help.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 4:27pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/4 "2021-05-17T16:27:08Z")

</div>

But doesn’t happen when the same scene is captured with animated gif option in Screen Capture.

---

<div class="post-metadata">

**Author:** ![tsehrhardt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tsehrhardt/32/18470_2.png) [@tsehrhardt](https://discourse.slicer.org/u/tsehrhardt)\
**Post date:** [May 17, 2021, 4:33pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/5 "2021-05-17T16:33:42Z")

</div>

> [@pieper](#):
>
> Perhaps using a different background color would help.

Yes it does not appear with black or light blue backgrounds.

---

<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:** [May 17, 2021, 5:21pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/6 "2021-05-17T17:21:53Z")

</div>

The Animator uses the ScreenCaptureLogic class, so the arguments to ffmpeg will be the same, but probably the screensize influences the way the colors are selected. Since it can only have 256 unique colors the overall number of pixels in a frame will make a big difference and probably the algorithm isn’t very good at picking a good set of colors. You could check this by trying different target sizes.

Depending on your use case, apng might be a good format to use. We could add that to ScreenCapture/Animator.

> **[APNG](https://en.wikipedia.org/wiki/APNG)**
>
> Animated Portable Network Graphics (APNG) is a file format which extends the Portable Network Graphics (PNG) specification to permit animated images that work similarly to animated GIF files, while supporting 24-bit images and 8-bit transparency not available for GIFs. It also retains backward compatibility with non-animated PNG files.
> The first frame of an APNG file is stored as a normal PNG stream, so most standard PNG decoders are able to display the first frame of an APNG file. The frame spe...

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 5:51pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/7 "2021-05-17T17:51:42Z")

</div>

This might be good. Particularly if we can save this directly (without ffmpeg). On linux ffmpeg doesn’t get automatically installed like windows or mac, so that’s an issue.

---

<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:** [May 17, 2021, 6:00pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/8 "2021-05-17T18:00:53Z")

</div>

It looks like this package could be pip\_installed into Slicer and avoid ffmpeg altogether.

> **[apng](https://pypi.org/project/apng/)**
>
> A Python module to deal with APNG file.

The files will be bigger and may not be as widely supported, but the quality will be better.

---

<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:** [May 17, 2021, 6:09pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/9 "2021-05-17T18:09:55Z")

</div>

The artifact that you see is indeed what @pieper suggested above - due to gif using only 256 colors. In the ScreenCapture module’s GIF export option we apply a palette optimization step (`-filter_complex palettegen,[v]paletteuse`) and there are many other optimization and preprocessing options in ffmpeg that you can use to improve the output image quality.

However, nowadays I would avoid using gifs. You can achieve 10-100x smaller image size and much better image quality with mp4. A few years ago, mp4 was not usable at many places, but nowadays it is quite universally supported (e.g, you can include it in discourse posts, github issues, …).

---

<div class="post-metadata">

**Author:** ![tsehrhardt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tsehrhardt/32/18470_2.png) [@tsehrhardt](https://discourse.slicer.org/u/tsehrhardt)\
**Post date:** [May 17, 2021, 6:28pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/10 "2021-05-17T18:28:48Z")

</div>

As Murat pointed out, the yellow artifact doesn’t show up when generating a gif with the Screen Capture module, just with Animator.

I mostly use gifs in presentations, but I can work with mp4.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 6:33pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/11 "2021-05-17T18:33:28Z")

</div>

> [@lassoan](#):
>
> 1. A few years ago, mp4 was not usable at many places, but nowadays it is quite universally supported (e.g, you can include it in discourse posts, github issues, …).

Except the support in powerpoint is hit and miss (e.g., in presentations where you are not running the slide deck from your own computer). Unfortunately support APNG Is even worse than mp4 in powerpoint, so that’s not a total solution either.

Having reliable gif output would be useful.

---

<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:** [May 17, 2021, 6:39pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/12 "2021-05-17T18:39:38Z")

</div>

> [@tsehrhardt](#):
>
> As Murat pointed out, the yellow artifact doesn’t show up when generating a gif with the Screen Capture module, just with Animator.

Right, but did you investigate the image size issue? If you make the Animator gif output smaller it should have a different selection of colors.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 6:48pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/13 "2021-05-17T18:48:46Z")

</div>

I did try with a quick one (120x160), still happened.

---

<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:** [May 17, 2021, 6:53pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/14 "2021-05-17T18:53:39Z")

</div>

A .mp4 file can contain video stream with a wide range of compression methods. If you use a basic H.264 compression then I don’t think you will have replay issues anywhere.

> [@muratmaga](#):
>
> I did try with a quick one (120x160), still happened.

Check the command-line that is used for running ffmpeg. It should include the palette optimization step (`-filter_complex palettegen,[v]paletteuse`). You may also check if the issue is related to background color or transparent background. You can experiment with ffmpeg gif encoding options and various preprocessing filters outside of Slicer.

---

<div class="post-metadata">

**Author:** ![tsehrhardt](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tsehrhardt/32/18470_2.png) [@tsehrhardt](https://discourse.slicer.org/u/tsehrhardt)\
**Post date:** [May 17, 2021, 7:17pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/15 "2021-05-17T19:17:40Z")

</div>

I turned OFF the palette optimization under Screen Capture and got the yellow artifact, so maybe the palette optimization is not being used in Animator.

---

<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:** [May 17, 2021, 8:40pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/16 "2021-05-17T20:40:45Z")

</div>

Thanks for testing - the animator passes these arguments, but I guess the ScreenCapture settings are not being used with it.

[https://github.com/SlicerMorph/SlicerMorph/blob/master/Animator/Animator.py#L732-L737](https://github.com/SlicerMorph/SlicerMorph/blob/master/Animator/Animator.py#L732-L737)

I believe Murat is experimenting with a fix to add the flags as we speak, but in the mean time after exporting from the Animator you will have a Sequence that can be selected in ScreenCapture for output using the options available there.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [May 17, 2021, 9:35pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/17 "2021-05-17T21:35:57Z")

</div>

> [@pieper](#):
>
> but in the mean time after exporting from the Animator you will have a Sequence that can be selected in ScreenCapture for output using the options available there.

Yes, see this for more information using Screen Capture for exporting [Spr\_2021/Day\_2/SlicerAnimator/SlicerAnimator.md at main · SlicerMorph/Spr\_2021 · GitHub](https://github.com/SlicerMorph/Spr_2021/blob/main/Day_2/SlicerAnimator/SlicerAnimator.md#saving-output)

---

<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:** [May 17, 2021, 10:58pm UTC](https://discourse.slicer.org/t/slicermorph-animator-yellow-highlight-on-gif-images/17653/18 "2021-05-17T22:58:14Z")

</div>

Thanks for the report and all the help debugging 👍

This should be fixed with this PR:

> <https://github.com/SlicerMorph/SlicerMorph/pull/161>
>
> Before the Animator exposed a custom subset of encoding
> options, but these were… not optimal for gif.
> 
> Now we use the ScreenCaptureLogic to replicate the same
> list of options so there is only one place where encoding
> options are stored.
> 
> Fixes #160
