Enhance Your Images with AnyDoor's Object-Level Customization Cognitive Actions

23 Apr 2025
Enhance Your Images with AnyDoor's Object-Level Customization Cognitive Actions

In the realm of image processing, the ability to manipulate and customize images with precision can elevate your applications to new heights. The AnyDoor Cognitive Actions offer a powerful solution for developers looking to integrate object-level image customization into their projects. With capabilities that allow for zero-shot manipulation of images, these actions eliminate the need for additional training, making them both efficient and user-friendly. In this guide, we'll explore how to utilize these Cognitive Actions effectively.

Prerequisites

To get started with the AnyDoor Cognitive Actions, you will need:

  • An API key for the Cognitive Actions platform.
  • Basic familiarity with making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the request headers. Ensure you have this ready before proceeding to use the actions.

Cognitive Actions Overview

Perform Object-Level Image Customization

The Perform Object-Level Image Customization action allows you to manipulate objects within a reference image against a background without the need for prior training. This action is particularly useful for enhancing images or creating composite visuals in a straightforward manner.

Input

The action requires the following fields in the input schema:

  • backgroundImagePath (string, required): URI path to the background image.
  • backgroundMaskPath (string, required): URI path to the background image mask.
  • referenceImagePath (string, required): URI path to the reference image.
  • referenceImageMask (string, required): URI to the mask for the reference image.

Additionally, there are several optional parameters:

  • seed (integer): A random seed for reproducibility. Leave blank for a randomized seed.
  • steps (integer): Number of steps for processing (default is 50, range 1-100).
  • guidanceScale (number): Scale factor for guidance (default is 4.5, range 0.1-30).
  • controlStrength (number): Strength of the control applied (default is 1, range 0-2).
  • enableShapeControl (boolean): Enables or disables shape control (default is false).

Example Input:

{
  "steps": 30,
  "guidanceScale": 4.5,
  "controlStrength": 1,
  "backgroundMaskPath": "https://replicate.delivery/pbxt/KAr5sZjqxgOrXGCOo2PAkvrywmnD8s6gtGYEKAzxV1n8UsKN/burger-mask.png",
  "enableShapeControl": false,
  "referenceImageMask": "https://replicate.delivery/pbxt/KAr5swy9Bdkv4cM2IKAvLoxCMWtLLmMLFSK1SpwTLDxzdYgW/sloth-mask.png",
  "referenceImagePath": "https://replicate.delivery/pbxt/KAr5sJGlXZyZPR2SfOduHMvnUgS1CIc81ynRVCdHV24JdTo0/sloth.png",
  "backgroundImagePath": "https://replicate.delivery/pbxt/KAr5t2fIFVQ4eNy4JwN6LAZpHyTYzXHaO78TinDeHzYWK9RS/burger.png"
}

Output

The output of this action typically returns a URI pointing to the newly customized image.

Example Output:

https://assets.cognitiveactions.com/invocations/90d48119-fd80-4f5b-941d-816c2c38d5c0/6bebd51a-a261-4573-85a3-85e8c31c4cff.png

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Perform Object-Level Image Customization action 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 = "7ae9183d-376e-417c-8df9-ccbd58ca28b9" # Action ID for Perform Object-Level Image Customization

# Construct the input payload based on the action's requirements
payload = {
    "steps": 30,
    "guidanceScale": 4.5,
    "controlStrength": 1,
    "backgroundMaskPath": "https://replicate.delivery/pbxt/KAr5sZjqxgOrXGCOo2PAkvrywmnD8s6gtGYEKAzxV1n8UsKN/burger-mask.png",
    "enableShapeControl": False,
    "referenceImageMask": "https://replicate.delivery/pbxt/KAr5swy9Bdkv4cM2IKAvLoxCMWtLLmMLFSK1SpwTLDxzdYgW/sloth-mask.png",
    "referenceImagePath": "https://replicate.delivery/pbxt/KAr5sJGlXZyZPR2SfOduHMvnUgS1CIc81ynRVCdHV24JdTo0/sloth.png",
    "backgroundImagePath": "https://replicate.delivery/pbxt/KAr5t2fIFVQ4eNy4JwN6LAZpHyTYzXHaO78TinDeHzYWK9RS/burger.png"
}

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 the placeholder for the API key and specify the correct endpoint URL. The action ID and input payload are structured according to the requirements of the Perform Object-Level Image Customization action.

Conclusion

With AnyDoor's Object-Level Image Customization Cognitive Actions, developers can seamlessly integrate advanced image manipulation capabilities into their applications. These actions not only streamline the process of image enhancement but also open up a world of creative possibilities. Whether you're developing a photo editing tool, an e-commerce platform, or any application that requires image customization, these Cognitive Actions can significantly enhance user experience.

Consider exploring additional use cases or combining this action with other capabilities to maximize the potential of your projects. Happy coding!