code: def gabor(
      input,
      freq,
      sigma=None,
      theta=0,
      nstds=3,
      offset=0,
      mode=None,
      constant_values=None,
      name=None,
  ):
      """
      Apply Gabor filter to image.
  
      Args:
        input: A 4-D (`[N, H, W, C]`) Tensor.
        freq: A float Tensor. Spatial frequency of the harmonic function.
          Specified in pixels.
        sigma: A scalar or 1-D `[sx, sy]` Tensor. Standard deviation in
          in x- and y-directions. These directions apply to the kernel
          before rotation. If theta = pi/2, then the kernel is rotated
          90 degrees so that sigma_x controls the vertical direction.
          If scalar, then `sigma` will be broadcasted to 1-D `[sx, sy]`.
        nstd: A scalar Tensor. The linear size of the kernel is nstds
          standard deviations, 3 by default.
        offset: A scalar Tensor. Phase offset of harmonic function in radians.
        mode: A `string`. One of "CONSTANT", "REFLECT", or "SYMMETRIC"
          (case-insensitive). Default "CONSTANT".
        constant_values: A `scalar`, the pad value to use in "CONSTANT"
          padding mode. Must be same type as input. Default 0.
        name: A name for the operation (optional).
  
      Returns:
        A 4-D (`[N, H, W, C]`) Tensor.
      """
      input = tf.convert_to_tensor(input)
  
      dtype = tf.complex128
  
      freq = tf.cast(freq, dtype.real_dtype)
      if sigma is None:
          # See http://www.cs.rug.nl/~imaging/simplecell.html
          b = 1  # bandwidth
          sigma = (
              tf.cast(
                  1.0
                  / np.pi
                  * np.sqrt(np.log(2) / 2.0)
                  * (2.0**b + 1)
                  / (2.0**b - 1),
                  dtype.real_dtype,
              )
              / freq
          )
      sigma = tf.broadcast_to(sigma, [2])
      sigma_x, sigma_y = sigma[0], sigma[1]
      theta = tf.cast(theta, dtype.real_dtype)
      nstds = tf.cast(nstds, dtype.real_dtype)
      offset = tf.cast(offset, dtype.real_dtype)
  
      x0 = tf.math.ceil(
          tf.math.maximum(
              tf.math.abs(nstds * sigma_x * tf.math.cos(theta)),
              tf.math.abs(nstds * sigma_y * tf.math.sin(theta)),
              tf.cast(1, dtype.real_dtype),
          )
      )
      y0 = tf.math.ceil(
          tf.math.maximum(
              tf.math.abs(nstds * sigma_y * tf.math.cos(theta)),
              tf.math.abs(nstds * sigma_x * tf.math.sin(theta)),
              tf.cast(1, dtype.real_dtype),
          )
      )
      y, x = tf.meshgrid(tf.range(-y0, y0 + 1), tf.range(-x0, x0 + 1))
      y, x = tf.transpose(y), tf.transpose(x)
  
      rotx = y * tf.math.sin(theta) + x * tf.math.cos(theta)
      roty = y * tf.math.cos(theta) - x * tf.math.sin(theta)
  
      g = tf.math.exp(
          -0.5 * (rotx**2 / sigma_x**2 + roty**2 / sigma_y**2)
      )
      g = g / (2 * np.pi * sigma_x * sigma_y)
      g = tf.cast(g, dtype) * tf.exp(
          tf.cast(1j, dtype)
          * tf.cast(2 * np.pi * freq * rotx + offset, dtype)
      )
  
      ksize = tf.shape(g)
  
      input = pad(input, ksize, mode, constant_values)
  
      channel = tf.shape(input)[-1]
      shape = tf.concat(
          [ksize, tf.constant([1, 1], ksize.dtype)], axis=0
      )
      g = tf.reshape(g, shape)
      shape = tf.concat(
          [ksize, [channel], tf.constant([1], ksize.dtype)], axis=0
      )
      g = tf.broadcast_to(g, shape)
  
      real = tf.nn.depthwise_conv2d(
          input,
          tf.cast(tf.math.real(g), input.dtype),
          [1, 1, 1, 1],
          padding="VALID",
      )
      imag = tf.nn.depthwise_conv2d(
          input,
          tf.cast(tf.math.imag(g), input.dtype),
          [1, 1, 1, 1],
          padding="VALID",
      )
      return tf.complex(real, imag)
  
file_path: io/tensorflow_io/python/experimental/filter_ops.py
imports: import numpy
  import tensorflow
label_desc: Use image node_id 4 for calling a global function with example usage: gabor(input, freq, sigma, theta, nstds, offset, mode, constant_values, name) and returns: tf