code: def test_quantize_positive_2d(rng):
      # an arbitrary number of quantization levels
      num_levels = 11
      # arbitrary test image shape (must contain at least 3 elements)
      img_shape = (15, 20)
      min_positive = 0.1
      max_positive = 1.0
      epsilon = 1e-8
  
      delta = (max_positive - min_positive + epsilon) / (num_levels - 1)
      true_levels = np.zeros((num_levels,), dtype=np.float32)
      # put the intensities at the centers of the bins
      true_levels[1:] = np.linspace(
          min_positive + delta * 0.5,
          max_positive - delta * 0.5,
          num_levels - 1,
      )
      # generate a target quantization image
      true_quantization = np.empty(img_shape, dtype=np.int32)
      random_labels = rng.integers(
          0, num_levels, np.size(true_quantization)
      )
  
      # make sure there is at least one element equal to 0, 1 and num_levels-1
      random_labels[0] = 0
      random_labels[1] = 1
      random_labels[2] = num_levels - 1
      true_quantization[...] = random_labels.reshape(img_shape)
  
      # make sure additive noise doesn't change the quantization result
      noise_amplitude = np.min([delta / 4.0, min_positive / 4.0])
      sz = np.size(true_quantization)
      noise = rng.random(sz).reshape(img_shape) * noise_amplitude
      noise = noise.astype(floating)
      input_image = np.ndarray(img_shape, dtype=floating)
      # assign intensities plus noise
      input_image[...] = true_levels[true_quantization] + noise
      # preserve original zeros
      input_image[true_quantization == 0] = 0
      # preserve min positive value
      input_image[true_quantization == 1] = min_positive
      # preserve max positive value
      input_image[true_quantization == num_levels - 1] = max_positive
  
      out, levels, hist = em.quantize_positive_2d(
          input_image, num_levels
      )
      levels = np.asarray(levels)
      assert_array_equal(out, true_quantization)
      assert_array_almost_equal(levels, true_levels)
      for i in range(num_levels):
          current_bin = np.asarray(true_quantization == i).sum()
          assert_equal(hist[i], current_bin)
  
      # test num_levels<2 and input image with zeros and non-zeros everywhere
      assert_raises(ValueError, em.quantize_positive_2d, input_image, 0)
      assert_raises(ValueError, em.quantize_positive_2d, input_image, 1)
  
      out, levels, hist = em.quantize_positive_2d(
          np.zeros(img_shape, dtype=floating), 2
      )
      assert_equal(out, np.zeros(img_shape, dtype=np.int32))
  
      out, levels, hist = em.quantize_positive_2d(
          np.ones(img_shape, dtype=floating), 2
      )
      assert_equal(out, np.ones(img_shape, dtype=np.int32))
  
file_path: dipy/dipy/align/tests/test_expectmax.py
imports: import numpy
  from numpy.testing import assert_equal, assert_array_equal, assert_array_almost_equal, assert_raises
  from dipy.align import floating
  from dipy.align import expectmax
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 3 for calling a global function with example usage: test_quantize_positive_2d(rng) without return types