class StaffFinder

Last modified: October 27, 2015

Contents

StaffFinder

In module gamera.toolkits.musicstaves.stafffinder

Virtual class providing a unified interface to staff line finding from a music/tablature image without their removal. For typical usage see the user's manual.

Important properties:

image:
The onebit image in which the staff lines are to be found. You might need to access this property, if the algorithm modifies this image during the staff finding process (e.g. by a line rectifying process).
staffline_height, staffspace_height:
Line thickness and distance of adjacent staff lines.
linelist:
Data structure in which the positional information is stored. It contains a nested list of StafflinAverage or StafflinePolygon or StafflineSkeleton objects; each sublist represents a stave system. In order to be independant of the actual internal representation do not read this variable directly from outside the class, but use the methods get_average(), get_polygon() or get_skeleton().

Note

This class cannot be used itself. You must use one of the derived classes which actually implement staff finding algorithms.

Author:Christoph Dalitz

__init__

Constructor of StaffFinder. This base constructor should be called by all derived classes.

Signature:

__init__(image, staffline_height=0, staffspace_height=0)

with

image:
Onebit or greyscale image of which the staves are to be found. StaffFinder creates a copy of the given image, so that the original image is not altered. The staff finding and possible additional operations will be done on StaffFinder.image
staffline_height:
average height of a single black staff line. When zero is given, StaffFinder computes it itself (recommended, unless you know exactly what you are doing).
staffspace_height:
average distance between adjacent lines of the same staff. When zero is given, StaffFinder computes it itself (recommended, unless you know exactly what you are doing).

find_staves

Finds staff lines from a music/tablature image.

This method is virtual and must be implemented in every derived class. Each implementation must at least support the following keyword argument:

num_lines:
Number of lines within one staff. In general it can be hard to guess this number automatically; if the staff removal algorithm supports this, a value num_lines=0 can be used to indicate that this number should be guessed automatically.

Additional algorithm specific keyword are possible of course. If num_lines cannot be chosen in the algorithm, this option must be offered nevertheless (albeit with no effect).

show_result

Returns an RGB image with the found staff lines highlighted.

Parameters:

highlight_groups:
when True (default), each stave system is underlayed in a different color. When false, only the edge points are marked in different colors, which is less visible for skeleton or average staff line representation.

get_average

Returns the average y-positions of the staff lines. When the native type of the StaffFinder implementation is not StafflineAverage, the average values are computed.

The return value is a nested list of StafflineAverage where each sublist represents one stave group.

get_polygon

Returns a polygonal approximation of the staff lines. When the native type of the StaffFinder implementation is not StafflinePolygon, the polygonal approximation is computed.

The return value is a nested list of StafflinePolygon where each sublist represents one stave group.

get_skeleton

Returns the skeleton of the staff lines. When the native type of the StaffFinder implementation is not StafflineSkeleton, the skeleton is computed.

The return value is a nested list of StafflineSkeleton where each sublist represents one stave group.