📄 Technical report: Inkcadence: Browser-Only Personal Handwriting Rendering from Phone Photos with Classical Image Analysis and a Compact Character CNN (Zenodo, DOI 10.5281/zenodo.24689131) · Code: github.com/mafzalkalwardev/inkcadence
Most "write in my handwriting" tools send your samples to a server and run a neural network there. I wanted the opposite: a static web page that learns your handwriting from phone photos and never uploads them.
That's Inkcadence (MIT). You give it photos of your writing, and it renders text you type in your own hand: same slant, ink colours and letterforms. Everything runs on your device.
This post explains how the pipeline works and what the test suite does (and doesn't) prove.
The ground rules
The repository has a few invariants that shaped every design decision:
- Everything runs on the device. No backend, no requests carrying user content, no third-party analytics.
- Output uses only your own glyphs. A missing character is built from your other letters or named clearly. It never silently falls back to a font.
- Photos never go into saved hands, exports or logs.
- Every exported page is labelled as AI-assisted handwriting.
Three ways to collect your letters
1. The letter sheet
Print an A4 sheet of boxes, one character per box, write in them, and take a photo. The sheet has four corner marks and a tiny bit pattern encoding the sheet type and page number. When reading the photo, Inkcadence finds the marks, computes a homography to undo perspective, warps the page flat, and crops each box. Empty boxes are recorded as missing, and you can print a "fill-in" sheet with just those characters.
2. Old pages
Got old notes or coursework? Inkcadence builds a colour-aware ink mask that keeps dark pens (including blue and green) and drops highlighter, printed rule lines and long horizontal lines. Then it finds connected components, filters them by size, aspect ratio and ink density, and labels the letter-like ones with a small CNN.
3. Known lines (no printer)
Copy four to six given sentences onto plain paper. Because the text is known, each ink mark is labelled by its position on the line, not by recognition. Scribbles and line numbers are ignored.
You can then review everything: relabel, delete, or mark your best version of each letter.
A tiny CNN that runs in plain JavaScript
The recogniser is deliberately small: three conv/batch-norm/pool blocks (32, 64, 128 channels) on 28×28 input, a 256-unit dense layer, and 62 outputs (digits plus upper- and lowercase letters). It's trained in PyTorch on EMNIST ByClass with "messy writing" augmentation, then exported to JSON and run with plain JavaScript in the browser.
It also learns from you: letters you confirm are stored as personal examples with their embeddings, and later labels are nudged by cosine similarity to them.
Measuring your style with classical image analysis
From each page, Inkcadence estimates:
- paper colour and an ink palette (pen, marker, pencil)
- an Otsu threshold
- slant, then deskews
- line spacing from projection profiles, stroke width
- style stats: x-height, letter and word spacing, baseline wobble
A pen used for larger text gets the heading role, so headings come out in your heading pen at your heading size.
Filling gaps without faking it
If your samples are missing a letter, generate.js builds it from letters you do have: m from two overlapped ns, u from a flipped n, b from a mirrored d, and so on. Generated glyphs are marked as such. If no recipe applies, Inkcadence stops and tells you which character is missing instead of substituting a font.
Rendering: controlled randomness
Real handwriting never repeats exactly. The renderer picks among your variants of each letter (avoiding the same one twice in a row), applies a small kerning table, and adds bounded variation in size, rotation and baseline drift scaled by your measured wobble. The randomness comes from a seeded xorshift32 generator, so the same seed gives the same page.
Exports are PNG and PDF. Every PNG carries a tEXt note ("AI-assisted handwriting") and the PDF carries the same subject. A visible footer is on by default. You can hide the footer, but the embedded note stays.
What the tests show (honestly)
I ran the full suite locally (Node 24, node-canvas 3.2.3): 16 test scripts, 340 passing checks, 0 failures. Some highlights:
| Check | Result |
|---|---|
| Letter-sheet boxes extracted correctly from a simulated phone photo | 121/121 |
| Empty boxes recorded as missing | 29/29 |
| Spot-checked harvest labels on a sample page | 39/39 |
| Same check on a second page, using the first page's confirmed letters | 31/31 |
| Lowercase letters labelled from copied known lines | 57/63 (90.5%) |
Important caveat: every image fixture is synthetic, generated from handwriting-style and italic fonts with simulated skew and shadows. These are regression checks, not accuracy numbers for real handwriting. Real handwriting stays out of the repo unless its writer consents.
Limitations and responsible use
- Cursive defeats connected-component harvesting (use the known-lines path).
- Letters are placed, not joined, and the kerning table is English-only.
- The
.inkpackshare format is obfuscated, not encrypted. - Misuse: a tool that writes in someone's hand could be used to pass off machine-made pages as handwritten work or to imitate someone else. The persistent AI-assisted note and default footer help, but they can't stop printing and copying. Use it for your own words.
FAQ
Does Inkcadence upload my handwriting?
No. It is a static site. Photos are processed in your browser (partly in a Web Worker) and are never stored in saved hands or exports.
What do I need to get started?
A phone camera and either a printer (for the letter sheet), some old handwritten pages, or plain paper to copy a few given sentences.
Is it a neural handwriting generator?
Not in the GAN or transformer sense. It reuses your own letter images, measures your style with classical image analysis, and uses a small CNN only to label letters.
How accurate is it on real handwriting?
That hasn't been measured yet. The test suite uses synthetic images. An evaluation on consented real samples is the next step.
Why is there an "AI-assisted" note on exports?
Transparency. The note is embedded in every PNG and PDF, and a visible footer is on by default.
Can I share my hand with another device?
Yes, as an .inkpack export with photos stripped. Imported packs are treated as untrusted input.
I'm Muhammad Afzal Kalwar, a Rust and Python automation engineer and founder of INDUS Web Agency in Islamabad. The full technical report is on Zenodo: doi.org/10.5281/zenodo.24689131. Code: github.com/mafzalkalwardev/inkcadence.
