stouputils.image.numpy_segments_to_obj module#

add_default_colors_to_segments(
segments: list[NDArray[Any]],
skip_unique_color: bool = False,
) list[tuple[NDArray[Any], tuple[float, float, float, float]]][source]#

Ensure all segments have an associated RGB color. If a segment is provided as a bare array, assign it a default color.

Parameters:
  • segments (list) – List of segments, where each segment is either a 3D array or a tuple of (array, rgba_color).

  • skip_unique_color (bool) – If True, do not assign a unique color to the first segment.

Returns:

List of segments as (array, rgba_color) tuples, with default colors assigned where needed.

Return type:

list[tuple[NDArray, tuple[float, float, float, float]]]

numpy_segments_to_obj(
path: str,
segments: list[tuple[NDArray[Any], tuple[float, float, float, float]]] | list[NDArray[Any]],
spacing: tuple[float, float, float] = (1.0, 1.0, 1.0),
threshold: float = 0.5,
step_size: int = 1,
pad_array: bool = True,
verbose: int = 0,
) None[source]#

Generate a ‘.obj’ file from multiple segmentation arrays, each with its own color.

Parameters:
  • path (str) – Path to the output .obj file (a .mtl file is created alongside it).

  • segments (list) – List of (array, rgb_color) tuples. Each array is a 3D segmentation mask. RGB values should be floats in [0.0, 1.0].

  • spacing (tuple) – Voxel spacing along each axis, passed to marching cubes.

  • threshold (float) – Iso-surface threshold for marching cubes (0.5 for binary masks).

  • step_size (int) – Step size for marching cubes (higher = coarser mesh, faster).

  • pad_array (bool) – Pad each array with zeros to close border surfaces.

  • verbose (int) – Verbosity level.

Examples