monochrome

Monochrome: Viewer for monochromatic video and image data.

monochrome.show(array_or_path: str | Path | ndarray, *args, **kwargs)[source]

Autodetect the type of the input and show it in Monochrome.

monochrome.show_video(array: ndarray, name: str = '', cmap: ColorMap | str = ColorMap.DEFAULT, vmin: float | None = None, vmax: float | None = None, bitrange: BitRange | str = BitRange.AUTODETECT, parent: str | None = None, opacity: OpacityFunction | None = None, comment: str = '', metadata: Dict | None = None)[source]

Play a video or open a image in Monochrome.

Arrays of dtype np.float, np.uint8, and np.uint16 are natively supported by Monochrome. Arrays with other dtypes will be converted to np.float32.

Parameters:
  • array (np.ndarray) – The video to be displayed. The array should have the shape (T, H, W) or (H, W).

  • name (str) – Name of the video

  • cmap (str or ColorMap) – Colormap for the video. One of ‘default’ (autodetect), ‘gray’, ‘hsv’, ‘blackbody’, ‘viridis’, ‘PRGn’, ‘PRGn_pos’, ‘PRGn_neg’, ‘RdBu’, ‘tab10’.

  • vmin (float) – Minimum value for the colormap. Default is None.

  • vmax (float) – Maximum value for the colormap. Default is None.

  • bitrange (str or BitRange) – Valuerange for the video. One of ‘autodetect’, ‘MinMax’ ‘uint8’, ‘uint10’, ‘uint12’, ‘uint16’, ‘float’ (for [0,1]), ‘diff’ (for [-1, 1]), ‘phase’ (for [0, 2*pi]), or ‘phase_diff (for [-pi, pi])’. Default is ‘autodetect’.

  • parent (str) – Name of the parent video

  • opacity (OpacityFunction) – Opacity function for alpha blending if video is a layer. One of ‘linear’, ‘linear_r’, ‘centered’, 1.0, 0.75, 0.5, 0.25, or 0.0. Default is opacity=1.0.

  • comment (str) – Comment to be displayed

  • metadata (dict) – Additional metadata to be displayed

monochrome.show_image(array: ndarray, name: str = '', cmap: ColorMap | str = ColorMap.DEFAULT, vmin: float | None = None, vmax: float | None = None, bitrange: BitRange | str = BitRange.AUTODETECT, parent: str | None = None, opacity: OpacityFunction | None = None, comment: str = '', metadata: Dict | None = None)[source]

Show an image in Monochrome.

Alias for show_video().

monochrome.show_layer(array: ndarray, name: str = '', parent: str | None = None, opacity: OpacityFunction | None = None, **kwargs)[source]

Add a layer to the parent video in Monochrome.

Parameters:
  • array (np.ndarray) – The layer to be displayed. The array should have the shape (T, H, W) or (H, W).

  • name (str) – Name of the layer

  • parent (str) – Name of the parent video, if None the last loaded video will be used

  • opacity (OpacityFunction) – Opacity function for alpha blending. One of ‘linear’, ‘linear_r’, ‘centered’, 1.0, 0.75, 0.5, 0.25, or 0.0. Default is opacity=1.0.

  • kwargs (dict) – Additional arguments to be passed to show_video()

monochrome.show_points(points, name: str = '', parent: str | None = None, color=None, point_size: float | None = None)[source]

Show a list of points for each frame in Monochrome.

Parameters:
  • points (List[List[Tuple[float, float]]]) – A list of list of points (x, y). The outer list elements are the frames, the inner list is the list of points for a specific frame.

  • name (str) – Optional description

  • parent (str) – Name of the video onto which the points will be displayed. If none is given the last loaded video will be used.

  • color (str or tuple) – Matplotlib color (either string like ‘black’ or rgba tuple)

  • point_size (float) – Size of points in image pixels

monochrome.show_file(filepath: str | Path)[source]

Load a file in Monochrome.

Parameters:

filepath (str or Path) – Path to the file to be loaded

monochrome.show_files(paths: List[str | Path])[source]

Load multiple files in Monochrome.

Parameters:

paths (List[str or Path]) – List of paths to the files to be loaded

