class MusicStaves_linetracking

Last modified: October 27, 2015

Contents

MusicStaves_linetracking

In module gamera.toolkits.musicstaves.musicstaves_linetracking

This staff removal class implements the most obvious approach to staff line removal: first find the staff lines, then follow them ("line tracking") and remove pixels based upon some decision criterion.

For an overview of decision criteria, whether a pixel belongs to a symbol, see the reference below. Note that this class does not use the staff line finding method described in this reference, because we have found this "wobble" method to be rather unstable. Hence we use the more robust StaffFinder_dalitz instead. To use a different staff finding algorithm, set the property staffinder to a class derived from StaffFinder, as in the following example:

sf = StaffFinder_projections(image)
ms = MusicStaves_linetracking(image)
ms.stafffinder = sf

References:

Author:Christoph Dalitz and Florian Pose

remove_staves

Detects and removes staff lines from a music/tablature image.

The stafflines are found using self.staffinder, which is a StaffFinder_dalitz by default. When the self.stafffinder.linelist is non empty, the staff lines form this list are used; otherwise self.stafffinder.find_staves is called.

Signature:

remove_staves(crossing_symbols='all', num_lines=0, symbol_criterion='runlength')

with

crossing_symbols:
Determines which symbols crossing staff lines should be kept intact. Supported values are 'all', 'bars' or 'none'.
num_lines:
Number of lines within one staff. A value of zero for automatic detection is supported, but if you give the actual number, staff line detection will improve.
symbol_criterion:

Determines which criterion is used for identifying symbol pixels which are not to be removed (only has effect when crossing_symbols = 'all'). Options are

runlength
Removes only vertical runlengths shorter than 2 * staffline_height.
secondchord
Checks whether a second long chord different from the chord from the staff line passes a pixel (Martin and Bellissant). Only the staff skeleton pixels are tested and when the criterion is true, the entire black vertical runlength is kept, otherwise it is removed.
mask
Checks for pixels within a T-shaped mask (Clarke, Brown and Thorne)
skewedruns
Checks whether the pixel is part of a skewed run that extents beyond the staff line. The skewed runs are found by moving parallel to the staff skeleton at a distance plusminus 1.5 * staffline_height and keeping tall skewed runs through the found black pixels (see keep_tall_skewed_runs)
vectorfieldruns
Similar to skewedruns, but only skewed runs in the direction of the vector field, as computed by compute_longest_chord_vectors, are considered.
threshold:
The height up to which a horizontal black runlength crossing the skeleton is interpreted as part of the staff line. Setting to zero results in 2 * staffline_height.
debug:
Debug level. 0 = No debug messages. 1 = Only text messages. 2 = Create debug image 'musicstaves_linetracking_debug.png' in current directory.

For details and references see D Bainbridge and T C Bell: Dealing with superimposed objects in optical music recognition. 6th International Conference on Image Processing and its Applications (1997)

get_staffpos

Returns the y-positions of all staff lines at a given x-position. Can only be called after remove_staves.

Signature:

get_staffpos(x=0)

The value for x is currently ignored and the average y-positions are always returned. The return value is a list of StaffObj.