Esempio n. 1
0
 def test_roll(self):
   with self.test_session():
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), 1).eval(),
                           [0, 1, 3, 5, 7])
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), -1).eval(),
                           [3, 5, 7, 9, 0])
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), 3).eval(),
                           [0, 0, 0, 1, 3])
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), -3).eval(),
                           [7, 9, 0, 0, 0])
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), 5).eval(),
                           [0, 0, 0, 0, 0])
     assert np.array_equal(roll(tf.constant([1, 3, 5, 7, 9]), -5).eval(),
                           [0, 0, 0, 0, 0])
Esempio n. 2
0
def staff_center_filter(page):
  img = page.tensor
  compute.get_staffsize(page)
  return functools.reduce(tf.logical_and,
      [util.roll(img, -page.staff_dist*2),
       util.roll(img, -page.staff_dist),
       img,
       util.roll(img, page.staff_dist),
       util.roll(img, page.staff_dist*2),
       (
          tf.cast(util.roll(img, -page.staff_dist*2 -3) | util.roll(img, -page.staff_dist*2 + 3), tf.int32)
          + tf.cast(util.roll(img, -page.staff_dist -3) | util.roll(img, -page.staff_dist + 3), tf.int32)
          + tf.cast(util.roll(img, -3) | util.roll(img, 3), tf.int32)
          + tf.cast(util.roll(img, page.staff_dist -3) | util.roll(img, page.staff_dist + 3), tf.int32)
          + tf.cast(util.roll(img, page.staff_dist*2 -3) | util.roll(img, page.staff_dist*2 + 3), tf.int32)
       ) < 3])
Esempio n. 3
0
File: base.py Progetto: pustar/homer
def staff_center_filter(page):
    img = page.tensor
    compute.get_staffsize(page)
    return functools.reduce(tf.logical_and, [
        util.roll(img, -page.staff_dist * 2),
        util.roll(img, -page.staff_dist), img,
        util.roll(img, page.staff_dist),
        util.roll(img, page.staff_dist * 2),
        (tf.cast(
            util.roll(img, -page.staff_dist * 2 - 3)
            | util.roll(img, -page.staff_dist * 2 + 3), tf.int32) + tf.cast(
                util.roll(img, -page.staff_dist - 3)
                | util.roll(img, -page.staff_dist + 3), tf.int32) +
         tf.cast(util.roll(img, -3) | util.roll(img, 3), tf.int32) + tf.cast(
             util.roll(img, page.staff_dist - 3)
             | util.roll(img, page.staff_dist + 3), tf.int32) + tf.cast(
                 util.roll(img, page.staff_dist * 2 - 3)
                 | util.roll(img, page.staff_dist * 2 + 3), tf.int32)) < 3
    ])