extract_mesh_from_mask#

brainglobe_atlasapi.atlas_generation.mesh_utils.extract_mesh_from_mask(volume, obj_filepath=None, threshold=0.5, smooth=False, mcubes_smooth=False, closing_n_iters=8, decimate_fraction=0.6, use_marching_cubes=False, extract_largest=False, origin=None)[source]#

Return a vedo mesh actor with just the outer surface of a binary mask volume. It’s faster though less accurate than extract_mesh_from_mask.

Parameters:
  • obj_filepath (str or Path object) – path to where the .obj mesh file will be saved

  • volume (3d np.ndarray)

  • threshold (float) – min value to threshold the volume for isosurface extraction. Ignored when mcubes_smooth is True.

  • smooth (bool) – if True the surface mesh is smoothed

  • use_marching_cubes (bool:) – if True scikit-image’s marching cubes is used to extract the volume’s surface instead of vedo. The mesh is not capped where the mask touches the volume border.

  • mcubes_smooth (bool,) – if True the mask’s surface is smoothed before applying marching cubes, with constrained smoothing (Lempitsky, 2010), or a Gaussian filter for volumes larger than 500**3 voxels. Only used when use_marching_cubes is True.

  • closing_n_iters (int) – number of iterations of closing morphological operation. set to None to avoid applying morphological operations

  • decimate_fraction (float in range [0, 1].) – What fraction of the original number of vertices is to be kept. EG .5 means that 50% of the vertices are kept, the others are removed.

  • extract_largest (bool) – If True only the largest region are extracted. It can cause issues for bilateral regions as only one will remain

  • origin (sequence of int or None) – Voxel index of volume[0, 0, 0] within a larger volume, so a cropped mask yields the same vertex coordinates as the uncropped one. Ignored when use_marching_cubes is True.