Seamlessly Merge Images with Cognitive Actions for Enhanced Creativity

In the world of digital content creation, the ability to manipulate and merge images is a powerful tool. The fofr/image-merge-sdxl API offers a robust set of Cognitive Actions that allow developers to seamlessly merge two images using a prompt to guide the integration process. With adjustable parameters for seed, steps, image dimensions, merge strength, and noise control, these pre-built actions simplify the image processing workflow and enhance creative possibilities.
Prerequisites
To get started with the Cognitive Actions provided by the fofr/image-merge-sdxl API, you’ll need:
- An API key for authentication.
- Basic understanding of JSON structure for constructing requests.
Authentication typically involves passing your API key in the request headers.
Cognitive Actions Overview
Merge Images with Prompt
Description:
This action enables you to merge two images based on a guiding prompt. It incorporates adjustable parameters that allow for fine-tuning the output, making it ideal for artistic applications and creative projects.
Category: Image Processing
Input
The input schema for this action is structured as follows:
- firstImage: (string, required) URI of the first image to be merged.
Example:"https://replicate.delivery/pbxt/KRyveMWjBWpI9NR6GuK1B1GoJMUhlvfUEa0yq6RWBqz3HaP5/ComfyUI_00319_.png" - secondImage: (string, required) URI of the second image to be merged.
Example:"https://replicate.delivery/pbxt/KRyveLQ82s8OdaAqUNIV5kbH3dPIdrGTqO9ka1IK5TecpWz0/output-0.png" - seed: (integer, optional) A fixed seed for random number generation to ensure result consistency.
- steps: (integer, optional) The number of iterative steps to process the image. Default is 20.
- width: (integer, optional) Defines the width of the output image in pixels. Default is 1024.
- height: (integer, optional) Defines the height of the output image in pixels. Default is 1024.
- prompt: (string, optional) A textual description to influence the style and content of the merged image.
Example:"a bright abstract painting of a cyborg" - batchSize: (integer, optional) Number of images to be processed concurrently, ranging from 1 to 8.
- primaryModel: (string, optional) Selects the underlying model for image prediction. Default is
"albedobaseXL_v13.safetensors". - mergeStrength: (number, optional) Controls the balance between merging strength and prompt influence. Ranges from 0 to 1.
- negativePrompt: (string, optional) Specifies unwanted elements to exclude from the merged image.
- addedMergeNoise: (number, optional) Introduces noise levels for greater control by the prompt. Ranges from 0 to 1.
Example Input:
{
"steps": 20,
"width": 1024,
"height": 1024,
"prompt": "a bright abstract painting of a cyborg",
"batchSize": 1,
"firstImage": "https://replicate.delivery/pbxt/KRyveMWjBWpI9NR6GuK1B1GoJMUhlvfUEa0yq6RWBqz3HaP5/ComfyUI_00319_.png",
"secondImage": "https://replicate.delivery/pbxt/KRyveLQ82s8OdaAqUNIV5kbH3dPIdrGTqO9ka1IK5TecpWz0/output-0.png",
"primaryModel": "albedobaseXL_v13.safetensors",
"mergeStrength": 0.92,
"negativePrompt": "",
"addedMergeNoise": 0
}
Output
The output of this action typically returns a URL of the merged image:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/c56299ab-19c0-4b59-981d-d45f577afa49/f82eec8b-9838-46b4-ab9a-5bb22016c4ce.png"
]
Conceptual Usage Example (Python)
Here’s a conceptual example of how to call the Merge Images with Prompt 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 = "ae309492-aacb-4c13-859a-e9146f7b7b12" # Action ID for Merge Images with Prompt
# Construct the input payload based on the action's requirements
payload = {
"steps": 20,
"width": 1024,
"height": 1024,
"prompt": "a bright abstract painting of a cyborg",
"batchSize": 1,
"firstImage": "https://replicate.delivery/pbxt/KRyveMWjBWpI9NR6GuK1B1GoJMUhlvfUEa0yq6RWBqz3HaP5/ComfyUI_00319_.png",
"secondImage": "https://replicate.delivery/pbxt/KRyveLQ82s8OdaAqUNIV5kbH3dPIdrGTqO9ka1IK5TecpWz0/output-0.png",
"primaryModel": "albedobaseXL_v13.safetensors",
"mergeStrength": 0.92,
"negativePrompt": "",
"addedMergeNoise": 0
}
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 and the input payload are structured according to the action's requirements.
Conclusion
The Merge Images with Prompt action from the fofr/image-merge-sdxl API provides developers with a powerful tool for innovative image processing. By leveraging the flexibility of prompts and adjustable parameters, you can create unique and compelling visuals that enhance your applications. Explore the potential of these Cognitive Actions to transform your creative workflows today!