docstr: Class for multichannel Markov random field image segmentation
  using the variational EM algorithm. For details regarding the
  underlying algorithm, see:
  
  Roche et al, 2011. On the convergence of EM-like algorithms
  for image segmentation using Markov random fields. Medical
  Image Analysis (DOI: 10.1016/j.media.2011.05.002).
  
  Parameters
  ----------
  data : array-like
    Input image array
  
  mask : array-like or tuple of array
    Input mask to restrict the segmentation
  
  beta : float
    Markov regularization parameter
  
  mu : array-like
    Initial class-specific means
  
  sigma : array-like
    Initial class-specific variances
docstr_tok: ["Class","for","multichannel","Markov","random","field","image","segmentation","using","the","variational","EM","algorithm",".","For","details","regarding","the","underlying","algorithm",",","see",":","Roche","et","al",",","2011",".","On","the","convergence","of","EM-like","algorithms","for","image","segmentation","using","Markov","random","fields",".","Medical","Image","Analysis","(","DOI",":","10.1016\/j.media.2011.05.002",")",".","Parameters","--","--","--","--","--","data",":","array-like","Input","image","array","mask",":","array-like","or","tuple","of","array","Input","mask","to","restrict","the","segmentation","beta",":","float","Markov","regularization","parameter","mu",":","array-like","Initial","class-specific","means","sigma",":","array-like","Initial","class-specific","variances"]
code: def __init__(
      self,
      data,
      mask=None,
      mu=None,
      sigma=None,
      ppm=None,
      prior=None,
      U=None,
      ngb_size=NGB_SIZE,
      beta=BETA,
  ):
      """
      Class for multichannel Markov random field image segmentation
      using the variational EM algorithm. For details regarding the
      underlying algorithm, see:
  
      Roche et al, 2011. On the convergence of EM-like algorithms
      for image segmentation using Markov random fields. Medical
      Image Analysis (DOI: 10.1016/j.media.2011.05.002).
  
      Parameters
      ----------
      data : array-like
        Input image array
  
      mask : array-like or tuple of array
        Input mask to restrict the segmentation
  
      beta : float
        Markov regularization parameter
  
      mu : array-like
        Initial class-specific means
  
      sigma : array-like
        Initial class-specific variances
      """
      data = data.squeeze()
      if len(data.shape) not in (3, 4):
          raise ValueError("Invalid input image")
      if len(data.shape) == 3:
          nchannels = 1
          space_shape = data.shape
      else:
          nchannels = data.shape[-1]
          space_shape = data.shape[0:-1]
  
      self.nchannels = nchannels
  
      # Make default mask (required by MRF regularization). This will
      # be passed to the _ve_step C-routine, which assumes a
      # contiguous int array and raise an error otherwise. Voxels on
      # the image borders are further rejected to avoid segmentation
      # faults.
      if mask is None:
          mask = np.ones(space_shape, dtype=bool)
      X, Y, Z = np.where(mask)
      XYZ = np.zeros((X.shape[0], 3), dtype="intp")
      XYZ[:, 0], XYZ[:, 1], XYZ[:, 2] = X, Y, Z
      self.XYZ = XYZ
  
      self.mask = mask
      self.data = data[mask]
      if nchannels == 1:
          self.data = np.reshape(self.data, (self.data.shape[0], 1))
  
      # By default, the ppm is initialized as a collection of
      # uniform distributions
      if ppm is None:
          nclasses = len(mu)
          self.ppm = np.zeros(list(space_shape) + [nclasses])
          self.ppm[mask] = 1.0 / nclasses
          self.is_ppm = False
          self.mu = np.array(mu, dtype="double").reshape(
              (nclasses, nchannels)
          )
          self.sigma = np.array(sigma, dtype="double").reshape(
              (nclasses, nchannels, nchannels)
          )
      elif mu is None:
          nclasses = ppm.shape[-1]
          self.ppm = np.asarray(ppm)
          self.is_ppm = True
          self.mu = np.zeros((nclasses, nchannels))
          self.sigma = np.zeros((nclasses, nchannels, nchannels))
      else:
          raise ValueError("missing information")
      self.nclasses = nclasses
  
      if prior is not None:
          self.prior = np.asarray(prior)[self.mask].reshape(
              [self.data.shape[0], nclasses]
          )
      else:
          self.prior = None
  
      self.ngb_size = int(ngb_size)
      self.set_markov_prior(beta, U=U)
  
file_path: nipy/nipy/algorithms/segmentation/segmentation.py
imports: import numpy
  from ._segmentation import _interaction_energy, _ve_step
label_desc: Use image node_id 1 to create a new Segmentation object  with example: obj = Segmentation(data, mask, mu, sigma, ppm, prior, U, ngb_size, beta)