media

media / ContentAwareResize / 0.1.3

README.md

content aware resize

Table of Contents

Introduction

This algorithm discovers the most important features of an image and attempts to preserve them when resizing. It does this by utilizing both both the face detection and Salnet algorithms to determine importance, and using opencv to directly crop and resize the image.

I/O

Input

{  
   "image":String,
   "output":String,
   "width":Int,
   "height":Int,
   "raio":Float,
   "binarize":Boolean
}
  • image - (required) - an input image as either a url, data connector uri (data://, s3://, etc) or a base 64 encoded string.
  • output - (optional) - the output data connector path to where you want to save the resized image to. defaults to data://.algo/temp/<uuid>.png
  • width - (optional) - the desired resize width. defaults to 188
  • height - (optional) - the desired resize height. defaults to 265
  • ratio - (optional) - the weighted ratio between the effects of Saliency and Face recognition on the final centroid. A value of 0.0 means the result will entirely depend on saliency, whereas a value of 1.0 will entirely depend on face detection. Here's the exact formula used by the algorithm: centroid(x,y) = face_detection(x,y)*(ratio) + salnet(x,y)*(1-ratio). defaults to 0.5
  • binarize - (optional) - an optional flag that if defined, forces the output to be returned as a base64 encoded string. defaults to false

Output

{  
   "output":String
}

  • output - the resized image data collection URI.

Examples

Example 1

example 1

Input

{  
   "height":1500,
   "width":400,
   "ratio":0.65,
   "output":"data://.algo/temp/thumb.jpg",
   "image":"http://i.imgur.com/NU7t6yB.jpg"
}

Output

{  
   "output":"data://.algo/temp/thumb.jpg"
}

Example 2

example 2

Input

{  
   "image":"https://i.redd.it/mdog3luiawcy.jpg",
   "width":400,
   "height":1500
}

Output

{  
   "output":"data://.algo/temp/77d3e783-b7fb-4390-b789-af321b69dc89.png"
}

Credits

This algorithm utilizes opencv for image manipulation and editing, dlib's face detection, and deeplearning's Salnet.

All images retrieved from imgur.com on April 25th, 2017