Comparing vector graphics

looking for an off-the-shelf library or starting point for comparing the similarity of vector graphics.

i know solutions exist for this because it's used by digital japanese dictionaries to allow you to search by drawing a kanji (which is very similar to my usecase, so the exact same algorythem should work without much tuning)

all i've been able to find are libraries for comparing mathmatical vectors, which could work actually, but it would require a lot of normalization.

anyone know if there an easier way?

EDIT: I am also looking to compile to wasm, so pure rust solutions are preferred

There’s Detexify which is not documented particularly thoroughly but seems to use dynamic time warping to compare user supplied strokes with TeX symbols. There’s also a Rust port of it from a few years ago.

There are various algorithms for matching Kanji. Here's one in JavaScript with a working demo (I'm not aware of any good open-source implementations in Rust).

The best matching algorithms tend to be domain-specific. For example, this app pre-processes a user's handwritten character and applies Kanji-specific rules to find a best match. Simply comparing pixel values or vector parameters against a reference image or parameter set will work to some extent, but is unlikely to give very good results.

1 Like

thanks! i may just try to fork this (i was gonna use js for the ui anyways), the main thing i want different from kanji is stroke order normalizations.

I'm looking for a way to compare vector graphics for similarity, specifically in SVG format, without converting them into pixels. The goal is to identify the most similar image for a given vector graphic image by comparing the geometric paths or structure directly from the SVG data.

Are there any libraries, algorithms, or approaches you recommend for this? I'm open to any starting points or tools that focus on SVG-based similarity, whether they’re specific to certain use cases or more general-purpose.

Any advice or resources would be greatly appreciated!

shape context is one metric, idk any rust implementation tho

1 Like