code: def test_background_sampling():
      """Run on an image with background subsampling"""
      #
      # Make an image with granularity at scale 2
      #
      i, j = numpy.mgrid[0:80, 0:80]
      image = (
          (i / 4).astype(int) % 2 == (j / 4).astype(int) % 2
      ).astype(float)
      #
      # Add in a background offset
      #
      image = image * 0.5 + 0.5
      #
      # The 4x4 blocks need two erosions before disappearing. The corners
      # need an additional two erosions before disappearing
      #
      expected = [0, 99, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
      module, workspace = make_pipeline(image, None, 1, 0.5, 10, 16)
      assert isinstance(
          module,
          cellprofiler.modules.measuregranularity.MeasureGranularity,
      )
      module.run(workspace)
      m = workspace.measurements
      assert isinstance(m, cellprofiler_core.measurement.Measurements)
      for i in range(1, 16):
          feature = module.granularity_feature(i, IMAGE_NAME)
          assert feature in m.get_feature_names("Image")
          value = m.get_current_image_measurement(feature)
          numpy.testing.assert_allclose(value, expected[i - 1])
  
imports: import sys
  import numpy
  import six.moves
  import cellprofiler_core.image
  import cellprofiler.modules.measuregranularity
  import cellprofiler_core.object
  import cellprofiler_core.pipeline
  import cellprofiler_core.workspace
  import tests.frontend.modules
label_desc: Use image node_id 7 for calling a global function with example usage: test_background_sampling() without return types