code: def plot_anat_3d(
      anat=None,
      anat_affine=None,
      scale=1,
      sulci_opacity=0.5,
      gyri_opacity=0.3,
      opacity=None,
      skull_percentile=78,
      wm_percentile=79,
      outline_color=None,
  ):
      """3D anatomical display
  
      Parameters
      ----------
      skull_percentile : float, optional
          The percentile of the values in the image that delimit the skull from
          the outside of the brain. The smaller the fraction of you field of view
          is occupied by the brain, the larger this value should be.
      wm_percentile : float, optional
          The percentile of the values in the image that delimit the white matter
          from the grey matter. Typical this is skull_percentile + 1
      """
      # Late import to avoid triggering wx imports before needed.
      try:
          from mayavi import mlab
      except ImportError:
          # Try out old install of Mayavi, with namespace packages
          from enthought.mayavi import mlab
      fig = mlab.gcf()
      disable_render = fig.scene.disable_render
      fig.scene.disable_render = True
      if anat is None:
          anat, anat_affine, anat_max = _AnatCache.get_anat()
          anat_blurred = _AnatCache.get_blurred()
          skull_threshold = 4800
          inner_threshold = 5000
          upper_threshold = 7227.8
      else:
          from scipy import ndimage
  
          # XXX: This should be in a separate function
          voxel_size = np.sqrt((anat_affine[:3, :3] ** 2).sum() / 3.0)
          skull_threshold = stats.scoreatpercentile(
              anat.ravel(), skull_percentile
          )
          inner_threshold = stats.scoreatpercentile(
              anat.ravel(), wm_percentile
          )
          upper_threshold = anat.max()
          anat_blurred = ndimage.gaussian_filter(
              (
                  ndimage.morphology.binary_fill_holes(
                      ndimage.gaussian_filter(
                          (anat > skull_threshold).astype(np.float64),
                          6.0 / voxel_size,
                      )
                      > 0.5
                  )
              ).astype(np.float64),
              2.0 / voxel_size,
          ).T.ravel()
  
      if opacity is None:
          try:
              from tvtk.api import tvtk
          except ImportError:
              # Try out old install of Mayavi, with namespace packages
              from enthought.tvtk.api import tvtk
          version = tvtk.Version()
          if (version.vtk_major_version, version.vtk_minor_version) < (
              5,
              2,
          ):
              opacity = 0.99
          else:
              opacity = 1
      ###########################################################################
      # Display the cortical surface (flattenned)
      anat_src = affine_img_src(
          anat, anat_affine, scale=scale, name="Anat"
      )
  
      anat_src.image_data.point_data.add_array(anat_blurred)
      anat_src.image_data.point_data.get_array(1).name = "blurred"
      anat_src.image_data.point_data.update()
      anat_blurred = mlab.pipeline.set_active_attribute(
          anat_src, point_scalars="blurred"
      )
  
      anat_blurred.update_pipeline()
      # anat_blurred = anat_src
  
      cortex_surf = mlab.pipeline.set_active_attribute(
          mlab.pipeline.contour(anat_blurred), point_scalars="scalar"
      )
  
      # XXX: the choice in vmin and vmax should be tuned to show the
      # sulci better
      cortex = mlab.pipeline.surface(
          cortex_surf,
          colormap="copper",
          opacity=opacity,
          vmin=skull_threshold,
          vmax=inner_threshold,
      )
      cortex.enable_contours = True
      cortex.contour.filled_contours = True
      cortex.contour.auto_contours = False
      cortex.contour.contours = [0, inner_threshold, upper_threshold]
      # cortex.actor.property.backface_culling = True
      # XXX: Why do we do 'frontface_culling' to see the front.
      cortex.actor.property.frontface_culling = True
  
      cortex.actor.mapper.interpolate_scalars_before_mapping = True
      cortex.actor.property.interpolation = "flat"
  
      # Add opacity variation to the colormap
      cmap = (
          cortex.module_manager.scalar_lut_manager.lut.table.to_array()
      )
      cmap[128:, -1] = gyri_opacity * 255
      cmap[:128, -1] = sulci_opacity * 255
      cortex.module_manager.scalar_lut_manager.lut.table = cmap
  
      if outline_color is not None:
          outline = mlab.pipeline.iso_surface(
              anat_blurred,
              contours=[0.4],
              color=outline_color,
              opacity=0.9,
          )
          outline.actor.property.backface_culling = True
  
      fig.scene.disable_render = disable_render
      return cortex
  
file_path: nipy/nipy/labs/viz_tools/maps_3d.py
imports: import os
  import tempfile
  import numpy
  from scipy import stats
  from .anat_cache import _AnatCache, mni_sform, mni_sform_inv
  from .coord_tools import coord_transform
label_desc: Use image node_id 4 for calling a global function with example usage: plot_anat_3d(anat, anat_affine, scale, sulci_opacity, gyri_opacity, opacity, skull_percentile, wm_percentile, outline_color) and returns: cortex