porescene.image module

porescene.image.frames2gif(pth_frames, pth_gif, fps=24, trim=True)[source]

Exports an animated GIF from the given frames.

The frames are encoded with the ffmpeg binary shipped with imageio-ffmpeg using a two-pass palette (palettegen / paletteuse) for good color fidelity. Frame transparency is preserved and the GIF loops indefinitely.

Parameters:
  • pth_frames (Iterator[Path]) – Ordered paths of the frame images. The animation follows this order.

  • pth_gif (Path) – Output path of the GIF file.

  • fps (int) – Playback speed in frames per second, by default 24.

  • trim (bool) – If True, the transparent padding common to all frames is cropped away before encoding (see _trim_common_padding()), by default True.

Returns:

File path of the written GIF.

Return type:

Path

porescene.image.frames2mp4(pth_frames, pth_mp4, fps=24, background=(255, 255, 255), trim=True)[source]

Exports an MP4 (H.264) video from the given frames.

The frames are encoded with the ffmpeg binary shipped with imageio-ffmpeg using the libx264 codec and the yuv420p pixel format for broad player and browser compatibility. MP4 cannot store an alpha channel, so each frame is flattened onto a solid background color.

Parameters:
  • pth_frames (Iterator[Path]) – Ordered paths of the frame images. The video follows this order.

  • pth_mp4 (Path) – Output path of the MP4 file.

  • fps (int) – Playback speed in frames per second, by default 24.

  • background (tuple[int, int, int]) – RGB color the (transparent) frames are composited onto, by default white (255, 255, 255).

  • trim (bool) – If True, the transparent padding common to all frames is cropped away before encoding (see _trim_common_padding()), by default True.

Returns:

File path of the written MP4.

Return type:

Path

porescene.image.img_add_axes(pth_vis, pth_ax)[source]

Combines a visualization image with the axes image.

Return type:

Path

porescene.image.img_add_colorbar(pth_vis, pth_cb, align=CompassDirection.SOUTH, orientation=Orientation.HORIZONTAL, *, center_rendering=False)[source]

Composites the colorbar next to the visualization image.

Return type:

Path

porescene.image.img_pad(pth_img, pad=(0, 0, 0, 0), /, trim=True)[source]

Adds padding to the given image

Parameters:
  • pth_img (Path) – Path of the image file

  • pad (int | float | tuple[int | float, int | float, int | float, int | float]) – Amount of padding to add on each side (top, right, bottom, left), by default (0, 0, 0, 0)

  • trim (bool) – If True, existing whitespace gets trimmed from the image before padding gets applied, by default True

Returns:

File path of the padded image.

Return type:

Path

porescene.image.img_pp(pth_img)[source]

Visualization image post-processing

Parameters:

pth_img (Path) – Filename of the visualization image to be trimmed and axes added.

Return type:

None

porescene.image.img_side_by_side(pth_img_left, pth_img_right, pth_merged)[source]
porescene.image.img_trim(pth_img)[source]

Trims the transparent padding of an image.

Return type:

Path

porescene.image.iterate_side_by_side(pthlist_left, pthlist_right, pth_merged)[source]