coord2region.utils.image_utils#

Utility functions for generating simple brain images.

This module currently exposes generate_mni152_image(), which creates a static visualization of a spherical region overlaid on the MNI152 template using Nilearn’s plotting utilities. The resulting image is returned as PNG bytes so it can be saved or embedded by callers without touching the filesystem.

Functions#

generate_mni152_image(→ bytes)

Return a PNG image of a sphere drawn on the MNI152 template.

add_watermark(→ bytes)

Overlay a semi-transparent watermark onto image bytes.

build_side_by_side_panel(, padding)

Return a labelled side-by-side comparison panel.

Module Contents#

coord2region.utils.image_utils.generate_mni152_image(coord: Sequence[float], radius: int = 6, cmap: str = 'autumn') bytes[source]#

Return a PNG image of a sphere drawn on the MNI152 template.

Parameters:
  • coord (sequence of float) – MNI coordinate (x, y, z) in millimetres.

  • radius (int, optional) – Radius of the sphere in millimetres. Defaults to 6.

  • cmap (str, optional) – Matplotlib colormap used for the overlay. Defaults to "autumn".

Returns:

PNG-encoded image bytes representing the sphere on the MNI152 template.

Return type:

bytes

coord2region.utils.image_utils.add_watermark(image_bytes: bytes, text: str = 'AI approximation for illustrative purposes') bytes[source]#

Overlay a semi-transparent watermark onto image bytes.

Parameters:
  • image_bytes (bytes) – Original image encoded as bytes.

  • text (str, optional) – Watermark text to overlay. Defaults to "AI approximation for illustrative purposes".

Returns:

PNG-encoded image bytes with the watermark applied.

Return type:

bytes

coord2region.utils.image_utils.build_side_by_side_panel(left_image: bytes, right_image: bytes, *, left_title: str = 'AI-generated approximation', right_title: str = 'Nilearn reference', background_color: tuple[int, int, int] = (20, 20, 24), padding: int = 36) bytes[source]#

Return a labelled side-by-side comparison panel.

Parameters:
  • left_image (bytes) – PNG-encoded images for the left and right panels respectively.

  • right_image (bytes) – PNG-encoded images for the left and right panels respectively.

  • left_title (str, optional) – Captions rendered above the corresponding image.

  • right_title (str, optional) – Captions rendered above the corresponding image.

  • background_color (tuple[int, int, int], optional) – RGB colour applied to the canvas background. Defaults to a dark grey.

  • padding (int, optional) – Padding (in pixels) surrounding the images and text.