The image resampling operator is used to perform size resampling (downsampling only) on the input image and save the result to the TOS directory specified by the user. Supports four interpolation algorithms (nearest/bilinear/bicubic/lanczos) and .jpg / .png output formats. Suitable for image preprocessing, data normalization, offline dataset construction, and similar scenarios.
Operator ID: las_image_resample
image_src_type=image_url: input public URLimage_src_type=image_tos: input tos:// addresstos_dir is required and specifies the output directory (folder level)_resample suffix is appended for identification..jpg / .pngtarget_dpi) with effect displaySub-item | Performance impact description |
|---|---|
Maximum RPM | 600 |
Subdivision | Detailed requirements |
|---|---|
Supported input data modalities |
|
Input format: image |
|
Input path requirements |
|
Subdivision | Detailed requirements |
|---|---|
Output data modality |
|
Output format: image |
|
Output path: TOS |
|
Billing standards
Itemization | Billing standards description |
|---|---|
Billing item | Usage is calculated based on the number of input images, and billed accordingly. |
Billing type | Usage-based billing, unit: |
Unit price | Depends on the resolution of the input images. |
Billing details
Billing formula: Total cost = unit price * usage
Detailed scenarios | Unit price |
|---|---|
| 600 CNY/million images |
| 350 CNY/million images |
| 50 CNY/million images |
Details | Caution and prerequisites |
|---|---|
Costs | Before calling an operator, you need to understand the model invocation costs associated with using the operator. For details, see Large model invocation billing. |
Authentication (API Key) | Before calling an operator, you need to generate an API Key for operator invocation. It is recommended to configure the API Key as an environment variable to ensure safer operator calls. For details, see Obtain and configure API Key. |
BaseURL | Before calling an operator, you need to determine the BaseURL for operator invocation based on the region where your current LAS service is deployed. This is used to configure the path parameter values for operator calls. |
Invoke the las_image_resample operator to resample the input image (downsampling only) and save the result to the TOS directory specified by the user.
Parameter | Type | Required | Example value | Description |
|---|---|---|---|---|
operator_id | string | Required | las_image_resample | The ID of this operator is las_image_resample. |
operator_version | string | Required | v1 | Currently only v1 is supported. |
data | process_param | Required | Operator parameters. |
Parameter | Type | Example value | Description |
|---|---|---|---|
metadata | metadata | Metadata of the request. | |
data | result | Returned when processing succeeds; omitted when processing fails. |
# Please set INPUT_IMAGE_URL to an accessible image URL export INPUT_IMAGE_URL="https://example.com/sample.jpg" # Please set OUTPUT_TOS_DIR to a writable TOS directory (folder) under the current account export OUTPUT_TOS_DIR="tos://xxxx/las_image_resample/output" curl --location "${LAS_ENDPOINT}/api/v1/process" \ --header "Content-Type: application/json" \ --header "Authorization: Bearer $LAS_API_KEY" \ --data @- <<EOF { "operator_id": "las_image_resample", "operator_version": "v1", "data": { "image_src_type": "image_url", "image": "$INPUT_IMAGE_URL", "tos_dir": "$OUTPUT_TOS_DIR", "image_suffix": ".jpg", "target_size": [200, 200], "target_dpi": [72, 72], "method": "lanczos" } } EOF
{ "metadata": { "task_status": "COMPLETED", "business_code": "0", "error_msg": "", "request_id": "c7b29d78a99f88beda5497753ed60816" }, "data": { "image_path": "tos://xxxx/las_image_resample/output/sample_resample.jpg" } }
Input column name | Description |
|---|---|
images | An array containing input images. Supports URL/base64/binary formats. |
images_name | Optional parameter. An array containing image identifiers, used to generate output file names. It is recommended to provide this to ensure file name uniqueness and not include a suffix. If not provided, a random name will be generated for images whose names cannot be parsed. |
An array of dictionaries containing processing results. Each element includes:
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
image_suffix | str | .jpg | Image format saved to TOS. Description: Image format saved to TOS. Default is '.jpg'. Optional values: [".jpg", ".png"]. Default value: ".jpg" |
tos_dir | str | TOS folder path for saving images. Description: TOS path for saving resampled images. If not set, resampled images will not be saved to TOS. Default value: "" | |
local_dir | str | Local folder path for saving images. Description: Local storage directory for adjusted images. If empty, adjusted images will not be saved locally. Default value: "" | |
image_src_type | str | image_url | Input image format type. Supports: - URL address (image_url) - base64 encoding (image_base64) - binary stream (image_binary) Description: Input image format type. Optional values: ["image_url", "image_base64", "image_binary"] Default value: "image_url" |
target_size | list | [200, 200] | Resampled image size. Description: The dimensions of the resampled image, in the format [width, height]. The default value is [200, 200]. Default value: [200, 200] |
target_dpi | list | [72, 72] | Image DPI. Description: Image DPI, in the format [width, height]. The default value is [72, 72]. Default value: [72, 72] |
method | str | lanczos | Resampling method. Description: The resampling method. Supported values are nearest (nearest neighbor interpolation), bilinear (bilinear interpolation), bicubic (bicubic interpolation), and lanczos (Lanczos interpolation). The default value is lanczos. Optional values: ["nearest", "bilinear", "bicubic", "lanczos"] Default value: "lanczos" |
The following code demonstrates how to use daft to run the operator for image resampling.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.image.image_resample import ImageResample from daft.las.functions.udf import las_udf if __name__ == "__main__": if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "image": [ f"https://{tos_dir_url}/public/shared_image_dataset/cat_ip_adapter.jpeg" ], "image_name": ["cat_ip_adapter"], } image_suffix = ".jpg" image_src_type = "image_url" target_size = (200, 200) target_dpi = (72, 72) method = "lanczos" local_dir = "" tos_dir = "" num_gpus = 0 ds = daft.from_pydict(samples) ds = ds.with_column( "image_resample", las_udf( ImageResample, construct_args={ "image_suffix": image_suffix, "tos_dir": tos_dir, "local_dir": local_dir, "image_src_type": image_src_type, "target_size": target_size, "target_dpi": target_dpi, "method": method, }, num_gpus=num_gpus, batch_size=1, )(col("image"), col("image_name")), ) ds.show() # ╭────────────────────────────────┬────────────────┬────────────────────────────────────────╮ # │ image ┆ image_name ┆ image_resample │ # │ --- ┆ --- ┆ --- │ # │ Utf8 ┆ Utf8 ┆ Struct[base64: Utf8, image_path: Utf8] │ # ╞════════════════════════════════╪════════════════╪════════════════════════════════════════╡ # │ https://las-cn-beijing-public… ┆ cat_ip_adapter ┆ {base64: iVBORw0KGgoAAAANSUhE… │ # ╰────────────────────────────────┴────────────────┴────────────────────────────────────────╯