Letterform Mask Comparison
Compare two binary text masks by letterform overlap and aspect ratio.
Try an example: Identical letterforms · Compare different letterforms
How it works
Paste two binary grids representing the same visible text to compare their ink shapes and proportions. Get visual similarity, Dice overlap, intersection-over-union and an aligned SVG overlay. The score compares supplied masks; it does not identify a font or express identity confidence.
- Trim each binary grid to its ink bounds, then independently resample width and height to 128 × 48 using rectangular occupancy at a 35% threshold. Input grids are limited to 128 × 64 and must contain visible ink.
- Find the best overlap over ±2 normalized pixels in each direction. Dice = 2 × intersection / total ink; IoU = intersection / union. Clipped pixels still count in the denominator.
- Aspect similarity = exp(-3 × abs(ln(referenceAspect / candidateAspect))). Visual similarity = 85% Dice + 15% aspect similarity. Scores are rounded to two decimal places and are not probabilities.
- Use identical text and case, one straight line and comparable thresholding. The SVG shows shared ink in dark gray, reference-only ink in orange and candidate-only ink in teal, after alignment. Type Lab uses this engine to rank candidate font renderings locally.
Sources
- WhatTheFont: image matching and custom text preview inspiration (MyFonts)
- OpenType name table (Microsoft)
- OpenType character-to-glyph mapping (Microsoft)
Related tools
- Font File Inspector & Glyph Coverage – Read TTF and OTF family names, styles, metrics and Unicode character coverage.
- Binary Silhouette to SVG – Turn a binary pixel grid into exact SVG outlines with transparent holes.
How to use the Letterform Mask Comparison
Compare two binary letter shapes, read the visual similarity, Dice and IoU scores, and download an aligned overlay.
What it is for
When you try to match lettering from a photo or a scan, you eventually need a number that says how close two shapes are. This tool compares two black-and-white grids of the same text: a reference (for example, a thresholded crop of a sign) and a candidate (the same word rendered in a font you are considering). It returns a visual similarity score, Dice overlap, intersection over union and an SVG overlay that shows where the shapes agree.
Each grid is written as rows of 1 (ink) and 0 (background), up to 128 columns and 64 rows. The score compares only the two masks you supply. It does not search a font database, read text or tell you how likely it is that a font has been identified. Lumina's Type Lab uses the same engine to rank many font renderings at once.
Worked example
The reference is a pointed capital A on a 5 × 6 grid:
00100
01010
10001
11111
10001
10001
The candidate is a round-topped A with the same width and height:
01110
10001
10001
11111
10001
10001
The tool returned visual similarity 83.17 / 100, Dice overlap 80.21 %, IoU 66.95 % and aspect similarity 100 %. The best alignment shift was 0 in both directions. Both shapes are 5 × 6 pixels, so the proportions match perfectly, and the difference comes entirely from the apex: the round top adds ink where the pointed letter has none.
Comparing a grid with itself gives exactly 100 for every score and zero shift.
How to read the result
- Visual similarity is 85 % Dice overlap plus 15 % aspect similarity, on a 0–100 scale. Use it to rank candidates against the same reference.
- Dice overlap is twice the shared ink divided by the total ink of both masks. It is the main shape score.
- IoU (intersection over union) is stricter than Dice and drops faster as shapes diverge.
- Aspect similarity compares width-to-height ratios. A condensed or expanded candidate loses points here even when the strokes overlap well.
- Shift X / Shift Y show how far, in normalized pixels, the candidate was moved (up to ±2) to find the best overlap.
- The SVG overlay shows shared ink in dark gray, reference-only ink in orange and candidate-only ink in teal.
Tips and common mistakes
- Use the same text and case in both masks. "Hamburg" against "HAMBURG" compares different shapes.
- Both grids are trimmed to their ink and resampled to the same size, so extra empty margins do not matter, but stray dots do: clean specks from the reference first.
- Keep one straight line of text. Rotated or multi-line samples lower the score for every candidate.
- Threshold both images the same way: dark ink on light paper in both, not one inverted.
- Read scores relatively. 83 against 79 says one candidate is closer; it is not an 83 % chance of a match.
- Very small grids are coarse. A 5 × 6 letter is fine for an illustration, but a larger mask of a whole word separates similar fonts more reliably.
FAQ
Can this identify the font in my image?
No. It only scores two masks against each other. Render your candidate fonts yourself, or use Type Lab, which renders browser fonts and your own TTF/OTF files and ranks them with this engine.
Why does a perfect overlap not reach 100 when the sizes differ?
After trimming, both masks are stretched to the same grid. The aspect score then penalizes the different width-to-height ratio, which accounts for 15 % of the visual similarity.
What is the largest grid I can paste?
128 columns by 64 rows, with every row the same length and only 0 and 1 characters.
Can I use it from a script or an AI agent?
Yes. The tool is available through the JSON API and MCP with the same two text inputs.
Guide last updated:
For scripts and AI agents
- JSON API:
POST https://luminaletterformcompare.usefulweb.app/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://luminaletterformcompare.usefulweb.app/mcp· tool namelumina_letterform_compare
Example request
curl -s -X POST https://luminaletterformcompare.usefulweb.app/api/v1/calculate \
-H 'content-type: application/json' \
-d '{"reference":"00100\n01010\n10001\n11111\n10001\n10001","candidate":"00100\n01010\n10001\n11111\n10001\n10001"}'