Skip to content

BUG/ENH: Proper gif/anim support in Report #11358

Closed

Description

@larsoner

The add_stc is big in the report:

 Source: Auditory                                          |  7.5 MB
 Source: Visual                                            |  7.6 MB
 Source: Auditory/Left                                     |  7.5 MB
 Source: Auditory/Right                                    |  7.5 MB

Trying to fix this, I noticed that image_format='gif' isn't really supported properly. It is supported (I think?) when doing report.add_image, but for Report(..., image_format='gif') things are very broken. So I propose:

  1. Add image_format='webp' format support for smaller file sizes now that matplotlib 3.6+ supports it: ENH: Add webp support to Report #11359
  2. Remove image_support='gif' support for Report as a class
  3. Add image_format=None kwarg to add_stc and add_evokeds, add_slider -- anything that supports a slider.
  4. Make image_format='gif' work properly when making a slider by selecting frames from the GIF rather than changing to different images. (This should hopefully make the images smaller, at least in some cases.)
  5. Add proper image_format='webp' support for animations by natively storing the frames in webp format -- this will hopefully be even smaller than GIF.

I already have (1) done because it's pretty easy. I'll open a PR for that, then later a separate one for 2-5 probably after doing some tests that (4) and (5) could actually save some space.

EDIT: Goal is to improve the ~60MB reports in mne-tools/mne-bids-pipeline#682

Activity

  1. larsoner commented on Dec 7, 2022

    @larsoner
    MemberAuthor

    Okay with a little bit of testing:

    kind PNGs (main) GIF webp animation webp separate
    evoked topomap slider 1.3 MB 0.66 MB 0.61 MB N/A
    stc slider 1.1 MB 0.64 MB 0.61 MB 0.69 MB

    So it looks like we're likely to get at least ~40-50% reduction in file size relative to storing plain PNGs. Going from individual webp images to a single animation is smaller (10-20%), but probably EDIT: not still worth it.

    PIL code
            from PIL import Image, ImageSequence
            from PIL import features
            assert features.check("webp_anim") is True
            sequence = []
            for ii, img in enumerate(imgs):
                sequence.append(Image.open(BytesIO(base64.b64decode(img.encode('ascii')))))
                sequence[-1].save(f'/home/larsoner/Desktop/test/test_{ii}.webp', lossless=True, method=6)
            for ext in ('webp', 'gif'):
                if ext == 'webp':
                    # should check minimize_size
                    kwargs = dict(loop=True, duration=500, lossless=True, method=6)
                else:
                    kwargs = dict(loop=True, duration=500)
                sequence[0].save(f'/home/larsoner/Desktop/test.{ext}', save_all=True, append_images=sequence[1:], **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions