Measure how Straight/Smooth the Borders are Rendered in an Image

I have two images:

I want to measure how straight/smooth the text borders are rendered.

First image is rendered perfectly straight, so it deserves a quality measure 1. On the other hand, the second image is rendered with a lot of varied curves (rough in a way) that is why it deserves a quality measure less than 1. How will I measure it using image processing or any Python function or any function written in other languages?

Clarification :

There are font styles that are rendered originally with straight strokes but there are also font styles that are rendered smoothly just like the cursive font styles. What I'm really after is to differentiate the text border surface roughness of the characters by giving it a quality measure.

I want to measure how straight/smooth the text borders are rendered in an image. Inversely, it can also be said that I want to measure how rough the text borders are rendered in an image.

• I have the regret to tell you that the borders are not smooth, because of the many corners of sans-serif fonts. Are you after a measure of rugosity, tortuosity? Jun 10 '20 at 16:14
• @LaurentDuval - maybe the right term is rugosity (the roughness of the text borders) . Thanks for correcting. Jun 11 '20 at 12:22
• by the way, I think the manuscript says "semper", not "lemper". Jun 13 '20 at 18:25

I'd try a very "tinkery" approach here:

1. Erode the image, so that the black area is shrunk by a fixed radius of pixels from its border (say, 5px).
2. Dilate the resulting image by the same amount
3. measure the amount of difference between original and processed image.

The idea is that something that is a locally convex border doesn't suffer through erosion (it's only shrunk) significantly, and that this erosion can be reverted by dilatation.

• Good, I think mathematical morphology has many tools for that, probably under vaguely shared denominations. Maybe evolutionary segmentation tools like snakes and level-sets could be useful, as regularity of contours are intrinseque. Jun 11 '20 at 18:25
• Thanks! By the way, what if the image contains a lot of dirt from the background and white speckles in the foreground? Will it still work? Jun 14 '20 at 1:23
• Do I have to isolate the largest black component of the character image and do erosion and dilation? Or what if there are white speckles in the foreground character itself, does erosion + dilation and the difference between the original and resultant image, measures the text border roughness? Jun 14 '20 at 1:31
• That would swap 1 and 2, and would probably work. Jun 14 '20 at 7:26
• Your design, your specific source images: you need to figure out this yourself. Sounds like a good problem for a bit of making tables, and trying out different things. Jun 14 '20 at 8:42