Type Detection

Last updated November 20th, 2017

Overview

The image properties API can help you determine if an image is an illustration or a photography. An illustration could be a drawing, a clipart, a painting, a logo or any such image that does not look like a photography.

Illustration (logo)
Illustration (drawing)
Illustration (clipart)
Illustration (painting)
Photography

Type detection

The property detection does not use any image meta-data to determine the type of an image. The file extension, the meta-data or the name will not influence the result. The classification is made using only the pixel content of the image.

Use-cases

  • Require that users submit or upload real photos only, and not non-photographic content.
  • Group or classify your images depending on their type

Limitations

  • Depending on the way they have been taken, photos of paintings / drawings may be detected as paintings or drawings and not as photos.
  • Some realistic illustrations (such as computer-generated scenes or realistic paintings) may be classified as photos.

Illustration

The returned value is between 0 and 1, images with an illustration value closer to 1 will be an illustration while images with an illustration value closer to 0 will be a photography.

Illustration: (illustration value 0.80677)

Photography

The returned value is between 0 and 1, images with a photo value closer to 1 will be a photography while images with a photo value closer to 0 will be an illustration.

photography: (photo value 0.950306)

Use the model

To start, you need to create an account to retrieve your API keys. Then you must install the SDK that corresponds to your programming language.


# install cURL: https://curl.haxx.se/download.html


pip install sightengine


composer require sightengine/client-php


npm install sightengine --save

Detect the type of an image

Let say you want moderate the following image:

You can either upload a public URL to the image, or upload the raw binary image. Here's how to upload the


curl -X GET -G 'https://api.sightengine.com/1.0/check.json' \
    -d 'models=type' \
    -d 'api_user={api_user}&api_secret={api_secret}' \
    -d 'url=https://d3m9459r9kwism.cloudfront.net/img/examples/example2.jpg'


 # if you haven't already, install the SDK with 'pip install sightengine'
from sightengine.client import SightengineClient
client = SightengineClient('{api_user}','{api_secret}')
output = client.check('type').set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example2.jpg')


// if you haven't already, install the SDK with 'composer require sightengine/client-php'
use \Sightengine\SightengineClient;
$client = new SightengineClient('{api_user}','{api_secret}');
$client->check(['type'])->set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example2.jpg');


// if you haven't already, install the SDK with 'npm install sightengine --save'
var sightengine = require('sightengine')('{api_user}','{api_secret}');
sightengine.check(['type']).set_url('https://d3m9459r9kwism.cloudfront.net/img/examples/example2.jpg').then(function(result) {
    // The result of the API
}).catch(function(err) {
    // Error
});

Here is the result:

                    
                    
{
  "status": "success",
  "request": {
    "id": "req_VjyxevVQYXQZ1HMbnwtn",
    "timestamp": 1471762434.0244,
    "operations": 1
  },
  "type": {
    "illustration": 0.000757,
    "photo": 0.999243
  },
  "media": {
    "id": "med_KWmB2GQZ29N4MVpVdq5K",
    "uri": "https://sightengine.com/assets/img/examples/example2.jpg"
  }
}
                    
                

Did you find this page helpful?

We're always looking for advice to help improve our documentation!

Let us know what you think