Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

bracket/ — Bracket/Brace Detection in Score Images

Detects bracket and brace symbols printed to the left of stave groups in orchestral scores. These symbols visually indicate which staves belong to the same instrument section (staff group). The detected bracket extents are saved alongside staff metadata to assist downstream group-alignment logic.

Files

bracket.ipynb

Exploratory notebook developing the bracket detection pipeline. The main output is a 6-panel figure visualizing each stage:

  • Panel A — Left strip of the score image (the region to the left of the first staff line), with OCR text blanked out
  • Panel B — Binary image after horizontal staff lines are removed via morphological subtraction
  • Panel C — Column-density profile (black-pixel count per column), with bracket x-ranges shaded by bracket type
  • Panel D — Result after a large vertical morphological close that bridges the inter-stave gaps, merging bracket fragments into continuous blobs
  • Panel E — Detected bracket candidate bounding boxes overlaid on the left strip
  • Panel F — Full score image with stave bounding boxes (lime) and bracket overlays color-coded by type (system_barline, system_bracket, group_bracket, brace_or_single)

bracket.py

Single-page prototype for bracket detection using an ROI (region of interest) search approach.

Algorithm:

  1. Reads the score image in grayscale and loads avg_start_x (normalized staff start x) from the YOLO staff JSON.
  2. Crops a left-side ROI from start_x - 50 to start_x + 10.
  3. Applies a vertical morphological open to enhance tall vertical strokes.
  4. Extracts connected components with height > 20 px.
  5. Filters by height range (2–5× average staff height) and max width (< 5 px).
  6. Merges fragmented detections using group_brackets_to_objects(), which does row-wise horizontal merging followed by vertical gap-bridging.
  7. For each merged bracket box, finds all stave centers that fall within the box's vertical range and records the staff index group.
  8. Saves the bracket box list and staff groupings back into the staff JSON.

Input: single score PNG + *_yolostaff.json Output: debug PNG with green rectangles + updated bracket JSON


bracket_batch.py

Batch version of bracket.py. Iterates over all *_yolostaff.json files in STAFFINFO_DIR, processes each page, and saves per-page result images and JSONs.


bracket_v2.py

Alternative single-page approach. Instead of an ROI search, uses the same get_vertical_lines() / refine_barlines() morphological pipeline as a_1_system_group.py to extract all vertical barlines first, then filters for lines near the staff start x-position.

This produces cleaner candidate lines by leveraging the full-image barline extraction rather than the narrow ROI. Uses slightly different height thresholds (up to 10× staff height vs. 5× in v1).

Input: single score PNG + *_yolostaff.json Output: debug PNG + updated bracket JSON


bracket_batch_v2.py

Batch version of bracket_v2.py. Same structure as bracket_batch.py but calls the v2 algorithm.