Image concatenation combines two or more spatially overlapping images captured from different viewpoints and times into a single wide-perspective image. You can concatenate images by calling the CreateImageSplicingTask API operation.
Prerequisites
-
You have created an AccessKey pair. For more information, see Create an AccessKey pair.
-
You have activated OSS, created a bucket, and uploaded files to the bucket. For more information, see Upload files.
-
You have activated IMM. For more information, see Activate IMM.
-
You have created a project in the IMM console. For more information, see Create a project.
Note-
You can also call the CreateProject operation to create a project. For more information, see Create a project.
-
You can call the ListProjects operation to list all projects in a specified region.
-
Create a concatenation task
Call the CreateImageSplicingTask operation to concatenate multiple images. This operation is asynchronous and returns a TaskId for tracking the task status.
Query task information
Task information is retained for seven days after the task starts. After this period, you can no longer retrieve the task information.
You can query or receive task information by using one of the following methods:
-
Simple Message Queue (formerly MNS) -- In the region where the IMM project resides, configure an SMQ subscription to receive task notifications. For more information, see Asynchronous message examples. For information about the MNS SDK, see Step 4: Receive and delete the message.
-
ApsaraMQ for RocketMQ 4.0 -- In the region where the IMM project resides, create an ApsaraMQ for RocketMQ 4.0 instance, a topic, and a group to receive task notifications. For more information, see Asynchronous message examples. For information about ApsaraMQ for RocketMQ, see Use HTTP client SDKs to send and subscribe to normal messages.
-
EventBridge -- In the region where the IMM project resides, use EventBridge to receive task notifications. For more information, see IMM events.
Example
The following example concatenates two images from OSS and saves the result to a specified location.
Image information
-
IMM project: test-project
-
Source images:
-
oss://test-bucket/test-object.jpg1
-
oss://test-bucket/test-object.jpg2
-
-
Output image:
oss://test-bucket/test-target-object.jpg
Request example
{
"ProjectName": "test-project",
"Sources": "[{\"URI\": \"oss://test-bucket/test-object.jpg1\"},{\"URI\": \"oss://test-bucket/test-object.jpg2\"}]",
"TargetURI": "oss://test-bucket/test-target-object.jpg"
}
Response example
{
"TaskId": "ImageSplicing-1c73b551-381d-46cc-86ed-16905*****",
"RequestId": "657DE82D-5960-0309-810C-639637*****",
"EventId": "124-1S7JgMQdZ3kWQbmUqXxI3******"
}
Sample code (Python SDK)
The following example uses the IMM SDK for Python to concatenate images.
Replace the endpoint with the region where your IMM project resides. The example uses imm.cn-beijing.aliyuncs.com. For other regions, use the format imm.<region-id>.aliyuncs.com.
# -*- coding: utf-8 -*-
import sys
import os
from typing import List
from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient
class Sample:
def __init__(self):
pass
@staticmethod
def create_client(
access_key_id: str,
access_key_secret: str,
) -> imm20200930Client:
"""
Initialize the client with your AccessKey ID and AccessKey secret.
@param access_key_id:
@param access_key_secret:
@return: Client
@throws Exception
"""
config = open_api_models.Config(
access_key_id=access_key_id,
access_key_secret=access_key_secret
)
# Specify the IMM endpoint. Replace the region as needed.
config.endpoint = f'imm.cn-beijing.aliyuncs.com'
return imm20200930Client(config)
@staticmethod
def main(
args: List[str],
) -> None:
# Read the AccessKey pair from environment variables.
# Do not hardcode credentials in your code.
# Use a RAM user instead of your Alibaba Cloud account for API calls.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
sources_0 = imm_20200930_models.CreateImageSplicingTaskRequestSources(
uri='oss://test-bucket/test-object.jpg1'
)
sources_1 = imm_20200930_models.CreateImageSplicingTaskRequestSources(
uri='oss://test-bucket/test-object.jpg2'
)
create_image_splicing_task_request = imm_20200930_models.CreateImageSplicingTaskRequest(
project_name='test-project',
sources=[
sources_0,
sources_1
],
target_uri='oss://test-bucket/test-target-object.jpg'
)
runtime = util_models.RuntimeOptions()
try:
# Call the API to create an image concatenation task.
client.create_image_splicing_task_with_options(create_image_splicing_task_request, runtime)
except Exception as error:
# Handle errors as needed.
UtilClient.assert_as_string(error.message)
@staticmethod
async def main_async(
args: List[str],
) -> None:
# Read the AccessKey pair from environment variables.
# Do not hardcode credentials in your code.
# Use a RAM user instead of your Alibaba Cloud account for API calls.
imm_access_key_id = os.getenv("AccessKeyId")
imm_access_key_secret = os.getenv("AccessKeySecret")
client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
sources_0 = imm_20200930_models.CreateImageSplicingTaskRequestSources(
uri='oss://test-bucket/test-object.jpg1'
)
sources_1 = imm_20200930_models.CreateImageSplicingTaskRequestSources(
uri='oss://test-bucket/test-object.jpg2'
)
create_image_splicing_task_request = imm_20200930_models.CreateImageSplicingTaskRequest(
project_name='test-project',
sources=[
sources_0,
sources_1
],
target_uri='oss://test-bucket/test-target-object.jpg'
)
runtime = util_models.RuntimeOptions()
try:
# Call the API asynchronously.
await client.create_image_splicing_task_with_options_async(create_image_splicing_task_request, runtime)
except Exception as error:
# Handle errors as needed.
UtilClient.assert_as_string(error.message)
if __name__ == '__main__':
Sample.main(sys.argv[1:])
Billing
Image concatenation incurs charges on both the OSS side and the IMM side.
OSS charges
For pricing details, see OSS产品定价.
|
API |
Billable item |
Description |
|
GetObject |
GET requests |
Charged based on the number of successful requests. |
|
IA data retrieval |
If Infrequent Access (IA) objects are retrieved, charged based on the size of retrieved IA objects. |
|
|
Real-time access of Archive objects |
If Archive objects in a bucket with real-time access enabled are retrieved, charged based on the size of retrieved Archive objects. |
|
|
Transfer acceleration |
If transfer acceleration is enabled and an acceleration endpoint is used, charged based on the data size. |
|
|
PutObject |
PUT requests |
Charged based on the number of successful requests. |
|
Storage fees |
Charged based on the storage class, size, and storage duration of the object. |
|
|
HeadObject |
GET requests |
Charged based on the number of successful requests. |
IMM charges
For pricing details, see IMM billable items.
Starting from 11:00 on July 28, 2025 (UTC+8), the IMM image concatenation service changed from free to paid. For more information, see IMM计费调整公告.
|
API |
Billable item |
Description |
|
CreateImageSplicingTask |
ImageSplicing |
Charged based on the number of image concatenation operations. |