未加星标

Use Smart Thumbnail to Perfectly Crop Images Programmatically

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二03 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

Use Smart Thumbnail to Perfectly Crop Images Programmatically
It’s not easy to dynamicallyscale and crop images of different sizes or aspect ratios.Typically, this is resolved in one of two ways: manipulate images by hand (slow, high quality, expensive), or indiscriminately crop-to-fit from the middle-out (fast, low quality, cheap).

Smart Thumbnailis a microservice developers can use to programmatically manipulate images at scale while ensuringthat every image is perfectly cropped.

Since webservices and social networks can’t employ hundreds of people to manually crop and resize images, they rely on “dumb” algorithms to generate these thumbnails. This is why we experiencethumbnails throughout the webof decapitated people, mountains without peaks, or subjects missing from the frame entirely.

If you wanted to extract structured data from websites, or wanted to crawl, scrape, and analyze websites , Smart Thumbnail would be the tool you’d want for handling images manipulation.

Here are two examples of Smart Thumbnail fixing imagespoorly cropped images:


Use Smart Thumbnail to Perfectly Crop Images Programmatically
Use Smart Thumbnail to Perfectly Crop Images Programmatically
What is Smart Thumbnail

Smart Thumbnail is a microservice that can automatically resize and crop images withthe most relevant parts framed and retained.

This microservice takes advantage of both facial recognition with OpenCV , as well as a deep convolutional network for saliency predication to“learn” where in an image to scale and crop.

For example,the most relevant part of an image with people would probably revolve around their faces.

Smart Thumbnail will useOpenCV to recognize the faces in the image and then crops the image to your desired thumbnail size with the face in the frame. No more decapitated people.

But what if image doesn’t contain people? Good question!

Smart Thumbnail will recognize that, and then usesaliency via SalNet, an implementation of the “ Shallow and Deep Convolutional Networks for Saliency Prediction ” research.

(The technical explanation goes like this: By default, Smart Thumbnail takes the average of the centroid of the largest face it detects, if one is detected, as well as the centroid of saliency in the image to determine where to crop. If no face is detected, Smart Thumbnail will use the centroid of of saliency to figure out what the most important part of the image is, and ensure it’s retained when scaled and cropped.)

Saliency represents the most prominent part of an image, like a person in a painting. The visual representation of saliency couldbest be seen as a heatmap like this:


Use Smart Thumbnail to Perfectly Crop Images Programmatically
Whether or not your image contains people, places, or things, Smart Thumbnail can intelligently crop and resize your images into thumbnails. Why You Need Smart Thumbnail

By using Smart Thumbnail, you ensure that thumbnails on your site are always perfectly cropped, even if the most salient object isn’t already centered.

When you leverage a microservice like Smart Thumbnail, you can scale your ability to manipulate images on your site programmatically, and avoid embarrassing thumbnails like the examples above.

Or, justlook at thisreal life examples of a poorly cropped image:


Use Smart Thumbnail to Perfectly Crop Images Programmatically
Low quality thumbnails like this erode the trust and undermine professionalism. How to Use Smart Thumbnail

There are a few ways to leverage Smart Thumbnail in your apps and services. The API requires an array with an input URL, output URL, thumbnail width , and thumbnail height .

The input requires either a URL or an Algorithmia Data URI. Youroutput will be the binary representation of the image, unless you specify adestination for a file when making the API call. This will be saved as a PNG.

The height and width are the desired output size of the image.

To start making calls, you’ll needa free API key fromAlgorithmia .

Below is the sample input/output. We’ll be using this image for reference:


Use Smart Thumbnail to Perfectly Crop Images Programmatically
Sample Input import Algorithmia
input = [
"https://hd.unsplash.com/photo-1466840787022-48e0ec048c8a",
"data://.algo/temp/test.png",
500,
500
]
client = Algorithmia.client('API KEY HERE')
algo = client.algo('opencv/SmartThumbnail/2.1.1')
print algo.pipe(input) Sample Output data://.algo/temp/arnold.png
Use Smart Thumbnail to Perfectly Crop Images Programmatically

That was easy. Now you have a solution for dynamically generating thumbnails next time you’re working on a web development project, app, or service.

To take things a step further, trying using one of our deep learning models, likeArtsyNet,Illustration Tagger, or thePlaces classifier to enrich your images with metadata and tags.

Give a try and let us know what you think @Algorithmia .

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: OpenCV
分页:12
转载请注明
本文标题:Use Smart Thumbnail to Perfectly Crop Images Programmatically
本站链接:http://www.codesec.net/view/482133.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(38)