Products

SIGN UPLOG IN

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 natural photo.

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.

Illustration

Illustrations include:

  • Photos of paintings, drawings, illustrations where they are the only visible element of the image
  • Animations and cartoons
  • Video game graphics
  • Cliparts
  • Logos

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.

Photography

Natural photos:

  • Photos, whether collor or black and white
  • Photos of statues, models or art
  • Composite images or collages where each element of the collage is itself a photo
  • Photos with filters or effects, unless animated

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.

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

Use the model

If you haven't already, create an account to get your own API keys.

Detect the type of an image

To determine the type of an 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}' \
    --data-urlencode 'url=https://sightengine.com/assets/img/examples/example7.jpg'


# this example uses requests
import requests
import json

params = {
  'url': 'https://sightengine.com/assets/img/examples/example7.jpg',
  'models': 'type',
  'api_user': '{api_user}',
  'api_secret': '{api_secret}'
}
r = requests.get('https://api.sightengine.com/1.0/check.json', params=params)

output = json.loads(r.text)


$params = array(
  'url' =>  'https://sightengine.com/assets/img/examples/example7.jpg',
  'models' => 'type',
  'api_user' => '{api_user}',
  'api_secret' => '{api_secret}',
);

// this example uses cURL
$ch = curl_init('https://api.sightengine.com/1.0/check.json?'.http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$output = json_decode($response, true);


// this example uses axios
const axios = require('axios');

axios.get('https://api.sightengine.com/1.0/check.json', {
  params: {
    'url': 'https://sightengine.com/assets/img/examples/example7.jpg',
    'models': 'type',
    'api_user': '{api_user}',
    'api_secret': '{api_secret}',
  }
})
.then(function (response) {
  // on success: handle response
  console.log(response.data);
})
.catch(function (error) {
  // handle error
  if (error.response) console.log(error.response.data);
  else console.log(error.message);
});

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/example7.jpg"
  }
}
                
            

Any other needs?

See our full list of Image/Video models for details on other filters and checks you can run on your images and videos. You might also want to check our Text models to moderate text-based content: messages, reviews, comments, usernames...

Was this page helpful?