Skip to content

Dominant Colors

PRICING DEMO

Ximilar provides service for extracting dominant colors from image. Currently there are two endpoints to extract dominant colors. Each of the endpoint has specific use case.

https://api.ximilar.com/dom_colors/generic/v2/dominantcolor
https://api.ximilar.com/dom_colors/product/v2/dominantcolor

Both endpoints return one or more dominant colors in three formats: RGB number values, RGB hex, Luv and name according to CSS3 color standard and pantone color naming.

Generic Photos

https://api.ximilar.com/dom_colors/generic/v2/dominantcolor

This endpoint detects, by default, up to 6 dominant colors from the whole image. The image is not transformed anyhow before the detection process.

Parameters:

  • records: A list of real-life photos to find similar products; each record
    • must contain either of _url or _base64 field
  • colors - the maximum number of dominant colors to be returned, default: 6 (3 for product photos)
curl -H "Content-Type: application/json" -H "Authorization: Token XYZ" https://api.ximilar.com/dom_colors/generic/v2/dominantcolor -d '{"color_names": true, "records":[{"_url":"https://www.ximilar.com/fashion_examples/1.jpg"}]}'
from ximilar.client import DominantColorProductClient, DominantColorGenericClient

product_client = DominantColorProductClient(token="__API_TOKEN__")
generic_client = DominantColorGenericClient(token="__API_TOKEN__")

result = product_client.dominantcolor([{"_url": "__URL_PATH_TO_IMAGE__"}])
print(result['records'][0]['_dominant_colors'])

The result has similar json structure:

CLICK TO SHOW JSON RESULT

{
    "records": [
        {
            "_url": "https://images.ximilar.com/examples/fashion_products/598980986.jpg",
            "test": "insomnia",
            "_status": {
                "code": 200,
                "text": "OK",
                "request_id": "29c94aa9-b8ea-4cf9-a1f7-189d23af75de"
            },
            "_id": "ed06d699-afde-4903-9ccc-2e5c6fe7e9b6",
            "_width": 480,
            "_height": 545,
            "_dominant_colors": {
                "rgb_colors": [
                    [
                        247,
                        235,
                        149
                    ],
                    [
                        209,
                        145,
                        70
                    ]
                ],
                "luv_colors": [
                    [
                        92,
                        12,
                        59
                    ],
                    [
                        65,
                        50,
                        52
                    ]
                ],
                "percentages": [
                    0.74,
                    0.26
                ],
                "rgb_hex_colors": [
                    "#f7eb95",
                    "#d19146"
                ],
                "color_names": [
                    "khaki",
                    "peru"
                ],
                "color_names_pantone": [
                    "Yellow Iris",
                    "Golden Nugget"
                ]
            }
        }
    ],
    "status": {
        "code": 200,
        "text": "OK",
        "request_id": "29c94aa9-b8ea-4cf9-a1f7-189d23af75de",
        "proc_id": "9bb4a188-a122-4751-9ee8-056a598431d7"
    },
    "statistics": {
        "processing time": 1.0255484580993652
    }
}

Product Photos

https://api.ximilar.com/dom_colors/product/v2/dominantcolor

This endpoint is meant for product photos with a one product, object or person (possibly a piece of clothes worn by a person). This endpoint:

  • first filters the background with remove background service
  • analyze and detects dominant colors of foreground object
  • detects up to 6 dominant colors in the image, but then returns the 3 major colors (by area)

Extract color for object

You can specify _extract_object_color along with _objects (the _objects field has same structure as Custom Object Detection and Fashion Tagging). This will ensure to extract colors for the specific area of the first object.

The endpoint has exact same params and workflow as for the generic photos.