code: def median_otsu(
      input_volume,
      vol_idx=None,
      median_radius=4,
      numpass=4,
      autocrop=False,
      dilate=None,
  ):
      """Simple brain extraction tool method for images from DWI data.
  
      It uses a median filter smoothing of the input_volumes `vol_idx` and an
      automatic histogram Otsu thresholding technique, hence the name
      *median_otsu*.
  
      This function is inspired from Mrtrix's bet which has default values
      ``median_radius=3``, ``numpass=2``. However, from tests on multiple 1.5T
      and 3T data     from GE, Philips, Siemens, the most robust choice is
      ``median_radius=4``, ``numpass=4``.
  
      Parameters
      ----------
      input_volume : ndarray
          3D or 4D array of the brain volume.
      vol_idx : None or array, optional.
          1D array representing indices of ``axis=3`` of a 4D `input_volume`.
          None is only an acceptable input if ``input_volume`` is 3D.
      median_radius : int
          Radius (in voxels) of the applied median filter (default: 4).
      numpass: int
          Number of pass of the median filter (default: 4).
      autocrop: bool, optional
          if True, the masked input_volume will also be cropped using the
          bounding box defined by the masked data. Should be on if DWI is
          upsampled to 1x1x1 resolution. (default: False).
  
      dilate : None or int, optional
          number of iterations for binary dilation
  
      Returns
      -------
      maskedvolume : ndarray
          Masked input_volume
      mask : 3D ndarray
          The binary brain mask
  
      Notes
      -----
      Copyright (C) 2011, the scikit-image team
      All rights reserved.
  
      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions are
      met:
  
       1. Redistributions of source code must retain the above copyright
          notice, this list of conditions and the following disclaimer.
       2. Redistributions in binary form must reproduce the above copyright
          notice, this list of conditions and the following disclaimer in
          the documentation and/or other materials provided with the
          distribution.
       3. Neither the name of skimage nor the names of its contributors may be
          used to endorse or promote products derived from this software without
          specific prior written permission.
  
      THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
      WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
      DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
      INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
      STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
      IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      POSSIBILITY OF SUCH DAMAGE.
      """
      if len(input_volume.shape) == 4:
          if vol_idx is not None:
              b0vol = np.mean(input_volume[..., tuple(vol_idx)], axis=3)
          else:
              raise ValueError(
                  "For 4D images, must provide vol_idx input"
              )
      else:
          b0vol = input_volume
      # Make a mask using a multiple pass median filter and histogram
      # thresholding.
      mask = multi_median(b0vol, median_radius, numpass)
      thresh = otsu(mask)
      mask = mask > thresh
  
      if dilate is not None:
          cross = generate_binary_structure(3, 1)
          mask = binary_dilation(mask, cross, iterations=dilate)
  
      # Auto crop the volumes using the mask as input_volume for bounding box
      # computing.
      if autocrop:
          mins, maxs = bounding_box(mask)
          mask = crop(mask, mins, maxs)
          croppedvolume = crop(input_volume, mins, maxs)
          maskedvolume = applymask(croppedvolume, mask)
      else:
          maskedvolume = applymask(input_volume, mask)
      return maskedvolume, mask
  
file_path: dipy/dipy/segment/mask.py
imports: from warnings import warn
  import numpy
  from dipy.reconst.dti import fractional_anisotropy, color_fa
  from scipy.ndimage import median_filter
  from scipy.ndimage import binary_dilation, generate_binary_structure
label_desc: Use image node_id 5 for calling a global function with example usage: median_otsu(input_volume, vol_idx, median_radius, numpass, autocrop, dilate) and returns: maskedvolume,  mask