Cloudinary Blog

Automatic face-blurring in images made easy

By Nadav Soferman
Automatically Blur Faces by Using the Pixelate Effect on Photos

After our recent, somewhat technical posts, we wanted to lighten things up with Cloudinary's latest (cool) semantic image transformation feature. Keeping people privacy in photos by automatically blurring their faces. 
 

Pixelate Effect

We previously detailed in length about Cloudinary's cloud-based API for applying effects on images. We now want to introduce Cloudinary’s latest effect - pixelization.
 
 
Use it by simply setting the 'effect' parameter (or 'e' for URLs) to 'pixelate'.
 
The example below generated a 150x200 thumbnail of a Facebook profile picture and applied the pixelization effect on it.
 
.../image/facebook/w_150,h_200,c_fill,e_pixelate/zuck.jpg
 
 
 
Isn't that great? With zero effort, you've converted an image to a pixelated one before embedding it in your site.
 
 
As you can see, the pixelate effect in the example above is quite intense. You can assume greater control on the effect’s intensity by specifying the size of the pixelization squares (numeric value, in pixels). In the following example, we applied the pixelate effect using six pixel blocks on the same Facebook profile picture that was automatically retrieved from Facebook by Cloudinary. As always, the resulting image is cached and delivered through a fast CDN.
 
.../image/facebook/w_150,h_200,c_fill,e_pixelate:6/zuck.jpg
 
 
 
Same example in Ruby on Rails, Django, Node.js and PHP:
 
Copy to clipboard
<%= facebook_profile_image_tag("zuck.jpg", :effect => "pixelate:6", 
                               :width => 150, :height => 200, :crop => :fill) %gt;
Copy to clipboard
{% cloudinary "zuck.jpg" type="facebook" effect="pixelate:6" 
              width=150 height=200 crop="fill"  %}
Copy to clipboard
cloudinary.image("zuck.jpg", { type: "facebook",  effect: "pixelate:6", 
                 width: 150, height: 200, crop: "fill"})
Copy to clipboard
<?php echo facebook_profile_image_tag("zuck.jpg", array("effect" => "pixelate:6", 
                             "width" => 150, "height" => 200, "crop" => "fill")) ?>

 

Automatic Face Blurring

In the examples above we've shown how to easily pixelate a whole picture. But if we are talking about privacy, showing the original image as is and just hiding the faces is probably more useful.
 
For example, let's take the following photo, depicting a nice couple:
 
 
 
 
We can now apply the new 'pixelate_faces' effect to hide the faces of the couple in the original image. The following URL generates a 200x200 rounded cornered thumbnail that was smartly cropped based of face detection, while blurring the faces in the process.
 
 
 
 
As you can see, all parts of the images are still clear while the faces in the picture were automatically detected and pixelated by Cloudinary.
 
Same example in Ruby on Rails, Django, Node.js and PHP:
 
Copy to clipboard
<%= cl_image_tag("couple.jpg", :effect => "pixelate_faces", :width => 200, 
                 :height => 200, :crop => :thumb, :gravity => :faces, :radius => 20) %>
Copy to clipboard
{% cloudinary "couple.jpg" effect="pixelate_faces" width=200 height=200 
              crop="thumb" gravity="faces" radius=20  %}
Copy to clipboard
cloudinary.image("couple.jpg", { effect: "pixelate_faces", width: 200, 
                 height: 200, crop: "thumb", gravity: "faces", radius: 20})
Copy to clipboard
<?php echo cl_image_tag("couple.jpg", array("effect" => "pixelate_faces", 
                        "width" => 200, "height" => 200, "crop" => "thumb", 
                        "gravity" => "faces", "radius" => 20)) ?>
 
With the pixelate faces effect, you can pixelate one or more faces automatically. You can even pixelate the faces of a whole soccer team as seen in the example below. Here, Cloudinary automatically fetches the remote image from Wikimedia Commons and applies the pixelate faces effect before delivery through a CDN:
 
 
 
If you are a Spanish or a European football fan, you probably recognized all players in the picture despite the heavy pixelization :) 
 
As with the pixelate effect, the pixelate_faces effect also supports specifying the number of pixels to use for each pixelization block. The following example applies a 4-pixels effect on the same remote image for making it easier for you to recognize the players...
 
 
  

Face Blurring as Incoming Transformation 

For simplicity, all the examples given above were applied on the images on-demand. A user, looking at the image source, may craft a URL that does not include the blur. 
 
To prevent access to the original image, you should apply the pixelate effect as part of an incoming transforming while uploading the image to Cloudinary and before it is stored in the cloud for delivery. Alternatively, you can also upload images as private images as we described in a previous blog post

Summary 

We've had great fun introducing this feature, and personally think it's quite cool :)
 
Sites with user generated content, news sites and dating sites might find this feature very useful. Note however that automatic face detection is not perfect, and faces might not be detected and pixelated if the face in the picture is not clear enough. If you are going to incorporate face blurring in your system, you might want to introduce it as a part of a semi-automatic moderation system. By suggesting the automatically censored photo to a human moderator, you will save lengthy manual image processing time, while allowing the moderator to override incorrectly censored photos.
 
This feature was actually not in our original plans or to-do list. It was requested by one of our clients. Thankfully, the Cloudinary system was built with enough flexibility to introduce this new feature in no time. We were especially lucky to be able to reuse many existing building blocks - face detection, image effects support, best of breed image transformation software and more.
 
If you need a yet unsupported cloud-based image transformation for your own web application, why don't you go ahead and challenge us?

Recent Blog Posts

Our $2B Valuation

By
Blackstone Growth Invests in Cloudinary

When we started our journey in 2012, we were looking to improve our lives as developers by making it easier for us to handle the arduous tasks of handling images and videos in our code. That initial line of developer code has evolved into a full suite of media experience solutions driven by a mission that gradually revealed itself over the course of the past 10 years: help companies unleash the full potential of their media to create the most engaging visual experiences.

Read more
Direct-to-Consumer E-Commerce Requires Compelling Visual Experiences

When brands like you adopt a direct–to-consumer (DTC) e-commerce approach with no involvement of retailers or marketplaces, you gain direct and timely insight into evolving shopping behaviors. Accordingly, you can accommodate shoppers’ preferences by continually adjusting your product offering and interspersing the shopping journey with moments of excitement and intrigue. Opportunities abound for you to cultivate engaging customer relationships.

Read more
Automatically Translating Videos for an International Audience

No matter your business focus—public service, B2B integration, recruitment—multimedia, in particular video, is remarkably effective in communicating with the audience. Before, making video accessible to diverse viewers involved tasks galore, such as eliciting the service of production studios to manually dub, transcribe, and add subtitles. Those operations were costly and slow, especially for globally destined content.

Read more
Cloudinary Helps Minted Manage Its Image-Generation Pipeline at Scale

Shoppers return time and again to Minted’s global online community of independent artists and designers because they know they can count on unique, statement-making products of the highest quality there. Concurrently, the visual imagery on Minted.com must do justice to the designs into which the creators have poured their hearts and souls. For Minted’s VP of Engineering David Lien, “Because we are a premium brand, we need to ensure that every single one of our product images matches the selected configuration exactly. For example, if you pick an 18x24 art print on blue canvas, we will show that exact combination on the hero images in the PDF.”

Read more
Highlights on ImageCon 2021 and a Preview of ImageCon 2022

New year, same trend! Visual media will continue to play a monumental role in driving online conversions. To keep up with visual-experience trends and best practices, Cloudinary holds an annual conference called ImageCon, a one-of-a-kind event that helps attendees create the most engaging visual experiences possible.

Read more