Cloudinary Blog

Automatically and accurately remove red eye from user uploaded photos

Automatic and accurate red eye removal with Cloudinary

Update - April 2016: The add-on described in this post is no longer available since ReKognition terminated their services. However, all features described here are still available via a different and even better add-on by Microsoft. See Facial attribute detection with Microsoft's Face API and the Advanced facial attributes detection add-on documentation.

Red eye often happens due to the use of flash in low light conditions as the light hits the eye very quickly and into the retina. It then bounces off of the back of the eye and emits a red color due to the blood vessels there. Although more professional modern cameras and flashes generally prevent this from happening, red eye may still occur with simpler, smaller cameras (including smartphones). There are various software solutions for red eye removal available on mobile devices and desktops, some of which require manual processing to get good results.

Obviously, it would be much faster and more convenient if this process were fully automatic, especially when dealing with a bulk of images that is uploaded by your web or mobile application’s users.

Cloudinary allows developers to automate red eye removal for websites and web applications. This especially comes in handy for social networks where users want their uploaded pictures to look as good as possible when they are shared among their family and friends.

How-to perform red eye removal

Cloudinary's rich transformation capabilities allow you to further enhance users’ uploaded photos with options such as face detection-based cropping, resizing and rotating, increasing color saturation and more. With this new capability incorporated into Cloudinary’s image lifecycle management, developers can automate red eye removal by setting the effect parameter within Cloudinary's dynamic transformation URLs to redeye. This enables smart red eye removal algorithms to be automatically applied on-the-fly to uploaded images.  

In the example below, the image on the left shows a scaled down version of an original image with red eyes and the image on the right shows a scaled down version of the original image with Cloudinary’s red eye removal feature dynamically applied.

Ruby:
Copy to clipboard
cl_image_tag("itaib_redeye_msjmif.jpg", :effect=>"redeye")
PHP v1:
Copy to clipboard
cl_image_tag("itaib_redeye_msjmif.jpg", array("effect"=>"redeye"))
PHP v2:
Copy to clipboard
(new ImageTag('itaib_redeye_msjmif.jpg'))
  ->effect(Effect::redEye());
Python:
Copy to clipboard
CloudinaryImage("itaib_redeye_msjmif.jpg").image(effect="redeye")
Node.js:
Copy to clipboard
cloudinary.image("itaib_redeye_msjmif.jpg", {effect: "redeye"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().effect("redeye")).imageTag("itaib_redeye_msjmif.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('itaib_redeye_msjmif.jpg', {effect: "redeye"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("itaib_redeye_msjmif.jpg", {effect: "redeye"})
React:
Copy to clipboard
<Image publicId="itaib_redeye_msjmif.jpg" >
  <Transformation effect="redeye" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="itaib_redeye_msjmif.jpg" >
  <cld-transformation effect="redeye" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="itaib_redeye_msjmif.jpg" >
  <cl-transformation effect="redeye">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("redeye")).BuildImageTag("itaib_redeye_msjmif.jpg")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().effect("redeye")).generate("itaib_redeye_msjmif.jpg");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("redeye")).generate("itaib_redeye_msjmif.jpg")!, cloudinary: cloudinary)

Original image

Uploaded image with red eye removed

Here we used the same images as above (before red eye removal and after) to generate face detection based thumbnails. This, as well as red eye removal, can be done by embedding a dynamic transformation URL and code (as shown below) from various development frameworks into your web page.

Ruby:
Copy to clipboard
cl_image_tag("itaib_redeye_msjmif.jpg", :transformation=>[
  {:effect=>"redeye"},
  {:gravity=>"face", :width=>200, :height=>200, :radius=>"max", :crop=>"thumb"}
  ])
PHP v1:
Copy to clipboard
cl_image_tag("itaib_redeye_msjmif.jpg", array("transformation"=>array(
  array("effect"=>"redeye"),
  array("gravity"=>"face", "width"=>200, "height"=>200, "radius"=>"max", "crop"=>"thumb")
  )))
PHP v2:
Copy to clipboard
(new ImageTag('itaib_redeye_msjmif.jpg'))
  ->effect(Effect::redEye())
  ->resize(Resize::thumbnail()->width(200)->height(200)->gravity(Gravity::focusOn(FocusOn::face())))
  ->roundCorners(RoundCorners::max());
Python:
Copy to clipboard
CloudinaryImage("itaib_redeye_msjmif.jpg").image(transformation=[
  {'effect': "redeye"},
  {'gravity': "face", 'width': 200, 'height': 200, 'radius': "max", 'crop': "thumb"}
  ])
Node.js:
Copy to clipboard
cloudinary.image("itaib_redeye_msjmif.jpg", {transformation: [
  {effect: "redeye"},
  {gravity: "face", width: 200, height: 200, radius: "max", crop: "thumb"}
  ]})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation()
  .effect("redeye").chain()
  .gravity("face").width(200).height(200).radius("max").crop("thumb")).imageTag("itaib_redeye_msjmif.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('itaib_redeye_msjmif.jpg', {transformation: [
  {effect: "redeye"},
  {gravity: "face", width: 200, height: 200, radius: "max", crop: "thumb"}
  ]}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("itaib_redeye_msjmif.jpg", {transformation: [
  {effect: "redeye"},
  {gravity: "face", width: 200, height: 200, radius: "max", crop: "thumb"}
  ]})
