Enhance Your Image Processing with datong-new/sam-point Cognitive Actions

In the world of image processing, having the right tools can make all the difference. The datong-new/sam-point API provides a powerful set of Cognitive Actions aimed at simplifying the manipulation and analysis of images. With these pre-built actions, developers can easily integrate advanced image processing capabilities into their applications without needing to start from scratch. In this blog post, we will explore one of the key actions available in this spec and how to leverage it effectively.
Prerequisites
Before diving into 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 familiarity with JSON and HTTP requests.
Authentication typically involves passing your API key in the headers of your requests, as shown in the examples below.
Cognitive Actions Overview
Process Image with Dilate and Regions
This action processes an image by applying a specified amount of dilation and allows targeting specific regions through coordinates. It accepts an RGB image URI as input, enabling precise control over image region processing.
- Category: Image Processing
Input
The input for this action is structured as follows:
{
"image": "https://replicate.delivery/pbxt/KX6QL1Amx5wP1zDvjyr5QNeObbrF7TR1aHGPA6JzNoBEdVEV/cup1.png",
"inputPoints": "[[950,950]]",
"dilate": 0,
"inputBox": ""
}
Required Fields:
image: A string representing the URI of the RGB image to be processed. This image must be accessible at the provided URL.
Optional Fields:
dilate: An integer specifying the amount of dilation to apply to the image. The default value is 0, meaning no dilation.inputBox: A string representing coordinates for a specific region of interest within the image.inputPoints: A string specifying the coordinates of points within the image for specific processing tasks (e.g.,[[950,950]]).
Example Input
Here’s an example of the JSON payload used to invoke this action:
{
"image": "https://replicate.delivery/pbxt/KX6QL1Amx5wP1zDvjyr5QNeObbrF7TR1aHGPA6JzNoBEdVEV/cup1.png",
"inputPoints": "[[950,950]]"
}
Output
Upon successful execution, the action returns a list of URLs pointing to the processed images. Here are some example outputs:
[
"https://assets.cognitiveactions.com/invocations/fd9276c4-c1df-4181-a984-f79de3ad8ab2/88bcd4d4-be58-4943-9088-3d809941d37e.png",
"https://assets.cognitiveactions.com/invocations/fd9276c4-c1df-4181-a984-f79de3ad8ab2/a6022b10-6438-441c-b9a4-df22a3b11918.png",
"https://assets.cognitiveactions.com/invocations/fd9276c4-c1df-4181-a984-f79de3ad8ab2/35b23953-a876-4d69-ab5d-db42bcfedfb6.png",
"https://assets.cognitiveactions.com/invocations/fd9276c4-c1df-4181-a984-f79de3ad8ab2/04646175-61fe-440d-a301-113893505471.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Process Image with Dilate and Regions 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 = "02fdbac3-8413-49f7-b65e-2773bb7e033c" # Action ID for Process Image with Dilate and Regions
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/KX6QL1Amx5wP1zDvjyr5QNeObbrF7TR1aHGPA6JzNoBEdVEV/cup1.png",
"inputPoints": "[[950,950]]"
}
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_KEYwith your actual API key. - The
action_idcorresponds to the specific action you are invoking. - The
payloadis structured according to the input schema, ensuring that all required fields are included.
Conclusion
The datong-new/sam-point Cognitive Actions provide an efficient way to enhance your image processing capabilities. By integrating actions like Process Image with Dilate and Regions, you can manipulate images with precision and ease. Consider experimenting with other actions in this spec to further enrich your applications. Happy coding!