How We Read 500-Year-Old Music

A step-by-step guide to the hybrid Computer Vision + AI pipeline that reads Renaissance mensural notation from manuscript images and turns it into playable digital scores.

OpenCVGemini 3.1 ProConsensus VotingABC.js

Test piece

“Qui veut avecque moy” by François Roussel

Magliabechiano XIX.57, folio 1v — Biblioteca Nazionale Centrale di Firenze

White mensural notation · C-clef on line 3 · Cut time (alla breve) · 16th century French chanson

0

The Original Manuscript

Original manuscript page — Magl. XIX.57 folio 1v

This is a page from a 16th-century French chansonnier (song book). It contains white mensural notation — the standard system for writing polyphonic European music from roughly 1450 to 1600.

Key features visible:

  • A large decorated “Q” initial (the piece begins “Qui veut avecque moy...”)
  • 5 staff systems (sets of 5 horizontal lines), each containing one line of music
  • Noteheads sitting on or between the staff lines — their vertical position determines pitch
  • French text written below each staff as lyrics
  • A C-clef at the start of each staff (tells you which line represents middle C)

The challenge: how do we read the exact pitch of each note when the noteheads are just a few pixels wide and the distinction between “on a line” vs “in a space” is ~5 pixels?

1

Contrast Enhancement

OpenCV CLAHE
CLAHE contrast enhanced image

Contrast-Limited Adaptive Histogram Equalization (CLAHE) enhances the contrast locally across the image, making the dark ink stand out more clearly from the parchment background.

The manuscript parchment has varying color and darkness across the page — CLAHE normalizes this so the staff lines and notes have consistent contrast everywhere.

2

Binarization

Otsu’s Threshold
Binary black and white image

We convert the image to pure black and white using Otsu’s thresholding— an algorithm that automatically finds the optimal threshold to separate ink from parchment.

Everything dark becomes white (ink detected), everything light becomes black (background). This gives us a clean separation of all ink marks: staff lines, noteheads, stems, text, clefs, and decorations.

3

Staff Line Extraction

Morphological Opening
Staff line mask — only horizontal lines remain

This is the crucial step. We apply a morphological opening with a very long horizontal kernel (1/6 of the image width). This keeps only features that are horizontally continuous for hundreds of pixels — meaning only the staff lines survive.

Noteheads, stems, text, clefs — all removed. Only the 5 long horizontal lines of each staff remain. This gives us the precise y-coordinate (vertical position) of every staff line on the page.

4

Row Projection Profile

NumPy
Row projection profile overlaid on the original

We sum up the white pixels in each row of the staff line mask to create a horizontal projection profile (shown as red bars on the left edge).

Each spike corresponds to a staff line. We find the peaks, then group them into sets of 5 (one staff = 5 lines). The spacing between lines within a staff should be roughly equal (~47 pixels on this page).

5

Staff Lines Detected

5 staves found
All 5 staves detected with colored lines

The algorithm found 5 staves on this page. Each staff’s 5 lines are drawn in color:

Line 5 (top) = G4Line 4 = E4Line 3 = C4 (middle C)Line 2 = A3Line 1 = F3

The pitch labels come from knowing this is a C-clef on line 3: the blue line is middle C, and we count up and down in the musical alphabet (C-D-E-F-G-A-B).

6

Isolate a Single Staff

Staff 4
Staff 4 cropped from the page

We crop out a single staff with margin above and below. This is Staff 4— which produced our best results with 6 out of 14 notes at 100% consensus.

You can see the notation clearly: a mix of hollow (white-filled) and solid (black-filled) noteheads on stems, sitting on or between the staff lines. The French text below reads: “cóme le suis d’elle soit, y’ amoureux”

7

The Grid Overlay

Key Innovation
Colored pitch reference grid overlaid on the staff

This is the breakthrough step. We zoom the staff to 2× and draw a colored pitch reference grid directly on the manuscript:

  • Solid colored lines on each staff line, labeled with pitch names
  • Dashed gray lines at each space, labeled with space pitches
  • Labels on both left and right edges for easy reference

This annotated image is what gets sent to Gemini 3.1 Pro. Instead of asking the AI to figure out the clef system and count lines, we give it a pre-computed reference grid. The AI’s job becomes: “this notehead is touching the blue line, which is labeled C4, so it’s a C4.”

We send this same image 3 times at slightly different AI temperature settings to get independent readings.

8

Consensus Voting

3 runs → majority vote
Consensus voting visualization showing confidence per note

For each note position (left to right), we take a majority vote across the 3 runs:

Green (100%) = all 3 agreeYellow (67%) = 2 of 3 agreeRed (33%) = only 1 of 3

Staff 4 result: C4 C4 B3 C4 A3 C4 E4 F4 E4 F4 G4 F4 E4 D4

The melody rises stepwise from C4 through E4 to G4, then descends through a cadential pattern F4–E4–D4 — textbook Renaissance chanson writing. The last three notes are all semibreves (long whole notes), indicating a phrase ending.

9

Digital Score & Playback

ABC.js
The final annotated staff

The consensus notes are converted to ABC notation — a text format for music — and rendered as a modern digital score using ABC.js. The viewer can:

  • Play back the melody with note highlighting
  • Choose from 8 Renaissance instruments (recorder, harpsichord, lute, organ...)
  • Adjust tempo and transpose to Renaissance pitch (A=415 Hz)
  • Compare the digital score with the original manuscript side by side

Why the Grid Overlay Works

Without grid (AI alone)

The AI gets pitch right only ~45% of the time. It can see that noteheads exist but can’t reliably distinguish between adjacent lines and spaces — a ~5 pixel difference in a 3000px image.

~45% accurate

With grid (hybrid CV+AI)

Accuracy jumps to 67–100% because the AI no longer needs to count lines. Each pitch has a colored reference — “blue line = C4”. The 2× zoom makes noteheads clearly visible.

~80% accurate

Pipeline Summary

0—Original manuscript image
1OpenCV CLAHEEnhance contrast (normalize parchment variations)
2OpenCV OtsuConvert to black/white (separate ink from background)
3OpenCV MorphologyExtract only staff lines (remove notes, text, everything else)
4NumPyFind exact y-position of each line via row projection
5AlgorithmGroup lines into staves of 5, validate spacing consistency
6OpenCVCrop individual staff with margin
7PIL / PillowDraw colored pitch grid overlay at 2× zoom
8Gemini 3.1 Pro × 3Read notes using the grid; majority vote for consensus
9ABC.jsRender as modern notation + play back in browser