Transform Your Product Images with Chromatic Lens Cognitive Actions

24 Apr 2025
Transform Your Product Images with Chromatic Lens Cognitive Actions

In today’s digital landscape, captivating product presentations are essential for e-commerce success. The Chromatic Lens API, specifically the product-shot-v1 specification, offers powerful Cognitive Actions to enhance your product images. These pre-built actions allow developers to generate stunning product shots by blending images with references, automating background removal, and offering customizable settings for a tailored output.

Prerequisites

Before you dive into using the Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • A basic understanding of making HTTP requests and handling JSON payloads.

Authentication typically involves passing your API key in the request headers, allowing you to securely access the service.

Cognitive Actions Overview

Create Product Shots with Reference Blending

This action is designed to generate visually appealing product images by merging them with reference images, thus creating a modern aesthetic. The process features automatic background removal and provides the flexibility to control how much influence the reference image has on the final output.

Input

The input schema for this action includes several fields:

  • seed (optional): An integer for reproducibility. If not set, a random seed will be used.
  • image (required): A string (URI) pointing to your product image, which will undergo background removal.
  • weight (optional): A number that determines the influence of the reference image. The default is 0.8.
  • negative (optional): A string listing undesirable aspects to exclude from your image, such as "watermark, noisy, glitch".
  • positive (optional): A string describing the desired scene for your product, e.g., "Sofa in a living room".
  • outputFormat (optional): Specifies the output image format, with options like "webp", "jpg", and "png". The default is "png".
  • numberOfSteps (optional): An integer that dictates how many steps the processing model should execute, ranging from 10 to 50 (default is 20).
  • numberOfImages (optional): Defines how many images to generate, from 1 to 20 (default is 1).
  • referenceImage (required): A string (URI) pointing to a reference image for inspiration.
  • maskMultiplierSize (optional): An integer to adjust the mask size for blending, with a default of 2.

Example Input:

{
  "image": "https://replicate.delivery/pbxt/LIOCo73tSUKgUDjpv7WkH9sucvvtzxnAUR5Uz4ymkDTBikN1/sofa.png",
  "weight": 0.5,
  "negative": "watermark, noisy, glitch, jpeg artifacts, bad",
  "positive": "Sofa in a living room",
  "outputFormat": "png",
  "numberOfSteps": 30,
  "numberOfImages": 4,
  "referenceImage": "https://replicate.delivery/pbxt/LIOCoFkkzRiVThSdHYhRjvLQG1v2HQtkssurFHt2ODMNrOi6/Untitled.png",
  "maskMultiplierSize": 5
}

Output

The output of this action typically consists of a list of URLs, each pointing to a generated product image based on the input parameters. The images will reflect the influence of the reference image and the specified settings.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/9669e35c-ee6f-42be-b531-d504f736bc5a/95288d79-0842-4686-b7b8-6f1ae017cc8b.png",
  "https://assets.cognitiveactions.com/invocations/9669e35c-ee6f-42be-b531-d504f736bc5a/b248aad7-61a5-45aa-ba90-f6ccd5788d75.png",
  "https://assets.cognitiveactions.com/invocations/9669e35c-ee6f-42be-b531-d504f736bc5a/9d97f443-14db-461b-9c6a-6e6697f48254.png",
  "https://assets.cognitiveactions.com/invocations/9669e35c-ee6f-42be-b531-d504f736bc5a/b16c58cd-f367-48e2-bb5e-e3a2f40167d1.png"
]

Conceptual Usage Example (Python)

Here’s how you could hypothetically call the Cognitive Actions execution endpoint using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"  # Hypothetical endpoint

action_id = "ba0062cc-5efe-4f78-a1de-d985be8f836e"  # Action ID for Create Product Shots with Reference Blending

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/LIOCo73tSUKgUDjpv7WkH9sucvvtzxnAUR5Uz4ymkDTBikN1/sofa.png",
    "weight": 0.5,
    "negative": "watermark, noisy, glitch, jpeg artifacts, bad",
    "positive": "Sofa in a living room",
    "outputFormat": "png",
    "numberOfSteps": 30,
    "numberOfImages": 4,
    "referenceImage": "https://replicate.delivery/pbxt/LIOCoFkkzRiVThSdHYhRjvLQG1v2HQtkssurFHt2ODMNrOi6/Untitled.png",
    "maskMultiplierSize": 5
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is structured to meet the input requirements of the action, and the request is sent to the API endpoint. The response will contain the URLs of the generated images.

Conclusion

The Chromatic Lens Cognitive Actions provide a seamless way to elevate your product imagery, helping you stand out in the competitive e-commerce landscape. By leveraging the Create Product Shots with Reference Blending action, developers can create visually stunning images that captivate customers and enhance the shopping experience. Explore further use cases by integrating other actions into your applications to fully harness the power of this API!