monochrome.show_flow(flow_uv: ndarray, name: str = '', parent: str | None = None, color=None)[source]

Visualize optical flow in Monochrome.

Parameters:
  • flow_uv (np.ndarray) – Optical flow field of shape (T, H, W, 2)

  • name (str) – Name of the flow

  • parent (str) – Name of the parent video, if None the last loaded video will be used

  • color (str or tuple) – Matplotlib color (either string like ‘black’ or rgba tuple)

monochrome.launch(speed: float | None = None, display_fps: int | None = None, scale: float | None = None, fliph: bool = False, flipv: bool = False, **kwargs)

Start bundled Monochrome executable with the given settings.

monochrome.export_video(filepath, name='', fps=30, t_start=0, t_end=-1, description='', close_after_completion=False)[source]

Export a video displayed in Monochrome to a .mp4 file.

Note

Monochrome exports the video as rendered in the window, i.e. the video will have the same resolution as the video window and all the layers/points/… will be merged into a single video.

Parameters:
  • filepath (str) – Path to the output .mp4 file

  • name (str) – Name of the video to be exported

  • fps (int) – Frames per second of the output video

  • t_start (int) – Start frame of the output video

  • t_end (int) – End frame of the output video, -1 for the last frame

  • description (str) – Description of the video to embed in the .mp4 file

  • close_after_completion (bool) – Close the video in Monochrome after the export is completed

monochrome.close_video(name='')[source]

Close a video in Monochrome.

Parameters:

name (str) – Name of the video to be closed. If empty, the last loaded video will be closed.

monochrome.close_all_videos()[source]

Close all videos currently open in Monochrome.

monochrome.set_playback_speed(speed: float)[source]

Set the playback speed for all videos in Monochrome.

Parameters:

speed (float) – Playback speed. 1.0 is normal speed, 0.0 is paused, 2.0 is double speed, etc.

monochrome.quit()[source]

Quit Monochrome, terminating the process.

enum monochrome.BitRange(value)[source]

Bases: IntEnum

Member Type:

int

Valid values are as follows:

AUTODETECT = <BitRange.AUTODETECT: 0>
MINMAX = <BitRange.MINMAX: 1>
UINT8 = <BitRange.UINT8: 2>
UINT10 = <BitRange.UINT10: 3>
UINT12 = <BitRange.UINT12: 4>
UINT16 = <BitRange.UINT16: 5>
FLOAT = <BitRange.FLOAT: 6>
DIFF = <BitRange.DIFF: 7>
PHASE = <BitRange.PHASE: 8>
PHASE_DIFF = <BitRange.PHASE_DIFF: 9>
INT8 = <BitRange.INT8: 10>
enum monochrome.ColorMap(value)[source]

Bases: IntEnum

Member Type:

int

Valid values are as follows:

DEFAULT = <ColorMap.DEFAULT: 0>
GRAY = <ColorMap.GRAY: 1>
HSV = <ColorMap.HSV: 2>
BLACKBODY = <ColorMap.BLACKBODY: 3>
VIRIDIS = <ColorMap.VIRIDIS: 4>
PRGN = <ColorMap.PRGN: 5>
PRGN_POS = <ColorMap.PRGN_POS: 6>
PRGN_NEG = <ColorMap.PRGN_NEG: 7>
RDBU = <ColorMap.RDBU: 8>
TAB10 = <ColorMap.TAB10: 9>
TURBO = <ColorMap.TURBO: 10>
CMOCEAN_PHASE = <ColorMap.CMOCEAN_PHASE: 11>
enum monochrome.OpacityFunction(value)[source]

Bases: IntEnum

Member Type:

int

Valid values are as follows:

NONE = <OpacityFunction.NONE: 0>
LINEAR = <OpacityFunction.LINEAR: 1>
LINEAR_R = <OpacityFunction.LINEAR_R: 2>
CENTERED = <OpacityFunction.CENTERED: 3>
FIXED_100 = <OpacityFunction.FIXED_100: 4>
FIXED_75 = <OpacityFunction.FIXED_75: 5>
FIXED_50 = <OpacityFunction.FIXED_50: 6>
FIXED_25 = <OpacityFunction.FIXED_25: 7>
FIXED_0 = <OpacityFunction.FIXED_0: 8>