Transform Your Images with the iordcalin Material Transfer Cognitive Actions

24 Apr 2025
Transform Your Images with the iordcalin Material Transfer Cognitive Actions

In the realm of image processing, the ability to apply textures and materials from one image to another can significantly enhance the visual appeal of digital content. The iordcalin/material-transfer spec offers a powerful Cognitive Action that allows developers to seamlessly transfer material textures to subject images. This process not only provides customization options for output quality but also supports various image dimensions and material application strengths, making it a versatile tool for enhancing your applications.

Prerequisites

To get started with the Cognitive Actions in the iordcalin/material-transfer spec, you'll need:

  • An API key for the Cognitive Actions platform to authenticate your requests.
  • Familiarity with making HTTP requests in your programming language of choice.

Authentication typically involves passing the API key in the request headers.

Cognitive Actions Overview

Apply Material Texture

The Apply Material Texture action is designed to transfer a material texture from a given image to a subject image. This action allows for fine-tuning through customizable options such as output quality, image dimensions, and the strength of material application, utilizing a step-based approach for precision—up to 20 steps for meticulous detail.

Input

The input schema for this action requires several fields:

  • materialImage (string, required): A URL pointing to the image of the material to be applied.
  • subjectImage (string, required): A URL pointing to the subject image to which the material will be applied.
  • seed (integer, optional): A seed value for reproducible results. Defaults to a random seed if not specified.
  • steps (integer, optional): The number of processing steps, defaulting to 6, with a maximum of 20 for enhanced detail.
  • prompt (string, optional): A descriptive text prompt for the desired attributes of the final image.
  • maxWidth (integer, optional): The maximum width of the output image (default is 1920 pixels).
  • maxHeight (integer, optional): The maximum height of the output image (default is 1920 pixels).
  • outputFormat (string, optional): The format of the output image, with options including 'webp', 'jpg', and 'png' (default is 'webp').
  • guidanceScale (number, optional): Influences the prompt's effect on the process (default is 2).
  • outputQuality (integer, optional): The quality of the output image, ranging from 0 (lowest) to 100 (highest), defaulting to 80.
  • negativePrompt (string, optional): Specifies features to avoid in the final image.
  • materialStrength (string, optional): Indicates the intensity of the material application ('medium' or 'strong', default is 'medium').
  • returnIntermediateImages (boolean, optional): If set to true, returns intermediate images for debugging (default is false).

Example Input:

{
  "steps": 12,
  "prompt": "delicate ruby model of a bird",
  "maxWidth": 1920,
  "maxHeight": 1920,
  "outputFormat": "webp",
  "subjectImage": "https://replicate.delivery/pbxt/KqS0LyQoJuCpq0D0eQEmcKVuFtT7WJfuxb1pxmaLtk7kpwSt/image.png",
  "guidanceScale": 2,
  "materialImage": "https://replicate.delivery/pbxt/KqS0L9BvaN0MsGQ5v9X1AIuzCbeb5jXYWDVRqmQelQB2qPGP/image.png",
  "outputQuality": 80,
  "materialStrength": "medium",
  "returnIntermediateImages": false
}

Output

The action typically returns a URL pointing to the generated output image after applying the material texture.

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/c288b94c-4e94-402a-8d0e-9d67b841262b/f08fae3e-cfea-4334-ba60-6d24074e94ac.webp"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet demonstrating how to call the Apply Material Texture action:

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 = "80ceb788-db8e-41a0-88dc-911a078971e8"  # Action ID for Apply Material Texture

# Construct the input payload based on the action's requirements
payload = {
    "steps": 12,
    "prompt": "delicate ruby model of a bird",
    "maxWidth": 1920,
    "maxHeight": 1920,
    "outputFormat": "webp",
    "subjectImage": "https://replicate.delivery/pbxt/KqS0LyQoJuCpq0D0eQEmcKVuFtT7WJfuxb1pxmaLtk7kpwSt/image.png",
    "guidanceScale": 2,
    "materialImage": "https://replicate.delivery/pbxt/KqS0L9BvaN0MsGQ5v9X1AIuzCbeb5jXYWDVRqmQelQB2qPGP/image.png",
    "outputQuality": 80,
    "materialStrength": "medium",
    "returnIntermediateImages": false
}

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, you will replace the COGNITIVE_ACTIONS_API_KEY with your actual API key and make a POST request to the hypothetical endpoint. The action_id is set to the ID of the Apply Material Texture action, and the payload is structured according to the input requirements.

Conclusion

The iordcalin/material-transfer spec provides a robust solution for developers looking to enhance their applications with advanced image processing capabilities. By utilizing the Apply Material Texture action, you can easily incorporate material textures into your images, offering a high level of customization and output quality. Explore the potential of these Cognitive Actions in your next project and elevate your image processing capabilities!