From contours to outlines

2024-12-10

How to get a simple outline, from a large number of contours?

One thing is finding all the contours (areas) in a logo - and trust me, the Theo Contour algorithm can find a lot of them 😊 - but what we need here, is an outline around all the found contours.

Rather than have to manually merge all the contours, I went for a quick hack: What happens, if I take all the points, making up all the contours and create a convex hull of them? I used a port of JTS Topology Suite to calculate the hull, and in most cases this works really well.

Here is an example of the outline (thick green line) found for the NBC logo:

Countours and outline of the NBC logo.

If there are really fine details at the edge of a logo, a bit of it/a corner might not be inside the outline. But a lot of this has to do with downsizing the logo in the first place. So I opted for giving the user an option of performing a “finer” outlining, sacrificing speed for better handling of details.

Here is another example, this time the Home Depot logo, where the ® part of the logo is “far away” in the bottom right corner, this approach still works fine.

Outline of the Home Depot logo.

And I also always had planned to allow the user to manually tweak the outline. Either if the result was not good enough, or for some of the shapes where a lot of empty space will be “captured” inside the outline. In most cases this will not be a big issue, but if you are doing hundreds of copies of the same logo, you might want to do the manual optimization, so you can pack the logos tighter.

Are there any problems with this approach? Yes, a completely rectangular “logo” (flags begin the most obvious example).

The Icelandic flag.

Here the contour tracing will take a very long time, and not end up being very precise. But a quick “hack” is to look at the number of transparent pixels compared to the total number of pixels in the logo.

If there are none, or relatively few, transparent pixels, just create an outline that matches the dimensions of the image.

Outline of a flag after tracing.

Which works fine in a gang sheet:

Gang sheet of logos containing a flag.

Written by: Jesper Halvorsen