Exemple #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)
Exemple #2
0
 def test_corpus_image(self):
     # Test only the default staff detector (because projection won't detect all
     # staves).
     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))
     detector = staves.StaffDetector(image_t)
     with self.test_session() as sess:
         staves_arr, staffline_distances = sess.run(
             [detector.staves, detector.staffline_distance])
     self.assertAllClose(
         np.mean(staves_arr[:, :, 1], axis=1),  # average y position
         [
             413, 603, 848, 1040, 1286, 1476, 1724, 1915, 2162, 2354, 2604,
             2795
         ],
         atol=5)
     self.assertAllEqual(staffline_distances, [16] * 12)
Exemple #3
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]
Exemple #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)