A method to create offset outline around a bitmap using Inkscape

tutorial
inkscape

#1

I’ve seen folks asking how to create an outline around a bitmap (or collection of vectors) so they don’t have to cut just a rectangle. There are several tutorials already, but here’s a technique that I’ve used for bitmaps in various programs for many, many years, and I haven’t seen it posted yet. I’ve adapted it to Inkscape as that’s all the rage.

I’m using the image supplied by @Darth_Sixstring as their post prompted me to put this walk-through together.

NOTE: this technique works great for some types of images, and not so great for others. Anything with a mostly solid color background will do – text, logos, pictures like this one… But your mileage may vary. This image worked well, IMO.

  1. Starting with an empty Inkscape document, load your bitmap

  1. Select the imported image, Edit->Copy, then Edit->Paste In Place.

  2. Select the pasted image, then go to Extensions->Raster->Level… and enter the settings shown (basically just change - Black Point: 94)

  1. The resulting image will probably look bad and might show some JPEG artifacting

  1. This next step is important as we’ll discuss later on. Go to Extensions->Raster->Gaussian Blur… and set the Factor and Sigma values to high values (10-20; I used 15 here)

  1. The results should be something like this:

  1. Next, we’ll do another Level pass. So return to Extensions->Raster->Level… and use the same settings as before (it should default to your last settings)

  1. Again, your results will look bad, but you might see where we’re going

  1. Next, go to Path->Trace Bitmap and use settings like below (this might be default, I can’t recall). Once you have the settings and press “OK” you can close the Trace Bitmap window.

  1. It shouldn’t look much different, though some of the blacks might appear with sharper edges. Click outside of the page to deselect everything. Then click in a black area to re-select the top-most art, which is your traced image.

  1. Select Path->Break Apart. This will separate all of the various traced bits into individual objects. You can see the dashed-line rectangles on all the JPEG artifacts that got traced, or the white sections in the leg areas of this pic.

  1. Click again off the page to deselect everything.

  2. Click in the black area of the large area that makes up the silhouette of your image to select just that object. Here, I clicked in the bottom right corner of the black.

  3. Edit->Cut to remove this object but keep it in the clipboard. THIS IS IMPORTANT! :slight_smile: The resulting image will look about the same, but with some possibly odd artifacts around remaining small objects (again, look at the area around the legs in this pic)

  1. Click on the black image (here again I clicked in the bottom-right area) and press DELETE on your keyboard. DO NOT USE CUT. This will select and then delete the copy of the original image we applied those raster effects to. This will leave you with the original image and any remaining traced bits.

  1. Now Edit->Select All to select everything on-screen. Then, hold down SHIFT on your keyboard and click on the original image. This will DE-select the image, leaving only the stray traced bits selected. Press DELETE on your keyboard. DO NOT USE CUT.

  1. Almost done! Now, Edit->Paste in Place. This will put the traced bitmap you cut earlier back on-screen and aligned with the original image.

  1. Change the fill of this layer to something not black and partly transparent. I used a green at 50% opacity

  1. Oooooooo! Now, Path->Simplify

  1. Finally, set the Fill to None, and the Stroke (Outline) to whatever color you want (here I chose magenta).

You now have a vector outline that is offset from the image everywhere except for the borders. You can edit this outline as you see fit. Yay!

The offset amount we create can be changed by altering the amount of the gaussian blur. This can be tricky and takes some trial and error to find values that work for both your image and the desired offset.

If you were doing this technique on a color image, I would first convert a copy to grayscale, and preferably change the levels to make it as pure black-and-white as you can. You can then use this B&W version to do the outlining and align over the original color version.

Hope this helps!


Inkscape photo project question
#2

Very nice! I’ll add that to the Matrix for Inkscape. :slightly_smiling_face:


#3

Brilliant!


#4

I’m trying this, tonight. I’ve always had to go to Fusion to get things outlined the way I want. I hope this will set me on the righteous path.


#5

Very kind of you to write this up.


#6

This technique also works in Photoshop with a lot more control – using Minimum, Maximum, Median, Gaussian Blur, and (better) Levels, you can really dial in the effect you want, then magic wand select and create a path without leaving.

I used this technique, and variations of it, a lot when I used to work in the prepress industry, doing things like fixing logos that clients would fax in to have printed on their business cards.(!) Happened more than you’d care to know, even for large, well-known companies. Blur and levels can work miracles. :slight_smile:

With tighter offsets, you can separate odd-shaped foregrounds from backgrounds fairly well, though really, new Photoshop selection tools are making these techniques obsolete.

And you can always manually paint in areas that you want to add to the mask, or erase areas, before doing the bitmap trace.


#7

good write up.

for those of you using photoshop, here is a similar write-up