Transform Images Effortlessly with Ich Test's Inpainting Action

26 Apr 2025
Transform Images Effortlessly with Ich Test's Inpainting Action

In the world of digital content creation, having the ability to transform and generate images can significantly enhance your projects. Ich Test offers a powerful Cognitive Action called "Transform Image with Inpainting," designed to enable developers to create and modify images with remarkable precision and creativity. This action allows you to generate images based on text prompts and customize various parameters such as aspect ratio, dimensions, and output format. The benefits are clear: faster image generation, improved quality, and the ability to tailor images to specific needs.

Common use cases include generating unique artwork, enhancing marketing materials, creating custom graphics for websites, and even modifying existing images to fit new contexts. Whether you're an artist, a marketer, or a developer, the inpainting action can streamline your workflow and elevate your visual content.

Prerequisites

To get started, you'll need an API key for the Cognitive Actions service and basic knowledge of how to make API calls.

Transform Image with Inpainting

The "Transform Image with Inpainting" action allows you to generate and modify images using a combination of image-to-image transformation and inpainting techniques, guided by a text prompt. This action is particularly valuable for developers looking to automate the image generation process while maintaining control over the output quality and characteristics.

  • Input Requirements: The input schema for this action consists of several parameters, with the essential one being the prompt, which is the text guiding the image generation. Additional optional parameters include:
    • image: URI of the input image.
    • mask: URI of the image mask for inpainting.
    • width and height: For custom aspect ratios.
    • numOutputs: The number of images you wish to generate (1-4).
    • guidanceScale: Influences the balance between realism and creativity.

    Here’s an example of an input:
    {
      "goFast": false,
      "prompt": "michael as managing director",
      "loraScale": 1,
      "numOutputs": 4,
      "guidanceScale": 3,
      "outputQuality": 80,
      "extraLoraScale": 1,
      "inferenceModel": "dev",
      "promptStrength": 0.8,
      "imageMegapixels": "1",
      "imageAspectRatio": "1:1",
      "imageOutputFormat": "webp",
      "numInferenceSteps": 28
    }
    
  • Expected Output: The output of this action is a collection of image URLs, each representing a generated image that matches the provided prompt and settings. For example:
    [
      "https://assets.cognitiveactions.com/invocations/f80b7072-7fe6-4441-b088-f27c640f923f/f6c8b7c3-5aef-4f91-90a7-d7a8b50363f0.webp",
      "https://assets.cognitiveactions.com/invocations/f80b7072-7fe6-4441-b088-f27c640f923f/e325653d-9f56-4b35-817c-eca04f7a81f6.webp",
      "https://assets.cognitiveactions.com/invocations/f80b7072-7fe6-4441-b088-f27c640f923f/3e985bb9-2739-442f-a995-451c6b515a0b.webp",
      "https://assets.cognitiveactions.com/invocations/f80b7072-7fe6-4441-b088-f27c640f923f/2d2adf39-63a1-4632-91a0-7d167b94c0dd.webp"
    ]
    
  • Use Cases for this Action: This action is ideal for scenarios where you need to create visually appealing content quickly. For instance:
    • Marketing Campaigns: Generate custom images that resonate with your target audience based on specific themes or concepts.
    • Artistic Projects: Artists can use this action to explore new styles and concepts, generating images from text prompts that inspire their work.
    • E-commerce: Enhance product images by modifying them to showcase different aspects or settings, increasing visual appeal to potential customers.

```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 = "2c34bb40-4ebd-44c5-a2c7-56e72d9e6859" # Action ID for: Transform 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 = {
  "goFast": false,
  "prompt": "michael as managing director",
  "loraScale": 1,
  "numOutputs": 4,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "imageOutputFormat": "webp",
  "numInferenceSteps": 28
}

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 "Transform Image with Inpainting" action from Ich Test empowers developers to create high-quality, customized images efficiently. With its flexibility and ease of use, you can streamline your image generation processes while exploring creative possibilities. Whether for marketing, artistic endeavors, or e-commerce applications, this action opens up new avenues for visual content creation. 

Ready to enhance your projects? Start integrating the inpainting action today and unlock the potential of automated image transformation!