code: def gradient_image(
      pixels, gradient_choice, automatic_smoothing, scale
  ):
      #
      # Get the smoothing parameter
      #
      if automatic_smoothing:
          # Pick the mode of the power spectrum - obviously this
          # is pretty hokey, not intended to really find a good number.
          #
          fft = numpy.fft.fft2(pixels)
          power2 = numpy.sqrt((fft * fft.conjugate()).real)
          mode = numpy.argwhere(power2 == power2.max())[0]
          scale = numpy.sqrt(numpy.sum((mode + 0.5) ** 2))
  
      gradient_magnitude = scipy.ndimage.gaussian_gradient_magnitude(
          pixels, scale
      )
  
      if gradient_choice == GRADIENT_MAGNITUDE:
          gradient_image = gradient_magnitude
      else:
          # Image data is indexed by rows and columns, with a given point located at
          # position (row, column). Here, x represents the column coordinate (at index 1)
          # and y represents the row coordinate (at index 0).
          #
          # You can learn more about image coordinate systems here:
          # http://scikit-image.org/docs/dev/user_guide/numpy_images.html#coordinate-conventions
          x = scipy.ndimage.correlate1d(
              gradient_magnitude, [-1, 0, 1], 1
          )
          y = scipy.ndimage.correlate1d(
              gradient_magnitude, [-1, 0, 1], 0
          )
          norm = numpy.sqrt(x**2 + y**2)
          if gradient_choice == GRADIENT_DIRECTION_X:
              gradient_image = 0.5 + x / norm / 2
          else:
              gradient_image = 0.5 + y / norm / 2
  
      return gradient_image
  
file_path: CellProfiler/src/frontend/cellprofiler/modules/plugins/imagetemplate.py
imports: import numpy
  import scipy.ndimage
  from cellprofiler_core.module import ImageProcessing
  from cellprofiler_core.setting import Binary
  from cellprofiler_core.setting.choice import Choice
  from cellprofiler_core.setting.text import Float
label_desc: Use image node_id 1 for calling a global function with example usage: gradient_image(pixels, gradient_choice, automatic_smoothing, scale) and returns: gradient_image