code: def estimate_occlusion_by_depth_and_segment(
      data,
      segments,
      x,
      y,
      num_frames,
      thresh,
      seg_id,
  ):
      """Estimate depth at a (floating point) x,y position.
  
      We prefer overestimating depth at the point, so we take the max over the 4
      neightoring pixels.
  
      Args:
        data: depth map. First axis is num_frames.
        segments: segmentation map. First axis is num_frames.
        x: x coordinate. First axis is num_frames.
        y: y coordinate. First axis is num_frames.
        num_frames: number of frames.
        thresh: Depth threshold at which we consider the point occluded.
        seg_id: Original segment id.  Assume occlusion if there's a mismatch.
  
      Returns:
        Depth for each point.
      """
  
      # need to convert from raster to pixel coordinates
      x = x - 0.5
      y = y - 0.5
  
      x0 = tf.cast(tf.floor(x), tf.int32)
      x1 = x0 + 1
      y0 = tf.cast(tf.floor(y), tf.int32)
      y1 = y0 + 1
  
      shp = tf.shape(data)
      assert len(data.shape) == 3
      x0 = tf.clip_by_value(x0, 0, shp[2] - 1)
      x1 = tf.clip_by_value(x1, 0, shp[2] - 1)
      y0 = tf.clip_by_value(y0, 0, shp[1] - 1)
      y1 = tf.clip_by_value(y1, 0, shp[1] - 1)
  
      data = tf.reshape(data, [-1])
      rng = tf.range(num_frames)[:, tf.newaxis]
      i1 = tf.gather(data, rng * shp[1] * shp[2] + y0 * shp[2] + x0)
      i2 = tf.gather(data, rng * shp[1] * shp[2] + y1 * shp[2] + x0)
      i3 = tf.gather(data, rng * shp[1] * shp[2] + y0 * shp[2] + x1)
      i4 = tf.gather(data, rng * shp[1] * shp[2] + y1 * shp[2] + x1)
  
      depth = tf.maximum(tf.maximum(tf.maximum(i1, i2), i3), i4)
  
      segments = tf.reshape(segments, [-1])
      i1 = tf.gather(segments, rng * shp[1] * shp[2] + y0 * shp[2] + x0)
      i2 = tf.gather(segments, rng * shp[1] * shp[2] + y1 * shp[2] + x0)
      i3 = tf.gather(segments, rng * shp[1] * shp[2] + y0 * shp[2] + x1)
      i4 = tf.gather(segments, rng * shp[1] * shp[2] + y1 * shp[2] + x1)
  
      depth_occluded = tf.less(tf.transpose(depth), thresh)
      seg_occluded = True
      for i in [i1, i2, i3, i4]:
          i = tf.cast(i, tf.int32)
          seg_occluded = tf.logical_and(
              seg_occluded, tf.not_equal(seg_id, i)
          )
  
      return tf.logical_or(depth_occluded, tf.transpose(seg_occluded))
  
imports: import functools
  import itertools
  import matplotlib.pyplot
  import mediapy
  import numpy
  import tensorflow.compat.v1
  import tensorflow_datasets
  from tensorflow_graphics.geometry.transformation import rotation_matrix_3d
label_desc: Use image node_id 4 for calling a global function with example usage: estimate_occlusion_by_depth_and_segment(data, segments, x, y, num_frames, thresh, seg_id) and returns: tf