Enhance Your Images with Stanidani's Inpainting Features

26 Apr 2025
Enhance Your Images with Stanidani's Inpainting Features

In the world of digital content creation, the need for high-quality images is paramount. Stanidani provides a powerful set of Cognitive Actions that enable developers to generate images through innovative techniques such as inpainting and img2img transformations. These actions not only enhance the visual quality of images but also offer flexibility and creative control, making them invaluable for developers looking to streamline their workflow.

With Stanidani's image generation capabilities, users can quickly create stunning visuals for various applications, including marketing materials, social media content, and digital art projects. Whether you need to restore a portion of an image, add new elements, or completely transform an existing picture, these actions simplify the process, allowing for quick iterations and refinements.

Prerequisites

To get started, you will need an API key for Stanidani's Cognitive Actions and a basic understanding of making API calls.

Generate Image with Inpainting

The "Generate Image with Inpainting" action allows developers to create images by specifying an input image and a mask. This action is particularly useful for cases where you want to preserve certain areas of an image while modifying others. By leveraging various refiners and schedulers, you can enhance the quality of the generated images and include specific features or elements through textual prompts.

Input Requirements

  • Mask: A URI pointing to the input mask used in inpaint mode. Black areas are preserved while white areas are inpainted.
  • Seed: An optional integer for deterministic seeding.
  • Image: A URI for the input image used in img2img or inpaint mode.
  • Width: Specifies the width of the output image (default is 1024 pixels).
  • Height: Specifies the height of the output image (default is 1024 pixels).
  • Prompt: A text prompt guiding the image generation process.
  • Lora Scale: A multiplier for LoRA model scales, applicable on trained models.
  • Output Count: Number of images to generate (default is 1; maximum is 4).
  • Refine Style: The refinement style to apply on the generated images.
  • Guidance Scale: Scale factor for classifier-free guidance (default is 7.5).
  • Noise Fraction: For expert ensemble refiner, specifies the fraction of noise applied.
  • Apply Watermark: Option to include a watermark on generated images.
  • Inference Steps: Total number of denoising steps (default is 50).
  • Negative Prompt: Text prompt for elements to exclude from the image.
  • Prompt Strength: Strength of the input prompt (maximum destruction of original content at 1.0).
  • Refinement Steps: Number of refinement steps for base image refiner.
  • Scheduling Algorithm: Algorithm used to schedule the steps for image generation.
  • Disable Safety Checker: Boolean to toggle the safety checker for images.

Expected Output

The action will return a URI pointing to the generated image, showcasing the modifications based on the provided mask, prompt, and other parameters.

Example Input

{
  "width": 1824,
  "height": 1312,
  "prompt": "a portrait of StaniDani",
  "loraScale": 0.6,
  "outputCount": 1,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "noiseFraction": 0.8,
  "applyWatermark": true,
  "inferenceSteps": 50,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "schedulingAlgorithm": "K_EULER"
}

Example Output

[
  "https://assets.cognitiveactions.com/invocations/155da893-9195-4da3-9884-2f38fbed0e70/44965432-49ba-487c-980d-eb88c74c1f67.png"
]

Use Cases for this Specific Action

  • Restoring Images: Perfect for restoring damaged images or removing unwanted elements while keeping the rest intact.
  • Creative Transformations: Ideal for artists looking to transform their artwork by adding new features or styles.
  • Content Generation: Useful for marketers needing quick visuals for campaigns, allowing for rapid prototyping and iteration.

```python
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 = "334ea1cf-38dd-4092-ab47-f5cafb601583" # Action ID for: Generate Image with Inpainting

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "width": 1824,
  "height": 1312,
  "prompt": "a portrait of StaniDani",
  "loraScale": 0.6,
  "outputCount": 1,
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "noiseFraction": 0.8,
  "applyWatermark": true,
  "inferenceSteps": 50,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "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
Stanidani's inpainting capabilities offer developers an advanced toolset to create and enhance images efficiently. By integrating these Cognitive Actions into your applications, you can streamline your image generation processes, allowing for greater creativity and quicker turnaround times. Whether for artistic purposes, marketing, or content creation, the potential applications are vast. Start exploring today to see how Stanidani can elevate your visual projects!