You need to enable JavaScript to run this app.
AI 数据湖服务

AI 数据湖服务

复制全文
图片处理
图像清晰度计算
复制全文
图像清晰度计算

算子ID:daft.las.functions.image.image_sharpness.ImageSharpness

算子介绍

描述

图像清晰度计算处理器,支持多种清晰度评估方法。

核心功能

  • 提供4种专业级清晰度评估方法:
    • 拉普拉斯方差法(laplacian) - 基于二阶导数的边缘检测,计算简单快速
    • Tenengrad法(tenengrad) - 基于Sobel梯度的边缘强度,对噪声敏感
    • Brenner法(brenner) - 基于相邻像素灰度差的简单计算,速度最快
    • FFT高频能量法(fft_highfreq) - 基于频域分析的清晰度评估,对模糊更敏感
  • 多格式输入支持:
    • URL地址(image_url)
    • Base64编码(image_base64)
    • 二进制流(image_binary)
  • 高精度计算:
    • 支持处理各种尺寸和格式的图像
    • 自动处理NaN值和异常情况

注意与前提

细分项

注意与前提

费用

调用算子前,您需先了解使用算子时的模型调用费用,详情请参见大模型调用计费

鉴权(API Key)

调用算子前,您需要先生成算子调用的API Key,并建议将API Key配置为环境变量,便于更安全地调用算子,详情请参见获取 API Key 并配置

BaseURL

调用算子前,您需要先根据您当前使用的LAS服务所在地域,了解算子调用的BaseURL,用于配置算子调用路径参数取值。
详情请参见获取 Base URL,下文中的调用示例仅作为参考,实际调用时需替换为您对应地域的路径取值。

Daft 调用

算子参数

输入

输入列名

说明

images

包含输入图像的数组,支持URL/base64/二进制格式

输出

包含清晰度计算结果的浮点数组

参数

如参数没有默认值,则为必填参数

参数名称

类型

默认值

描述

image_src_type

str

"image_url"

输入图像的格式类型,支持:

  • image_url:url地址
  • image_base64:base64编码
  • image_binary:二进制流

默认值: "image_url"

method

str

"laplacian"

清晰度计算方法,支持:

  • laplacian(拉普拉斯方差)
  • tenengrad(Tenengrad梯度)
  • brenner(Brenner梯度)
  • fft_highfreq(FFT高频能量)

默认为 laplacian。

调用示例

下面的代码展示了如何使用 daft 运行算子对图像做清晰度计算。

from __future__ import annotations

import os

import daft
from daft import col
from daft.las.functions.image.image_sharpness import ImageSharpness
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_src_type = "image_url"
    method = "laplacian"
    num_gpus = 0

    ds = daft.from_pydict(samples)
    ds = ds.with_column(
        "image_sharpness",
        las_udf(
            ImageSharpness,
            construct_args={
                "image_src_type": image_src_type,
                "method": method,
            },
            num_gpus=num_gpus,
            batch_size=1,
        )(col("image")),
    )

    ds.show()

    # ╭────────────────────────────────┬───────────────────────╮
    # │ image                          ┆ image_sharpness       │
    # │ ---                            ┆ ---                   │
    # │ Utf8                           ┆ Float64               │
    # ╞════════════════════════════════╪═══════════════════════╡
    # │ https://las-cn-beijing-public… ┆ 1234.56               │
    # ╰────────────────────────────────┴───────────────────────╯
最近更新时间:2026.02.10 15:51:19
这个页面对您有帮助吗?
有用
有用
无用
无用