SlicerMorph Animator yellow highlight on gif images

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.

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 for @pieper to take a quick look.

1 Like

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). I’m not sure we have a lot of control over that. Perhaps using a different background color would help.

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

1 Like

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

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.

1 Like

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.

It looks like this package could be pip_installed into Slicer and avoid ffmpeg altogether.

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

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, …).

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.

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.

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.

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

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.

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.

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.

1 Like

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

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.

1 Like

Yes, see this for more information using Screen Capture for exporting Spr_2021/Day_2/SlicerAnimator/SlicerAnimator.md at main · SlicerMorph/Spr_2021 · GitHub

1 Like

Thanks for the report and all the help debugging :+1:

This should be fixed with this PR:

3 Likes