wuhuikai

wuhuikai / A2RL / 0.2.0

README.md

WARNING

A2RL_online should be used instead of A2RL, A2RL_online supports urls as input and is much faster than A2RL.

Overview

[Project] [Paper] [Online Demo] [API] [Related Work: GP-GAN (for Image Blending)]

sourcestep 1step 2step 3step 4step 5output

A2-RL (aka. Aesthetics Aware Reinforcement Learning) is the author's implementation of the RL-based automatic image cropping algorithm described in:

A2-RL: Aesthetics Aware Reinforcement Learning for Automatic Image Cropping   
Debang Li, Huikai Wu, Junge Zhang, Kaiqi Huang

Given a source image, our algorithm could take actions step by step to find almost the best cropping window on source image.

Usage

Input

For client users, the input is a list of bytearray reading from image files.

input = bytearray(open('xxx.jpg', 'rb').read())
result = algo.pipe([input]).result

For web (javascript) users, the input is a dict with 'xxximagexxx' as the keys and base64 string of the images as the values.

...
<input id="file-input" type="file" name="name" style="display: none;"/>
...
document.getElementById('file-input').onchange = function (evt) {
        var tgt = evt.target || window.event.srcElement;
        files = tgt.files;
        // FileReader support
        if (FileReader && files && files.length) {
            var reader = new FileReader();
            reader.onload = function () {
                Algorithmia.client("xxxxxxxxxxxxxxxx")
                           .algo("algo://wuhuikai/A2RL")
                           .pipe({'super_image_a': reader.result})
                           .then(function(output) {
                                ...
                           });
            }
            reader.readAsDataURL(files[0]);
        } else {
            // Not supported
            ...
        }

Output

output.result = [[xmin, ymin, xmax, ymax], [xmin, ymin, xmax, ymax], ..., [xmin, ymin, xmax, ymax]]

Examples

SourceA2-RL