Image hash calculation operator: Supports three input formats—URL, Base64, and binary—and outputs both hexadecimal and binary hashes in a unified manner.
ahash, dhash, phash, whash, md5image_url, image_base64, image_binaryimage_src_type parametermd5 and perceptual hash will be standardized to 64-bit binary and 16-digit hexadecimalimagededup.methods; if the dependency is unavailable, an empty string will be returnedahashdhashphashwhashmd5Input column name | Note |
|---|---|
image | An array containing image data, with element types as string or binary ( |
A structured result array, where each element contains the following fields:
hash_hex (str): The hexadecimal hash value of the image. For the md5 method, this value is 16 characters (the first 64 bits of the full digest).hash_bin (str): The binary hash value of the image. For the md5 method, this value is 64 bits.If a parameter does not have a default value, it is required
Parameter name | Type | Default value | Description |
|---|---|---|---|
| str |
| The source type of the input image. Selectable values: |
| str |
| Hash calculation method. Selectable values: |
| int |
| Batch size, used to balance throughput and memory consumption. |
The following code demonstrates how to use daft to invoke the ImageHash operator to compute the perceptual hash value of an image.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.image.image_hash import ImageHash 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" ] } ds = daft.from_pydict(samples) ds = ds.with_column( "image_hash", las_udf( ImageHash, construct_args={ "image_src_type": "image_url", "method": "phash", }, num_gpus=0, batch_size=1, concurrency=1, )(col("image")), ) ds.show() # ╭────────────────────────────────┬────────────────────────────────────────╮ # │ image ┆ image_hash │ # │ --- ┆ --- │ # │ Utf8 ┆ Struct[hash_hex: Utf8, hash_bin: Utf8] │ # ╞════════════════════════════════╪════════════════════════════════════════╡ # │ https://las-cn-beijing-public… ┆ {hash_hex: 8d3986a636e768ad, │ # │ ┆ … │ # ╰────────────────────────────────┴────────────────────────────────────────╯