stouputils.image.segments_export 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 of segments, where each segment is either a 3D array or a tuple of (array, rgba_color).

  • skip_unique_color – 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.

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 – Path to the output .obj file (a .mtl file is created alongside it).

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

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

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

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

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

  • verbose – Verbosity level.