code: def test_downsample_scalar_field_2d(rng):
      size = 32
      sh = (size, size)
      for reduce_r in [True, False]:
          nr = size - 1 if reduce_r else size
          for reduce_c in [True, False]:
              nc = size - 1 if reduce_c else size
              image = np.empty((size, size), dtype=floating)
              image[...] = rng.integers(0, 10, np.size(image)).reshape(
                  sh
              )
  
              if reduce_r:
                  image[-1, :] = 0
              if reduce_c:
                  image[:, -1] = 0
  
              a = image[::2, ::2]
              b = image[1::2, ::2]
              c = image[::2, 1::2]
              d = image[1::2, 1::2]
  
              expected = 0.25 * (a + b + c + d)
  
              if reduce_r:
                  expected[-1, :] *= 2
              if reduce_c:
                  expected[:, -1] *= 2
  
              actual = np.array(
                  vfu.downsample_scalar_field_2d(image[:nr, :nc])
              )
              assert_array_almost_equal(expected, actual)
  
imports: import numpy
  from numpy.testing import assert_array_equal, assert_array_almost_equal, assert_almost_equal, assert_equal, assert_raises
  from scipy.ndimage import map_coordinates
  from nibabel.affines import apply_affine, from_matvec
  from dipy.core import geometry
  from dipy.align import floating
  from dipy.align import imwarp
  from dipy.align import vector_fields
  from dipy.align.transforms import regtransforms
  from dipy.align.parzenhist import sample_domain_regular
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 17 for calling a global function with example usage: test_downsample_scalar_field_2d(rng) without return types