Transform Your Images with Enhanced Inpainting Using Op Test

25 Apr 2025
Transform Your Images with Enhanced Inpainting Using Op Test

In the world of digital content creation, the ability to modify and enhance images is invaluable. Op Test provides a powerful Cognitive Action called "Generate Enhanced Inpainted Image," which allows developers to seamlessly create modified versions of existing images. This action leverages advanced inpainting techniques to enhance images with customizable options that cater to various needs. Whether you're looking to improve the aesthetic quality of an image or need to adapt it for specific dimensions and alignment, this action makes the process fast and straightforward.

Common use cases for this action include graphic design, game development, and social media content creation, where unique and visually appealing images are essential. By using the enhanced inpainting capabilities of Op Test, developers can save time while ensuring high-quality outputs that meet their creative requirements.

Prerequisites

To get started, you will need an Op Test Cognitive Actions API key and a general understanding of making API calls.

Generate Enhanced Inpainted Image

The "Generate Enhanced Inpainted Image" action is designed to modify an input image through inpainting. It offers a range of customizable options, allowing you to specify dimensions, alignment, overlap features, and guidance to refine the output. This action is particularly useful for generating consistent results by allowing you to set a random seed for reproducibility.

Input Requirements:

  • Image: The URI of the base image to be modified (e.g., https://example.com/image.png).
  • Width: The output image width in pixels (default is 1280).
  • Height: The output image height in pixels (default is 1024).
  • Prompt: Descriptive keywords to guide the image generation (default is "High quality, 4K, UHD").
  • Guidance: A scale factor that adjusts adherence to the prompt (default is 30).
  • Alignment: Determines the image alignment (options: Middle, Left, Right, Top, Bottom; default is Middle).
  • Overlap Options: Control outpainting features on different sides of the image (default values: Top - true, Left - true, Right - false, Bottom - false).
  • Resize Option: Specifies how the image should be resized (options include Full, 50%, 33%, 25%, Custom; default is Full).
  • Num Inference Steps: The number of inference steps during image generation (default is 28).
  • Overlap Percentage: Percentage for image overlap during outpainting (default is 10).
  • Custom Resize Percentage: Specifies the percentage for custom resizing (default is 50).

Expected Output: The output will be a modified image or a set of images that reflect the specified enhancements. The results will be provided in the form of URIs, allowing for easy access and integration into your applications.

Use Cases for this specific action:

  • Graphic Design: Quickly modify images for promotional materials, ensuring they meet specific visual criteria.
  • Game Development: Create unique textures or backgrounds by inpainting existing assets, enhancing the game's visual appeal.
  • Social Media: Generate engaging visuals for posts by modifying existing images to fit specific themes or styles.
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 = "16565bab-300e-4619-bc68-343135325352" # Action ID for: Generate Enhanced Inpainted Image

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/MlYSaSOb3QaDtLorlxkRDkeH6uFi3lr9F3LB6yuXQ4Kn6ZxP/13039-2946705617-1girl%2C%20solo%2C%20long%20hair%2C%20bust%2C%20blindfold%2C%20blush%2C%20black%20hair%2C%20hair%20ornament%2C%20long%20sleeves%2C%20holding%2C%20off%20shoulders%2C%20closed%20mouth%2C%20s.png",
  "width": 1280,
  "height": 1024,
  "prompt": "High quailty, 4K, UHD",
  "guidance": 30,
  "alignment": "Right",
  "overlapTop": false,
  "overlapLeft": true,
  "overlapRight": false,
  "resizeOption": "Full",
  "overlapBottom": false,
  "numInferenceSteps": 28,
  "overlapPercentage": 15,
  "customResizePercentage": 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 "Generate Enhanced Inpainted Image" action from Op Test offers a robust solution for developers looking to enhance and modify images with ease. With its customizable options, you can produce high-quality outputs tailored to your specific needs, whether for design, gaming, or social media. Start integrating this action into your projects today to unlock new creative possibilities and streamline your image generation processes.