# Path: moonlight/util/functional_ops.py
# def flat_map_fn(fn, elems, dtype=None):
#   def compute(i, results):
# 
# Path: moonlight/util/memoize.py
# class MemoizedFunction(object):
#   def __init__(self, function):
#   def __call__(self, *args):
# 
# Path: moonlight/util/segments.py
# class SegmentsMode(enum.Enum):
#   STARTS = 1
#   CENTERS = 2
# def true_segments_1d(segments,
#                      mode=SegmentsMode.CENTERS,
#                      max_gap=0,
#                      min_length=0,
#                      name=None):
# def _segments_1d(values, mode, name=None):
#     def do_segments(values):
#     def empty_segments():
# def peaks(values, minval=None, invalidate_distance=0, name=None):
#     def loop_condition(_, current_peaks):
#     def loop_body(accepted_peaks, current_peaks):
# 
# Path: moonlight/vision/images.py
# def translate(image, x, y):
# 
# Path: moonlight/vision/morphology.py
# def binary_erosion(image, n):
# def binary_dilation(image, n):
# def _repeated_morphological_op(float_image, binary_op, n):
#   def body(i, image):
# def _single_morphological_op(float_image, binary_op):


import numpy as np
import tensorflow as tf
from moonlight.util import functional_ops
from moonlight.util import memoize
from moonlight.util import segments
from moonlight.vision import images
from moonlight.vision import morphology
    """Returns the list of verticals tensors to be computed.

    Returns:
      A list of Tensors.
    """
    return [self.lines]


def _horizontal_filter(image, staffline_thickness):
  """The vertical lines horizontal filter.

  A black pixel in a vertical line must have a white pixel
  `2 * staffline_thickness` pixels away, on the left and/or right.

  Args:
    image: 2D thresholded boolean image with black pixels as True.
    staffline_thickness: The estimated staffline thickness, in pixels.

  Returns:
    The filtered image.
  """
  # images.translate() requires a float image. Unlike the convention (255 or 1.0
  # for white), the image is already thresholded here, so 1.0 is black and 0.0
  # is white.
  float_image = tf.cast(image, tf.float32)
  gap = staffline_thickness * 2
  return tf.logical_and(
      image,
      tf.logical_or(
          tf.equal(images.translate(float_image, -gap, 0), 0),

# Path: moonlight/util/functional_ops.py
# def flat_map_fn(fn, elems, dtype=None):
#   def compute(i, results):
# 
# Path: moonlight/util/memoize.py
# class MemoizedFunction(object):
#   def __init__(self, function):
#   def __call__(self, *args):
# 
# Path: moonlight/util/segments.py
# class SegmentsMode(enum.Enum):
#   STARTS = 1
#   CENTERS = 2
# def true_segments_1d(segments,
#                      mode=SegmentsMode.CENTERS,
#                      max_gap=0,
#                      min_length=0,
#                      name=None):
# def _segments_1d(values, mode, name=None):
#     def do_segments(values):
#     def empty_segments():
# def peaks(values, minval=None, invalidate_distance=0, name=None):
#     def loop_condition(_, current_peaks):
#     def loop_body(accepted_peaks, current_peaks):
# 
# Path: moonlight/vision/images.py
# def translate(image, x, y):
# 
# Path: moonlight/vision/morphology.py
# def binary_erosion(image, n):
# def binary_dilation(image, n):
# def _repeated_morphological_op(float_image, binary_op, n):
#   def body(i, image):
# def _single_morphological_op(float_image, binary_op):


# Path: moonlight/structure/verticals.py
import numpy as np
import tensorflow as tf
from moonlight.util import functional_ops
from moonlight.util import memoize
from moonlight.util import segments
from moonlight.vision import images
from moonlight.vision import morphology

    """Returns the list of verticals tensors to be computed.

    Returns:
      A list of Tensors.
    """
    return [self.lines]


def _horizontal_filter(image, staffline_thickness):
  """The vertical lines horizontal filter.

  A black pixel in a vertical line must have a white pixel
  `2 * staffline_thickness` pixels away, on the left and/or right.

  Args:
    image: 2D thresholded boolean image with black pixels as True.
    staffline_thickness: The estimated staffline thickness, in pixels.

  Returns:
    The filtered image.
  """
  # images.translate() requires a float image. Unlike the convention (255 or 1.0
  # for white), the image is already thresholded here, so 1.0 is black and 0.0
  # is white.
  float_image = tf.cast(image, tf.float32)
  gap = staffline_thickness * 2
  return tf.logical_and(
      image,
      tf.logical_or(
          tf.equal(images.translate(float_image, -gap, 0), 0),

          tf.equal(images.translate(float_image, gap, 0), 0)))