In module gamera.toolkits.musicstaves.stafffinder_dalitz
Finds staff lines with the aid of long quasi black run extraction
and skeletonization.
The method works as follows:
- Extract long horizontal runs with an average blackness above
a certain threshold. The resulting filaments are vertically thinned
and among the resulting lines, those shorter than 2 * staffspace_height
are removed.
- Vertically link line segments that overlap horizontally and
have a vertical distance about staff_space_height + staff_line_height.
- Remove line segments without links and label the remaining segments
with a staff and line label. Staffs are identified as connected components
and line numbers are assinged based upon vertical link steps.
- "Melt" overlapping segments of the same staff line to one segment.
This is done by selecting the segment that is closer to a least square
fit of the total line.
- Remove staffs that have too few staff lines and remove additional
staff lines on top of and below the staff.
- If the number of lines in every staff is given:
Get the shortest of the upper and lower line and
remove it. Do this until the correct number
of staff lines is reached.
- If the number of lines is unknown: Remove every
line in a staff that is much shorter than the
maximum length in this staff.
- Remove staffline groups that overlap with other staffline groups.
From all overlapping groups the widest is kept.
Then join adjacent groups, whose distance is smaller then
2 * staffspace_height
- [Remove groups that are narrower than half the widest group.]
This step has been removed!
- Interpolate between non-overlapping skeleton segments of
the same staff line.
Authors: | Christoph Dalitz, Thomas Karsten and Florian Pose |
Method for finding the staff lines.
Signature:
find_staves(num_lines=0, window=3, blackness=60, tolerance=25, align_edges=True, join_interrupted=True, debug=0)
with
num_lines:
Number of lines per staff. If unknown, set to 0.
window and blackness:
Parameters for the extraction of long horizontal runs. Only pixels are
extracted that have an average blackness greater than blackness within
a window of the width window * staff_space_height.
tolerance:
The tolerance that is used while connecting line segments that
belong to the same staff. They may have a vertical distance of
staff_line_height + staff_space_height with a deviation of
tolerance in percent.
align_edges:
When True, staff line edges in a staff are aligned up to the
left most and right most found staff line within this staff.
debug:
0 = Be quiet.
1 = Show Progress messages.
2 = print images with prefix 'dalitzdebug' to current directory
This method fills the self.linelist attribute for further
processing.