Animate Images Seamlessly with the leonmak/svd Cognitive Actions

22 Apr 2025
Animate Images Seamlessly with the leonmak/svd Cognitive Actions

In the world of digital content, animation can bring static images to life, making them more engaging and dynamic. The leonmak/svd Cognitive Actions provide developers with a powerful toolset to animate images using state-of-the-art techniques such as Singular Value Decomposition (SVD) and in-painting. This blog post will guide you through the capabilities of these actions, focusing on how to integrate them into your applications, enhancing user experience with animated content.

Prerequisites

To get started with the leonmak/svd Cognitive Actions, you'll need:

  • A valid API key for the Cognitive Actions platform.
  • Basic knowledge of RESTful APIs and JSON.
  • Python installed on your development environment for testing the code examples.

Authentication typically involves passing your API key in the headers of your requests, ensuring secure access to the Cognitive Actions.

Cognitive Actions Overview

Animate Image with In-Painting

Description:
Transform RGBA encoded images by animating selected regions using Singular Value Decomposition (SVD) and in-painting techniques. This action enhances dynamic content by manipulating alpha channels while preserving original RGB values for seamless animations.

Category: image-animation

Input

The input for this action requires the following fields:

  • imagePath (string, required): The URI of the input image to be animated.
  • frames (integer, optional): The number of frames to process. Default is 28.
  • fileFormat (string, optional): The desired output file format. Options include "image/gif", "image/webp", "video/h264-mp4", "video/h265-mp4", and "video/webm". Default is "image/gif".
  • growMaskBy (integer, optional): The amount to enlarge the mask by (0 to 50). Default is 6.
  • maskRadius (number, optional): The radius of the mask (1 to 50). Default is 10.1.
  • configValue (number, optional): Configuration value (0 to 10). Default is 2.5.
  • kSamplerSteps (integer, optional): Number of sampling steps (1 to 90). Default is 20.
  • motionBucketId (integer, optional): Overall motion definition (1 to 255). Default is 127.
  • framesPerSecond (integer, optional): The desired FPS for the output. Default is 14.
  • compressionFactor (integer, optional): The compression factor (0 to 100). Default is 20.
  • conditionalAugmentation (number, optional): The degree of noise augmentation (-0.4 to 0.4). Default is 0.02.

Example Input:

{
  "frames": 28,
  "imagePath": "https://replicate.delivery/pbxt/JynV692sdM5PCawSFUpj3YJ5lFkBpwcKztbkMMVN9VX6A9L8/clipspace-mask-409893.90000000596.png",
  "fileFormat": "image/gif",
  "growMaskBy": 6,
  "maskRadius": 10.1,
  "configValue": 2.5,
  "kSamplerSteps": 20,
  "motionBucketId": 81,
  "framesPerSecond": 14,
  "compressionFactor": 20,
  "conditionalAugmentation": 0.01
}

Output

The action typically returns a URL to the generated animated output, which can be an animated GIF or video format, depending on the specified file format.

Example Output:

https://assets.cognitiveactions.com/invocations/c8ae467b-9586-4f6d-9aa3-0da968225824/c5e50b72-b59a-46fa-8819-6bee4d809d05.gif

Conceptual Usage Example (Python)

Here’s a conceptual example of how you might call the Animate Image with In-Painting 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 = "c31ff4f7-e12b-4de1-b5c7-0092fc892a0c" # Action ID for Animate Image with In-Painting

# Construct the input payload based on the action's requirements
payload = {
    "frames": 28,
    "imagePath": "https://replicate.delivery/pbxt/JynV692sdM5PCawSFUpj3YJ5lFkBpwcKztbkMMVN9VX6A9L8/clipspace-mask-409893.90000000596.png",
    "fileFormat": "image/gif",
    "growMaskBy": 6,
    "maskRadius": 10.1,
    "configValue": 2.5,
    "kSamplerSteps": 20,
    "motionBucketId": 81,
    "framesPerSecond": 14,
    "compressionFactor": 20,
    "conditionalAugmentation": 0.01
}

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 must correspond to the Animate Image with In-Painting action, and the payload is structured as per the input schema requirements. This example demonstrates how to execute the action and handle responses gracefully.

Conclusion

The leonmak/svd Cognitive Actions provide developers with robust tools for animating images, allowing for enhanced user engagement through dynamic content. By following the examples and guidelines provided, you can easily integrate these actions into your applications. Explore the possibilities of image manipulation and animation to create unique and captivating experiences for your users.