Blur Faces in an Image

Automatically blur faces in an image.

code

X

how it works

Heres an image with faces:

In[1]:=
X

FindFaces returns a list of the bottom left and upper right corners of rectangles in the image that contain faces:

In[2]:=
X
Out[2]=

To blur the faces, create a mask image that corresponds to the faces by drawing disks inside each face rectangle:

In[3]:=
X
Out[3]=

The amount of blur necessary to obscure the details of a face depends on the size of the face rectangle. Calculate the number of pixels of blur in proportion to the largest dimension of a face rectangle:

In[4]:=
X
Out[4]=

This expression blurs the entire image, then picks out just the face regions using the mask computed above. The background is set to fully transparent and the face regions to fully opaque. The mask is blurred to give a gradual transition between the background and face regions.

In[5]:=
X
Out[5]=

Finally, overlaying the blurred face image on top of the original image with ImageCompose gives the face-blurred result.

In[6]:=
X
Out[6]=

Gathering up those steps and packaging them as a function yields BlurFaces:

In[7]:=
X

Test BlurFaces on a larger face to check that the proportional blur is working correctly:

In[8]:=
X
Out[8]=
In[9]:=
X
Out[9]=