React:
Copy to clipboard
<Image publicId="itaib_redeye_msjmif.jpg" >
  <Transformation effect="redeye" />
  <Transformation gravity="face" width="200" height="200" radius="max" crop="thumb" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="itaib_redeye_msjmif.jpg" >
  <cld-transformation effect="redeye" />
  <cld-transformation gravity="face" width="200" height="200" radius="max" crop="thumb" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="itaib_redeye_msjmif.jpg" >
  <cl-transformation effect="redeye">
  </cl-transformation>
  <cl-transformation gravity="face" width="200" height="200" radius="max" crop="thumb">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation()
  .Effect("redeye").Chain()
  .Gravity("face").Width(200).Height(200).Radius("max").Crop("thumb")).BuildImageTag("itaib_redeye_msjmif.jpg")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation()
  .effect("redeye").chain()
  .gravity("face").width(200).height(200).radius("max").crop("thumb")).generate("itaib_redeye_msjmif.jpg");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation()
  .setEffect("redeye").chain()
  .setGravity("face").setWidth(200).setHeight(200).setRadius("max").setCrop("thumb")).generate("itaib_redeye_msjmif.jpg")!, cloudinary: cloudinary)

Original thumbnail

Face detection based thumbnail with red-eye removed

Leveraging eye detection for more accurate red eye removal

In order to get even higher quality results, you can use Cloudinary’s ReKognition face attribute detection add-on for eye detection. Together with this add-on and the red eye removal effect, Cloudinary can automatically detect where eyes are located in a photo and apply the red eye removal algorithm in a more precise way. In order to do this, set the effect parameter of Cloudinary’s dynamic transformation URLs to rek_redeye. Cloudinary's SDKs allow you to easily generate transformation and delivery URLs in various development frameworks. Below is a sample dynamic transformation URL and code to generate an HTML image tag that can be adjusted for various popular frameworks such as Ruby on Rails, PHP, Node.js, and more.

Following the examples above that simply underwent dynamic red eye removal, below is an original uploaded image that was cropped and underwent accurate red eye removal using Cloudinary’s ReKognition face attribute detection add-on.

Ruby:
Copy to clipboard
cl_image_tag("tali_redeye_rvem1u.jpg", :effect=>"rek_redeye")
PHP v1:
Copy to clipboard
cl_image_tag("tali_redeye_rvem1u.jpg", array("effect"=>"rek_redeye"))
PHP v2:
Copy to clipboard
This code example is not currently available.
Python:
Copy to clipboard
CloudinaryImage("tali_redeye_rvem1u.jpg").image(effect="rek_redeye")
Node.js:
Copy to clipboard
cloudinary.image("tali_redeye_rvem1u.jpg", {effect: "rek_redeye"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().effect("rek_redeye")).imageTag("tali_redeye_rvem1u.jpg");
JS:
Copy to clipboard
cloudinary.imageTag('tali_redeye_rvem1u.jpg', {effect: "rek_redeye"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("tali_redeye_rvem1u.jpg", {effect: "rek_redeye"})
React:
Copy to clipboard
<Image publicId="tali_redeye_rvem1u.jpg" >
  <Transformation effect="rek_redeye" />
</Image>
Vue.js:
Copy to clipboard
<cld-image publicId="tali_redeye_rvem1u.jpg" >
  <cld-transformation effect="rek_redeye" />
</cld-image>
Angular:
Copy to clipboard
<cl-image public-id="tali_redeye_rvem1u.jpg" >
  <cl-transformation effect="rek_redeye">
  </cl-transformation>
</cl-image>
.NET:
Copy to clipboard
cloudinary.Api.UrlImgUp.Transform(new Transformation().Effect("rek_redeye")).BuildImageTag("tali_redeye_rvem1u.jpg")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().effect("rek_redeye")).generate("tali_redeye_rvem1u.jpg");
iOS:
Copy to clipboard
imageView.cldSetImage(cloudinary.createUrl().setTransformation(CLDTransformation().setEffect("rek_redeye")).generate("tali_redeye_rvem1u.jpg")!, cloudinary: cloudinary)

Original image

Uploaded image with red eye removed using ReKognition eye detection

Final Notes

Cloudinary’s advanced image transformation capabilities improve photo quality without any added effort on your side, and are fully integrated into Cloudinary's image management lifecycle. Simply add the parameters outlined above to an image’s CDN delivered URL and apply further effects, if desired, to adjust sharpness, color balance and more. The red eye removal feature is available with all of Cloudinary’s plans, including the free tier. You can use the ReKognition add-on eye detection effect by subscribing to the add-on itself. If you don't have a Cloudinary account yet, sign up for a free account here.

Update - April 2016: The add-on described in this post is no longer available since ReKognition terminated their services. However, all features described here are still available via a different and even better add-on by Microsoft. See Facial attribute detection with Microsoft's Face API and the Advanced facial attributes detection add-on documentation.

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