You need to enable JavaScript to run this app.
Lake AI Service

Lake AI Service

Copy page
Download PDF
Image processing
Image resampling
Copy page
Download PDF
Image resampling

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 introduction

Operator ID: las_image_resample

Core capabilities

  1. Multiple interpolation algorithms
  • nearest: fastest speed, suitable for pixel-style images
  • bilinear: balanced speed and quality
  • bicubic: smoother, high-quality scaling
  • lanczos: superior anti-aliasing, suitable for photos
  1. URL / TOS input support
  • image_src_type=image_url: input public URL
  • image_src_type=image_tos: input tos:// address
  1. Output to TOS
  • tos_dir is required and specifies the output directory (folder level)
  • The output file name is generated by the server (image_name can assist with naming), and the _resample suffix is appended for identification.
  1. Output format and DPI control
  • Output formats supported: .jpg / .png
  • Supports setting output DPI (target_dpi) with effect display

Supported regions

  • Beijing: cn-beijing
  • Shanghai: cn-shanghai
  • Guangzhou: cn-guangzhou

Operator performance

Sub-item
Performance impact description

Maximum RPM

600

Input and output requirements

Input requirements

Subdivision

Detailed requirements

Supported input data modalities

  • Image

Input format: image

  • Format: JPEG/PNG/TIFF (JPG/TIF aliases are supported).
  • Size: The file must not exceed 100MB or 225,000,000 pixels.

Input path requirements

  • Provide the input image through image as an accessible HTTP/HTTPS URL or TOS path.
    • Public URLs requiring login or extra headers are unsupported; temporary URLs must remain valid during processing.
    • The TOS object must be in the same account and region as LAS and be readable; use a path such as tos://bucket_name/path/to/image.

Output requirements

Subdivision

Detailed requirements

Output data modality

  • Image

Output format: image

  • Format: .jpg or .png.
  • Dimensions: target_size must contain two positive integers. Output must not exceed 36,000,000 pixels or the input width and height. Aspect ratio is not preserved automatically.
  • DPI: target_dpi only changes DPI metadata, not output pixel dimensions.

Output path: TOS

  • Use tos_dir to specify a writable TOS output directory such as tos://bucket/output/.
    • The returned image_path is the complete TOS path; no additional concatenation is required.

Billing description
  • 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: CNY/million images, billed hourly based on actual usage.

    Unit price

    Depends on the resolution of the input images.

  • Billing details
    Billing formula: Total cost = unit price * usage

    Detailed scenarios
    Unit price
    • Input image resolution: 16k

    600 CNY/million images

    • Input image resolution: 12k

    350 CNY/million images

    • Input image resolution: 4k

    50 CNY/million images

Cautions and prerequisites

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.
For details, see Obtain the Base URL. The Examples below are for reference only; when making actual calls, replace the path values with those corresponding to your region.

REST API invocation

Interface description

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.

Request parameters

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.

Response parameters

Parameter
Type
Example value
Description
metadata
metadata
Metadata of the request.
data
result
Returned when processing succeeds; omitted when processing fails.

Examples

Request example

# 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

Response example

{
  "metadata": {
    "task_status": "COMPLETED",
    "business_code": "0",
    "error_msg": "",
    "request_id": "c7b29d78a99f88beda5497753ed60816"
  },
  "data": {
    "image_path": "tos://xxxx/las_image_resample/output/sample_resample.jpg"
  }
}

Daft invocation

Operator parameters

Input

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.

Output

An array of dictionaries containing processing results. Each element includes:

  • base64: base64 encoding of the resampled image;
  • image_path: local/TOS storage path (valid when output directory is configured)

Parameters

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"

Examples

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…         │
    # ╰────────────────────────────────┴────────────────┴────────────────────────────────────────╯
Last updated: 2026.09.03 16:27:53