3D printable stencil from binary image

Alec Jacobson

July 21, 2015

weblog/

Using code lying around in gptoolbox it was easy to whip up a little function that converts a binary image into a 3d-printable stencil.

hans hass as 3d printed stencil

I've added a new function bwstencil.m to gptoolbox. Here're the simple contents:

  imh = imfill(im,'holes');
  im = imresize(im,2,'nearest');
  [V,F] = bwmesh(~im,varargin{:});
  [V,F] = extrude(V,F);
  [V,F] = remesh_planar_patches(V,F);

Notice that I'm removing "islands" (regions that would be part of the stencil but not connected to the boundary). You can see that the eye of Hans Hass above has been removed in the stencil.

For this example, I've 3D printed the result as a proof of concept:

3d printed stencil and result

In retrospect, for this example I should have created the opposite stencil if I'm painting black on white:

hans hass as 3d printed stencil

and the physical proof:

3d printed stencil and result