# Path: moonlight/structure/components.py
# class ConnectedComponentsColumns(enum.IntEnum):
# class ConnectedComponents(object):
# class ComputedComponents(object):
#   X0 = 0
#   Y0 = 1
#   X1 = 2
#   Y1 = 3
#   SIZE = 4
# def from_staff_remover(staff_remover, threshold=127):
#   def __init__(self, components):
#   def __init__(self, components):
# def get_component_bounds(image):
# def _unsorted_segment_min(data, segment_ids, num_segments):
# 
# 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.structure import components
from moonlight.vision import morphology
Beams are long, very thick, horizontal or diagonal lines that may intersect with
the staves. To detect them, we use staff removal followed by extra binary
erosion, in case the staves are not completely removed and still have extra
black pixels around a beam. We then find all of the connected components,
because each beam should now be detached from the stem, staff, and (typically)
other beams. We filter beams by minimum width. Further processing and assignment
of stems to beams is done in `beam_processor.py`.

Each beam halves the duration of each note it is atteched to by a stem.
"""
# TODO(ringw): Make Hough line segments more robust, and then use them here
# instead of connected components.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



COLUMNS = components.ConnectedComponentsColumns


class Beams(object):
  """Note beam detector."""

  def __init__(self, staff_remover, threshold=127):
    staff_detector = staff_remover.staff_detector
    image = morphology.binary_erosion(
        tf.less(staff_remover.remove_staves, threshold),
        staff_detector.staffline_thickness)

# Path: moonlight/structure/components.py
# class ConnectedComponentsColumns(enum.IntEnum):
# class ConnectedComponents(object):
# class ComputedComponents(object):
#   X0 = 0
#   Y0 = 1
#   X1 = 2
#   Y1 = 3
#   SIZE = 4
# def from_staff_remover(staff_remover, threshold=127):
#   def __init__(self, components):
#   def __init__(self, components):
# def get_component_bounds(image):
# def _unsorted_segment_min(data, segment_ids, num_segments):
# 
# 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/beams.py
import numpy as np
import tensorflow as tf
from moonlight.structure import components
from moonlight.vision import morphology

Beams are long, very thick, horizontal or diagonal lines that may intersect with
the staves. To detect them, we use staff removal followed by extra binary
erosion, in case the staves are not completely removed and still have extra
black pixels around a beam. We then find all of the connected components,
because each beam should now be detached from the stem, staff, and (typically)
other beams. We filter beams by minimum width. Further processing and assignment
of stems to beams is done in `beam_processor.py`.

Each beam halves the duration of each note it is atteched to by a stem.
"""
# TODO(ringw): Make Hough line segments more robust, and then use them here
# instead of connected components.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function



COLUMNS = components.ConnectedComponentsColumns


class Beams(object):
  """Note beam detector."""

  def __init__(self, staff_remover, threshold=127):
    staff_detector = staff_remover.staff_detector
    image = morphology.binary_erosion(
        tf.less(staff_remover.remove_staves, threshold),
        staff_detector.staffline_thickness)

    beams = components.get_component_bounds(image)