Create Stunning Inpainted Images with Fine Tune Iteration3

27 Apr 2025
Create Stunning Inpainted Images with Fine Tune Iteration3

In the realm of digital content creation, the ability to generate and manipulate images is paramount. The Fine Tune Iteration3 service offers developers a powerful set of Cognitive Actions, specifically designed for image generation and customization. With the "Generate Inpainted Images" action, you can create visually striking images by inpainting specific areas based on textual prompts. This capability not only simplifies the creative process but also enhances productivity, allowing for rapid prototyping and diverse artistic expression.

Imagine a scenario where you want to modify an existing image by replacing certain elements or enhancing specific features. With this action, you can specify the areas to be inpainted, apply various styles, and even adjust parameters to achieve your desired outcome. Whether you're working on a marketing campaign, designing a game, or simply experimenting with art, this action provides the flexibility needed to bring your vision to life.

Prerequisites

To use the Fine Tune Iteration3 service, you'll need a valid Cognitive Actions API key and a basic understanding of making API calls. This will enable you to easily integrate the image generation capabilities into your applications.

Generate Inpainted Images

The "Generate Inpainted Images" action allows you to create images by inpainting specified areas based on your textual prompts. This operation is ideal for users looking to customize images with high precision and flexibility.

Input Requirements

To utilize this action, you need to provide several parameters:

  • mask: A URI of the mask image indicating which areas to modify (black areas remain unchanged, white areas will be modified).
  • image: A URI of the input image that will undergo inpainting.
  • prompt: Textual guidance for the image generation.
  • width: Width of the output image in pixels (default is 1024).
  • height: Height of the output image in pixels (default is 1024).
  • refine: Style refinement option (e.g., no_refiner, expert_ensemble_refiner).
  • numberOfOutputs: Number of images to generate (maximum of 4).
  • Additional parameters include seed, loraScale, scheduler, guidanceScale, and more, allowing for extensive customization.

Expected Output

The output will be a generated image that reflects the modifications specified in the input parameters. For example, an image could replace certain features based on the prompt while adhering to the mask provided.

Example Input

{
  "width": 1024,
  "height": 1024,
  "prompt": "a tile in black , light structure, glossy , rectified",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "low resolution, not realistic",
  "promptStrength": 0.2,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

Example Output

[
  "https://assets.cognitiveactions.com/invocations/77f00b0d-706d-4f63-83f2-555b32bab9b4/e294632e-4595-4270-8bfd-ded033635db4.png"
]

Use Cases for this Action

  • Creative Design: Tailor images for artistic projects by inpainting elements that need to be changed or enhanced, allowing for unique visual storytelling.
  • Game Development: Modify character designs or environments dynamically, providing artists with tools to iterate quickly on visual assets.
  • Marketing and Advertising: Quickly generate promotional materials by customizing existing images to fit specific campaigns, thus saving time and resources.

```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 = "df821f84-274c-4d42-bbf5-68e0a68fd7d3" # Action ID for: Generate Inpainted Images

# 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 tile in black , light structure, glossy , rectified",
  "refine": "no_refiner",
  "loraScale": 0.6,
  "scheduler": "K_EULER",
  "guidanceScale": 7.5,
  "applyWatermark": true,
  "negativePrompt": "low resolution, not realistic",
  "promptStrength": 0.2,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "numberOfInferenceSteps": 50
}

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
The Fine Tune Iteration3 service, particularly the "Generate Inpainted Images" action, empowers developers and creators to craft stunning images with ease and precision. By leveraging the flexibility of customizable parameters and high-quality outputs, you can enhance your projects and streamline your creative processes. Whether for personal use or professional applications, integrating this action into your workflow can significantly elevate the quality and efficiency of your image generation tasks. Start exploring the possibilities today!