Enhance Your Images with Inpainting Using M M M Cognitive Actions

27 Apr 2025
Enhance Your Images with Inpainting Using M M M Cognitive Actions

In the world of digital content creation, the ability to generate high-quality images tailored to specific needs can significantly enhance user engagement and experience. The "M M M" service provides a powerful Cognitive Action for image generation, specifically through a feature known as "Generate Image with Inpainting." This action allows developers to create images based on detailed prompts, including options for inpainting, custom dimensions, and multiple output formats, all while optimizing for quality and speed.

Imagine needing to produce a unique visual representation for a marketing campaign or an article. This Cognitive Action can help you generate realistic images that align perfectly with your vision, whether it's for social media posts, website graphics, or any other digital content. By leveraging advanced parameters like LoRA intensity and diffusion steps, you can ensure the images not only meet but exceed your quality standards.

Prerequisites

To utilize the M M M Cognitive Actions, you will need an API key and a basic understanding of making API calls. This will enable you to effectively integrate the image generation capabilities into your applications.

Generate Image with Inpainting

The "Generate Image with Inpainting" action is designed to produce images based on user-defined prompts and parameters. This action is particularly useful for scenarios where you need to create or modify images to fit specific requirements.

Purpose

This action allows you to generate images by specifying a detailed prompt while offering flexibility for inpainting existing images. It solves the problem of needing customized visuals without the need for extensive graphic design skills or resources.

Input Requirements

The input is structured as a JSON object that includes several properties:

  • prompt (required): A detailed description of the desired image.
  • mask: An optional image mask for inpainting.
  • image: An optional base image for modification.
  • width and height: Specify dimensions if using custom aspect ratios.
  • outputCount: Number of images to generate (1-4).
  • outputFormat: Choose from supported formats like webp, jpg, or png.
  • Additional parameters such as guidanceScale, loraScale, and inferenceModel can further refine the output.

Example input:

{
  "prompt": "Create a realistic visual of a south korean middle aged lady looking at the camera...",
  "loraScale": 1,
  "outputCount": 1,
  "outputFormat": "webp",
  "enableFastRun": false,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "inferenceStepsCount": 28
}

Expected Output

The output will be a URL linking to the generated image in the specified format. For example:

"https://assets.cognitiveactions.com/invocations/80decfed-79c9-4b61-a618-a4289801a51d/969009c5-4666-47e3-b3cc-2cb5b321e706.webp"

Use Cases for this Specific Action

  • Marketing Campaigns: Create unique visuals that reflect brand messaging and aesthetics.
  • E-commerce: Generate product images tailored to specific styles or themes.
  • Content Creation: Produce engaging visuals for blogs, articles, or social media posts that require a specific look or feel.
  • Artistic Projects: Enable artists and designers to experiment with new concepts and ideas without starting from scratch.
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 = "ba07a75f-969c-47e3-8839-4b0574569925" # 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 = {
  "prompt": "Create a realistic visual of a south korean middle aged lady looking at the camera. Do not include lettering or any type of logo or brand reference. \n\nThe image must be bright and dominated by white and luminous, full of light, filled with positive energy.\n\nUse the red colour,, black, and white only. White should cover 70% of the image, red 25% and black even less.\n\nHigh fidelity authentic and real images.\n\nThe setting is modern and sleek, emphasizing clean lines and high-tech aesthetics. \n\nInclude a shallow depth of field for a blurred background effect, emulating a DSLR camera, using a 50mm lens at f/1.8 for a shallow depth of field\nComposition: Use rule of thirds, framing, and perspective \nStrictly avoiding stylized, cartoonish, or exaggerated features, ensuring a realistic human portrayal. Avoid cartoonish, animated, or exaggerated styles. The image must look indistinguishable from a real photograph.\n",
  "loraScale": 1,
  "outputCount": 1,
  "outputFormat": "webp",
  "enableFastRun": false,
  "guidanceScale": 3,
  "outputQuality": 80,
  "extraLoraScale": 1,
  "inferenceModel": "dev",
  "promptStrength": 0.8,
  "imageMegapixels": "1",
  "imageAspectRatio": "1:1",
  "inferenceStepsCount": 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 "Generate Image with Inpainting" action from the M M M service empowers developers to create customized, high-quality images efficiently. By leveraging detailed prompts and flexible parameters, you can easily produce visuals that meet your specific needs, enhancing the overall quality of your digital content.

As you explore these Cognitive Actions, consider integrating them into your projects to see how they can elevate your visual content strategy. Whether for marketing, e-commerce, or creative endeavors, the possibilities are endless!