Create Stunning Inpainted Images with Sdxl Mate

26 Apr 2025
Create Stunning Inpainted Images with Sdxl Mate

In the world of digital content creation, the ability to generate and manipulate images with precision can greatly enhance your projects. With Sdxl Mate, developers can leverage powerful Cognitive Actions designed for image generation. One of the standout features is the ability to generate inpainted images with refinement, allowing for the seamless integration of new elements into existing images. This service not only speeds up the creative process but also simplifies complex tasks, enabling developers to focus more on their creative vision rather than the technical details.

Common use cases for Sdxl Mate's inpainting capabilities include enhancing visual storytelling by replacing or adding elements in images, creating product mockups, or even generating unique artwork based on specific prompts. Whether you are a game developer looking to create immersive environments or a content creator aiming to produce eye-catching visuals, Sdxl Mate provides the tools to make your ideas come to life.

Prerequisites

To get started, you'll need a Cognitive Actions API key and a fundamental understanding of making API calls.

Generate Inpainted Images with Refinement

The "Generate Inpainted Images with Refinement" action allows you to create images by inpainting specified areas based on prompt guidance. This action supports multiple refinement styles, image size adjustments, and optional watermarking, making it versatile for various creative needs.

Input Requirements

The input for this action requires a structured set of parameters, including:

  • Mask: A URI that specifies the areas to be inpainted (white areas will be altered, black areas remain unchanged).
  • Image: A URI for the original image to be modified.
  • Prompt: A text description that guides the inpainting process.
  • Width and Height: Define the dimensions of the output image.
  • Guidance Scale: Adjusts how closely the generated image follows the prompt.
  • Refinement Style: Selects the method of refinement to be applied.

Here’s an example of input parameters:

{
  "width": 1024,
  "height": 1024,
  "prompt": "A picture of Harry Potter holding a mate in the style of TOK",
  "loraScale": 0.6,
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "inferenceSteps": 50,
  "negativePrompt": "ugly, broken, disfigured, people, cartoon",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "refinementStyle": "expert_ensemble_refiner",
  "highNoiseFraction": 0.9,
  "schedulingAlgorithm": "K_EULER"
}

Expected Output

The expected output from this action is a URI linking to the generated image, which will reflect the specified modifications based on the prompt and mask provided. For example:

"https://assets.cognitiveactions.com/invocations/1ee0d99b-256f-4e19-96f0-90b8785839c2/aea9cc11-7621-4a06-8ef0-375e330d9fdb.png"

Use Cases for this Specific Action

This action is particularly useful in scenarios where image manipulation is required, such as:

  • Artistic Enhancement: Artists can refine their creations by adding or altering elements within a composition.
  • Marketing and Advertising: Marketers can customize promotional images by integrating brand elements or adjusting visuals to better fit their campaigns.
  • Content Creation: Bloggers and social media managers can create unique visuals that stand out, ensuring their content is engaging and visually appealing.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "8435144f-e869-48c2-b766-a07b65a1ff97" # Action ID for: Generate Inpainted Images with Refinement

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1024,
  "height": 1024,
  "prompt": "A picture of Harry Potter holding a mate in the style of TOK",
  "loraScale": 0.6,
  "guidanceScale": 7.5,
  "applyWatermark": false,
  "inferenceSteps": 50,
  "negativePrompt": "ugly, broken, disfigured, people, cartoon",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "refinementStyle": "expert_ensemble_refiner",
  "highNoiseFraction": 0.9,
  "schedulingAlgorithm": "K_EULER"
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

Sdxl Mate's image inpainting capabilities empower developers to create stunning visuals quickly and efficiently. By leveraging these Cognitive Actions, you can enhance your projects with tailored images that resonate with your audience. Whether you’re refining an existing image or creating something entirely new, Sdxl Mate provides the tools to bring your creative vision to life. As a next step, explore how you can integrate Sdxl Mate into your workflow and start generating remarkable images today.