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.

We also provide results with just 12 simplified colors - black, grey, white, red, pink, orange, yellow, green, blue, purple, brown, and beige.

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": "__URL_JPG____",
            "_status": {
                "code": 200,
                "text": "OK",
                "request_id": "e24dd726-5b28-418c-b188-d3d50b1fb3e9"
            },
            "_id": "6cd97353-e491-4c12-bf08-1c26a03c2834",
            "_width": 480,
            "_height": 545,
            "_dominant_colors": {
                "rgb_colors": [
                    [
                        238,
                        235,
                        223
                    ],
                    [
                        247,
                        235,
                        149
                    ],
                    [
                        225,
                        167,
                        89
                    ],
                    [
                        179,
                        106,
                        29
                    ]
                ],
                "luv_colors": [
                    [
                        93,
                        2,
                        10
                    ],
                    [
                        92,
                        12,
                        59
                    ],
                    [
                        73,
                        45,
                        55
                    ],
                    [
                        52,
                        59,
                        46
                    ]
                ],
                "percentages": [
                    0.77,
                    0.17,
                    0.04,
                    0.02
                ],
                "rgb_hex_colors": [
                    "#eeebdf",
                    "#f7eb95",
                    "#e1a759",
                    "#b36a1d"
                ],
                "color_names": [
                    "linen",
                    "khaki",
                    "darkgoldenrod",
                    "peru"
                ],
                "color_names_pantone": [
                    "Cannoli Cream",
                    "Yellow Iris",
                    "Golden Apricot",
                    "Golden Oak"
                ],
                "color_names_simple": {
                    "beige": 0.77,
                    "yellow": 0.17,
                    "brown": 0.06
                }
            }
        }
    ],
    "status": {
        "code": 200,
        "text": "OK",
        "request_id": "e24dd726-5b28-418c-b188-d3d50b1fb3e9",
        "proc_id": "4cd45093-7067-46a7-a255-4cf62ad1785f"
    },
    "statistics": {
        "processing time": 0.7197988033294678
    }
}

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

Dominant Colors Similarity

If you have a collection of photos/images, you can search this collection by the similarity of their dominant colors. You can create a collection for dominant colors search at Ximilar App. The API is the same as for other Similarity Search Services and is available at API prefix:

https://api.ximilar.com/similarity/colors/

By default, inserting an image into a collection of this type, the Generic photos color extraction is used (no background removal), but it can be turned on using parameter

color_type": "product"