code: def test_grayscale_image():
      nclasses = 4
      beta = np.float64(0.0)
  
      image = create_image()
      com = ConstantObservationModel()
      icm = IteratedConditionalModes()
  
      mu, sigmasq = com.initialize_param_uniform(image, nclasses)
      npt.assert_array_almost_equal(
          mu, np.array([0.0, 0.25, 0.5, 0.75])
      )
      npt.assert_array_almost_equal(
          sigmasq, np.array([1.0, 1.0, 1.0, 1.0])
      )
  
      neglogl = com.negloglikelihood(image, mu, sigmasq, nclasses)
      npt.assert_(neglogl[100, 100, 1, 0] != neglogl[100, 100, 1, 1])
      npt.assert_(neglogl[100, 100, 1, 1] != neglogl[100, 100, 1, 2])
      npt.assert_(neglogl[100, 100, 1, 2] != neglogl[100, 100, 1, 3])
      npt.assert_(neglogl[100, 100, 1, 1] != neglogl[100, 100, 1, 3])
  
      initial_segmentation = icm.initialize_maximum_likelihood(neglogl)
      npt.assert_(initial_segmentation.max() == nclasses - 1)
      npt.assert_(initial_segmentation.min() == 0)
  
      PLN = icm.prob_neighborhood(initial_segmentation, beta, nclasses)
      print(PLN.shape)
      npt.assert_(np.all((PLN >= 0) & (PLN <= 1.0)))
  
      if beta == 0.0:
          npt.assert_almost_equal(PLN[50, 50, 1, 0], 0.25, True)
          npt.assert_almost_equal(PLN[50, 50, 1, 1], 0.25, True)
          npt.assert_almost_equal(PLN[50, 50, 1, 2], 0.25, True)
          npt.assert_almost_equal(PLN[50, 50, 1, 3], 0.25, True)
          npt.assert_almost_equal(PLN[147, 129, 1, 0], 0.25, True)
          npt.assert_almost_equal(PLN[147, 129, 1, 1], 0.25, True)
          npt.assert_almost_equal(PLN[147, 129, 1, 2], 0.25, True)
          npt.assert_almost_equal(PLN[147, 129, 1, 3], 0.25, True)
          npt.assert_almost_equal(PLN[61, 152, 1, 0], 0.25, True)
          npt.assert_almost_equal(PLN[61, 152, 1, 1], 0.25, True)
          npt.assert_almost_equal(PLN[61, 152, 1, 2], 0.25, True)
          npt.assert_almost_equal(PLN[61, 152, 1, 3], 0.25, True)
          npt.assert_almost_equal(PLN[100, 100, 1, 0], 0.25, True)
          npt.assert_almost_equal(PLN[100, 100, 1, 1], 0.25, True)
          npt.assert_almost_equal(PLN[100, 100, 1, 2], 0.25, True)
          npt.assert_almost_equal(PLN[100, 100, 1, 3], 0.25, True)
  
      PLY = com.prob_image(image, nclasses, mu, sigmasq, PLN)
      print(PLY)
      npt.assert_(np.all((PLY >= 0) & (PLY <= 1.0)))
  
      mu_upd, sigmasq_upd = com.update_param(image, PLY, mu, nclasses)
      print(mu)
      print(mu_upd)
      npt.assert_(mu_upd[0] != mu[0])
      npt.assert_(mu_upd[1] != mu[1])
      npt.assert_(mu_upd[2] != mu[2])
      npt.assert_(mu_upd[3] != mu[3])
      print(sigmasq)
      print(sigmasq_upd)
      npt.assert_(sigmasq_upd[0] != sigmasq[0])
      npt.assert_(sigmasq_upd[1] != sigmasq[1])
      npt.assert_(sigmasq_upd[2] != sigmasq[2])
      npt.assert_(sigmasq_upd[3] != sigmasq[3])
  
      icm_segmentation, energy = icm.icm_ising(
          neglogl, beta, initial_segmentation
      )
      npt.assert_(np.abs(np.sum(icm_segmentation)) != 0)
      npt.assert_(icm_segmentation.max() == nclasses - 1)
      npt.assert_(icm_segmentation.min() == 0)
  
file_path: dipy/dipy/segment/tests/test_mrf.py
imports: import numpy
  import numpy.testing
  from dipy.data import get_fnames
  from dipy.sims.voxel import add_noise
  from dipy.segment.mrf import ConstantObservationModel, IteratedConditionalModes
  from dipy.segment.tissue import TissueClassifierHMRF
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 5 for calling a global function with example usage: test_grayscale_image() without return types