Generate Stunning Textures with tstramer/material-diffusion Cognitive Actions

21 Apr 2025
Generate Stunning Textures with tstramer/material-diffusion Cognitive Actions

In the world of digital content creation, the need for high-quality, seamless textures is paramount. The tstramer/material-diffusion API offers developers a powerful toolset to generate tileable images using advanced AI-driven methods. These pre-built Cognitive Actions simplify the image generation process, allowing you to focus on creating engaging visuals without needing extensive expertise in AI or image processing.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure that you have the following:

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
  • Familiarity with JSON format for structuring your input payload.
  • A basic understanding of how to make HTTP requests in your programming language of choice.

To authenticate your requests, you will generally pass the API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Tileable Images

The Generate Tileable Images action allows you to create seamless tileable images optimized for texture creation. By leveraging the v1.5 model of a Stable Diffusion fork, this action produces high-quality outputs tailored to your specifications.

Input

The input for this action consists of several parameters, which are detailed below:

  • mask (optional): A URI string representing a black and white mask image for inpainting. Black pixels indicate areas to inpaint, while white pixels are preserved.
  • seed (optional): An integer to initialize the random generator. Leaving this field blank generates a random seed each time.
  • width (optional): The width of the output image. Valid dimensions range from 128 to 1024 in increments of 64 (default: 512).
  • height (optional): The height of the output image, with the same valid dimensions as width (default: 512).
  • prompt (optional): A textual description guiding the image generation (default: empty).
  • scheduler (optional): The algorithm for image generation, with options like DDIM, K-LMS, and PNDM (default: K-LMS).
  • initialImage (optional): A URI string for an initial image from which variations will be generated.
  • guidanceScale (optional): A float value indicating the intensity of classifier-free guidance (default: 7.5).
  • promptStrength (optional): A float value indicating the influence of the prompt when using an initial image (default: 0.8).
  • numberOfOutputs (optional): The count of images to produce (default: 1; max: 10).
  • numberOfInferenceSteps (optional): The quantity of denoising steps in the algorithm (default: 50; max: 500).

Example Input:

{
  "width": 512,
  "height": 512,
  "prompt": "Mossy Runic Bricks seamless texture, trending on artstation, stone, moss, base color, albedo, 4k",
  "scheduler": "K-LMS",
  "guidanceScale": 7.5,
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

The action typically returns a list of URIs pointing to the generated images. Here is an example of a successful output:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/c44b35a7-9859-45f1-b1ec-33d69d22d0b3/dd75acd2-7952-4199-87f9-23304f25f123.png"
]

Conceptual Usage Example (Python)

Below is a conceptual example of how you might call the Generate Tileable Images action using Python. This snippet illustrates how to structure the input payload and make a request to the Cognitive Actions execution endpoint.

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 = "189b2667-0190-4389-b6a9-95b03f106185" # Action ID for Generate Tileable Images

# Construct the input payload based on the action's requirements
payload = {
    "width": 512,
    "height": 512,
    "prompt": "Mossy Runic Bricks seamless texture, trending on artstation, stone, moss, base color, albedo, 4k",
    "scheduler": "K-LMS",
    "guidanceScale": 7.5,
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 50
}

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 example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and the input payload correspond to the specific parameters required for generating tileable images.

Conclusion

The tstramer/material-diffusion Cognitive Actions offer an efficient way to create stunning textures for your applications. By using the Generate Tileable Images action, you can harness the power of AI to produce high-quality visuals with ease. As you explore these capabilities, consider how they can enhance your projects or lead to innovative use cases in your development workflow. Happy coding!