Nov 20th, 2017

Models / Type Detection

Type Detection

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

If you haven't already, create an account to get your own API keys. You should then install the SDK that corresponds to your programming language. You can also implement your own logic to interact with our API if you prefer. Have a look at our API reference for more details.


# 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's say you want to moderate the following image:

You can either upload a public URL to the image, or upload the raw binary image. Here's how to proceed if you choose to share the image's public URL:


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://sightengine.com/assets/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://sightengine.com/assets/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://sightengine.com/assets/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://sightengine.com/assets/img/examples/example2.jpg').then(function(result) {
    // The API response (result)
}).catch(function(err) {
    // Handle error
});

The API will then return a JSON response:

                    
                    
{
  "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"
  }
}
                    
                

Any other needs?

See our full list of models for details on other filters and checks you can run on your images and videos.

Did you find this page helpful?

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

Let us know what you think