stouputils.image.numpy_to_obj module#
- numpy_to_obj(
- path: str,
- array: NDArray[np.integer | np.floating | np.bool_],
- threshold: float = 0.5,
- step_size: int = 1,
- pad_array: bool = True,
- verbose: int = 0,
Generate a ‘.obj’ file from a numpy array for 3D visualization using marching cubes.
- Parameters:
path (str) – Path to the output .obj file.
array (NDArray) – Numpy array to be dumped (must be 3D).
threshold (float) – Threshold level for marching cubes (0.5 for binary data).
step_size (int) – Step size for marching cubes (higher = simpler mesh, faster generation).
pad_array (bool) – If True, pad array with zeros to ensure closed volumes for border cells.
verbose (int) – Verbosity level (0 = no output, 1 = some output, 2 = full output).
Examples
> array = np.random.rand(64, 64, 64) > 0.5 # Binary volume > numpy_to_obj("output_mesh.obj", array, threshold=0.5, step_size=2, pad_array=True, verbose=1) > array = my_3d_data # Some 3D numpy array (e.g. human lung scan) > numpy_to_obj("output_mesh.obj", array, threshold=0.3)