Enhance Your Images with the farbodmehr/fcm3 Cognitive Actions

24 Apr 2025
Enhance Your Images with the farbodmehr/fcm3 Cognitive Actions

In today's digital landscape, image processing has become a crucial component of many applications. The farbodmehr/fcm3 API offers a powerful set of Cognitive Actions that allow developers to perform advanced image manipulation, including image inpainting. These pre-built actions streamline the process of enhancing and refining images, enabling developers to integrate sophisticated image processing capabilities into their applications seamlessly.

Prerequisites

Before you start using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform. This key is essential for authenticating your requests.
  • Basic knowledge of how to make HTTP requests in your preferred programming language (e.g., Python).

Authentication typically involves passing your API key in the request headers to access the Cognitive Actions securely.

Cognitive Actions Overview

Perform Image Inpainting

The Perform Image Inpainting action allows you to execute an image inpainting operation. By providing specific masks and prompts, developers can generate and refine images with customizable properties such as size, style, guidance scale, and watermarking.

Input

The action requires a structured input defined by the following schema:

  • mask: (string, required) URI of the input mask for inpaint mode. Black areas are preserved, while white areas are inpainted.
  • seed: (integer, optional) Sets the random seed for generating images. Leave blank to use a randomized seed.
  • image: (string, required) URI of the input image for img2img or inpaint mode.
  • width: (integer, optional) The width of the output image in pixels. Default is 1024.
  • height: (integer, optional) The height of the output image in pixels. Default is 1024.
  • prompt: (string, optional) The prompt input for generating images. Default is "An astronaut riding a rainbow unicorn."
  • loraWeights: (string, optional) Specifies the LoRA weights to use. Leave blank to use default weights.
  • refineSteps: (integer, optional) Number of steps for base_image_refiner to refine the image.
  • refineStyle: (string, optional) The style to use for refining the image. Default is "no_refiner."
  • guidanceScale: (number, optional) Guidance scale factor for classifier-free guidance. Default is 7.5.
  • schedulerType: (string, optional) The type of scheduler to use for inference. Default is "K_EULER."
  • applyWatermark: (boolean, optional) Determines whether a watermark is applied to the generated image. Default is true.
  • negativePrompt: (string, optional) Input prompt to specify attributes to be avoided in the image generation.
  • promptStrength: (number, optional) Strength of the prompt when using img2img or inpaint modes. Default is 0.8.
  • numberOfOutputs: (integer, optional) The number of images to produce. Default is 1.
  • highNoiseFraction: (number, optional) Fraction of noise to introduce when using expert_ensemble_refiner. Default is 0.8.
  • loraIntensityScale: (number, optional) Determines the additive scale for LoRA models. Default is 0.6.
  • disableSafetyChecker: (boolean, optional) Toggles the safety checker for generated images off.
  • numberOfInferenceSteps: (integer, optional) Specifies the number of denoising steps. Default is 50.

Example Input:

{
  "width": 1024,
  "height": 1024,
  "prompt": "soccer player in style of TOK",
  "refineStyle": "no_refiner",
  "guidanceScale": 7.5,
  "schedulerType": "K_EULER",
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "highNoiseFraction": 0.8,
  "loraIntensityScale": 0.6,
  "numberOfInferenceSteps": 50
}

Output

The action typically returns a URI linking to the generated image. For example:

Example Output:

[
  "https://assets.cognitiveactions.com/invocations/53ffa35f-9d4b-450d-bb10-743dd248798a/eb97c284-e75c-4995-9fc5-4ed0f8f5df4b.png"
]

Conceptual Usage Example (Python)

Here's how you might call the Perform Image Inpainting action using Python:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "31d29668-b9f0-4452-aa63-9ee13640e8b5"  # Action ID for Perform Image Inpainting

# Construct the input payload based on the action's requirements
payload = {
    "width": 1024,
    "height": 1024,
    "prompt": "soccer player in style of TOK",
    "refineStyle": "no_refiner",
    "guidanceScale": 7.5,
    "schedulerType": "K_EULER",
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "highNoiseFraction": 0.8,
    "loraIntensityScale": 0.6,
    "numberOfInferenceSteps": 50
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload}  # Hypothetical structure
    )
    response.raise_for_status()  # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    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: {e.response.text}")

In this code snippet, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id is set to the ID of the Perform Image Inpainting action. The input payload is structured according to the action's requirements.

Conclusion

The farbodmehr/fcm3 Cognitive Actions provide powerful capabilities for image processing, particularly through the Perform Image Inpainting action. By leveraging these tools, developers can enhance their applications with advanced image generation and refinement features. Consider exploring additional use cases or integrating other Cognitive Actions to further enrich your projects!