Enhance Image Realism with ControlNet's Inpainting Action

25 Apr 2025
Enhance Image Realism with ControlNet's Inpainting Action

In the world of image processing, enhancing the quality and realism of images is a key requirement for developers and artists alike. The Controlnet X Ip Adapter Realistic Vision V5 offers powerful Cognitive Actions that enable seamless image manipulation, particularly through its inpainting capabilities. This allows users to fill in missing parts of an image or modify existing elements while maintaining a high degree of realism and detail. By leveraging advanced features like multi-controlnet and IP Adapter variants, this service simplifies the process of creating stunning visual content, saving time and effort.

Prerequisites

To utilize these Cognitive Actions, you will need an API key from the Cognitive Actions platform and a basic understanding of making API calls.

Perform Image Inpainting with ControlNet

The Perform Image Inpainting with ControlNet action is designed to help developers enhance images by filling in areas that require modification or improvement. This action solves the common problem of incomplete or low-quality images by allowing users to specify prompts and masks that guide the inpainting process, resulting in visually appealing and coherent images.

Input Requirements: The inpainting action requires a structured input, including:

  • prompt: A detailed description of the image you want to generate or modify.
  • maskImage: A URI pointing to the mask image that indicates which areas to inpaint.
  • guidanceScale: A number that adjusts the influence of the prompt on the image generation.
  • Additional parameters like negativePrompt, scheduler, and various image URIs for control images.

Example Input:

{
  "prompt": "a bookmark showcasing rippling water in a forest, depicted in a detailed illustration style...",
  "maskImage": "https://example.com/mask.png",
  "guidanceScale": 7,
  "numberOfImages": 1,
  "maximumImageWidth": 512,
  "ipAdapterIntensity": 0.7
}

Expected Output: The output will be a high-quality image URL that reflects the modifications based on the provided prompt and mask.

[
  "https://assets.cognitiveactions.com/invocations/8ad8bde9-02b0-4228-a4b9-1259e66d7d0a/f9f45245-b1c6-47e2-8601-b3859d4916cb.png"
]

Use Cases for this Specific Action:

  • Restoring Old Photos: Developers can use inpainting to fill in missing parts of damaged photographs, bringing them back to life.
  • Creative Design: Artists can manipulate existing images by removing unwanted elements or adding new ones, allowing for creative freedom in their designs.
  • Game Development: Inpainting can be utilized to create immersive environments by modifying textures and backgrounds dynamically based on user input.
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 = "9877d9f8-45d4-45cd-a226-1dd9ad91952e" # Action ID for: Perform Image Inpainting with ControlNet

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "eta": 0,
  "prompt": "a bookmark showcasing rippling water in a forest, depicted in a detailed illustration style. The artwork captures the moonlit water, accentuated by the reflection of the moon above. Rich and vibrant colors intensify the moonlit ambiance. The lighting casts dramatic shadows, enhancing the depth and texture of the scene. Pro vector, perfect MINIMALISTIC art HIGH QUALITY details, Ultra high details, full design, victoria, vibrant vector, deep lines, heavy strokes",
  "guessMode": false,
  "scheduler": "K_EULER_ANCESTRAL",
  "guidanceScale": 7,
  "scribbleImage": "https://replicate.delivery/pbxt/K7J0YI1KOZ88qUL7eT6HORXPIlXTXvuSkZv99Z1MIEAP5Lq6/Screenshot_20231226-060658.jpg",
  "negativePrompt": "(worst quality)++ ,(low quality)++ ,(normal quality)++ , lowres ,watermark ,",
  "numberOfImages": 1,
  "maximumImageWidth": 512,
  "sortedControlnets": "tile, inpainting, lineart",
  "disableSafetyCheck": false,
  "internalParameters": "",
  "ipAdapterIntensity": 0.7,
  "maximumImageHeight": 1024,
  "filmGrainLoraWeight": 0,
  "inferenceStepsCount": 20,
  "ipAdapterCheckpoint": "ip-adapter-plus-face_sd15.bin",
  "imageToImageStrength": 0.5,
  "tileConditioningScale": 1,
  "addMoreDetailLoraScale": 0,
  "detailTweakerLoraWeight": 0,
  "epiNoiseOffsetLoraWeight": 0,
  "lineartConditioningScale": 0.6,
  "scribbleConditioningScale": 0,
  "brightnessConditioningScale": 1,
  "inpaintingConditioningScale": 1,
  "colorTempratureSliderLoraWeight": 0
}

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 Controlnet X Ip Adapter Realistic Vision V5 offers developers a robust tool for image inpainting, enabling the enhancement of image realism with ease. With its flexible input options and high-quality output, this action can be applied across various fields, from photography restoration to creative design and gaming. To get started, integrate this action into your projects and explore the endless possibilities of image manipulation.