コード例 #1
0
 def test_corpus_image(self):
   filename = os.path.join(tf.resource_loader.get_data_files_path(),
                           '../testdata/IMSLP00747-000.png')
   image_t = omr_image.decode_music_score_png(tf.read_file(filename))
   remover = removal.StaffRemover(staves.StaffDetector(image_t))
   with self.test_session() as sess:
     removed, image = sess.run([remover.remove_staves, image_t])
     self.assertFalse(np.allclose(removed, image))
     # If staff removal runs successfully, we should be unable to estimate the
     # staffline distance from the staves-removed image.
     est_staffline_distance, est_staffline_thickness = sess.run(
         staffline_distance.estimate_staffline_distance_and_thickness(removed))
     print(est_staffline_distance)
     self.assertAllEqual([], est_staffline_distance)
     self.assertEqual(-1, est_staffline_thickness)
コード例 #2
0
    def __init__(self,
                 num_sections=DEFAULT_NUM_SECTIONS,
                 patch_height=15,
                 patch_width=12,
                 run_options=None):
        self.num_sections = num_sections
        self.patch_height = patch_height
        self.patch_width = patch_width
        self.run_options = run_options

        self.graph = tf.Graph()
        with self.graph.as_default():
            # Identifying information for the patch.
            self.filename = tf.placeholder(tf.string, name='filename')
            self.staff_index = tf.placeholder(tf.int64, name='staff_index')
            self.y_position = tf.placeholder(tf.int64, name='y_position')

            image = image_module.decode_music_score_png(
                tf.read_file(self.filename))
            staff_detector = staves_module.StaffDetector(image)
            staff_remover = removal.StaffRemover(staff_detector)
            extractor = StafflineExtractor(staff_remover.remove_staves,
                                           staff_detector,
                                           num_sections=num_sections,
                                           target_height=patch_height)
            # Index into the staff strips array, where a y position of 0 is the center
            # element. Positive positions count up (towards higher notes, towards the
            # top of the image, and smaller indices into the array).
            position_index = num_sections // 2 - self.y_position
            self.all_stafflines = extractor.extract_staves()
            # The entire extracted horizontal strip of the image.
            self.staffline = self.all_stafflines[self.staff_index,
                                                 position_index]

            # Determine the scale for converting image x coordinates to the scaled
            # staff strip from which the patch is extracted.
            extracted_staff_strip_height = tf.shape(self.all_stafflines)[2]
            unscaled_staff_strip_heights = tf.multiply(
                DEFAULT_STAFFLINE_DISTANCE_MULTIPLE,
                staff_detector.staffline_distance)
            self.all_staffline_scales = tf.divide(
                tf.to_float(extracted_staff_strip_height),
                tf.to_float(unscaled_staff_strip_heights))
            self.staffline_scale = self.all_staffline_scales[self.staff_index]
コード例 #3
0
ファイル: __init__.py プロジェクト: wh-forker/moonlight
def create_structure(image,
                     staff_detector=staves.StaffDetector,
                     beams=beams_module.Beams,
                     verticals=verticals_module.ColumnBasedVerticals,
                     components=components_module.from_staff_remover):
    """Constructs a Structure instance.

  Constructs a staff detector and verticals with the given callables.

  Args:
    image: The image tensor.
    staff_detector: A callable that accepts the image and returns a
        StaffDetector.
    beams: A callable that accept a StaffRemover and returns a Beams.
    verticals: A callable that accepts the staff detector and returns a
        verticals impl (e.g. ColumnBasedVerticals).
    components: A callable that accepts a StaffRemover and returns a
        ConnectedComponents.

  Returns:
    The Structure instance.
  """
    with tf.name_scope('staff_detector'):
        staff_detector = staff_detector(image)
    with tf.name_scope('staff_remover'):
        staff_remover = removal.StaffRemover(staff_detector)
    with tf.name_scope('beams'):
        beams = beams(staff_remover)
    with tf.name_scope('verticals'):
        verticals = verticals(staff_detector)
    with tf.name_scope('components'):
        components = components(staff_remover)
    structure = Structure(staff_detector,
                          beams,
                          verticals,
                          components,
                          image=image,
                          staff_remover=staff_remover)
    return structure
コード例 #4
0
def pipeline_graph(png_path, staffline_height, patch_width, num_stafflines):
    """Constructs the graph for the staffline patches pipeline.

  Args:
    png_path: Path to the input png. String scalar tensor.
    staffline_height: Height of a staffline. int.
    patch_width: Width of a patch. int.
    num_stafflines: Number of stafflines to extract around each staff. int.

  Returns:
    A tensor representing the staffline patches. float32 with shape
        (num_patches, staffline_height, patch_width).
  """
    image_t = image.decode_music_score_png(tf.read_file(png_path))
    staff_detector = staves.StaffDetector(image_t)
    staff_remover = removal.StaffRemover(staff_detector)
    stafflines = tf.identity(staffline_extractor.StafflineExtractor(
        staff_remover.remove_staves,
        staff_detector,
        target_height=staffline_height,
        num_sections=num_stafflines).extract_staves(),
                             name='stafflines')
    return _extract_patches(stafflines, patch_width)