Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Eventual Inc Daft Data Preprocessing Image Decoding

From Leeroopedia


Knowledge Sources
Domains Data_Engineering, Computer_Vision
Last Updated 2026-02-08 00:00 GMT

Overview

Technique for decoding raw image bytes into structured image representations within a dataframe.

Description

Image decoding converts binary-encoded images (PNG, JPEG, TIFF, WebP, and other common formats) into Daft's native Image data type. This transformation is a critical step in computer vision pipelines, bridging the gap between raw binary data (as downloaded from URLs or read from files) and structured image representations that can be processed further.

Key aspects of image decoding in Daft include:

  • Multi-format support: Handles PNG, JPEG, TIFF, WebP, BMP, GIF, and other image formats transparently.
  • Color mode conversion: Images are automatically converted to a specified color mode (RGB by default), ensuring consistent downstream processing. Supported modes include RGB, RGBA, grayscale (L), and others defined by ImageMode.
  • Null-safe mode inference: When mode=None, the color mode is inferred from the underlying image data rather than forced to a specific mode.
  • Error handling: Two modes are available: "raise" to fail on corrupted or unreadable images, or "null" to return null values and log warnings for problematic images.

Once decoded, Image columns support downstream operations such as resize, crop, convert_image, and embedding via AI models.

Usage

Use this technique when you need to convert downloaded image bytes into a processable Image column. Typical scenarios include:

  • Decoding images downloaded from URLs in an ML data preparation pipeline
  • Converting binary image data read from Parquet or other storage into Image type for visual processing
  • Preparing image data for embedding, classification, or other AI model inference

Theoretical Basis

Image decoding follows an image format decoding with color mode conversion pattern:

  1. Format detection: The image codec is identified from the binary header (magic bytes) of each image, enabling transparent multi-format support without user intervention.
  2. Decompression: The binary data is decompressed according to the detected format (e.g., DEFLATE for PNG, DCT for JPEG).
  3. Color space conversion: The raw pixel data is converted to the target color mode (e.g., CMYK to RGB, palette-indexed to RGBA), ensuring uniformity across all images in the column.
  4. Structured representation: The decoded pixel data, along with metadata (width, height, mode), is stored in Daft's Image type, which supports both fixed-shape and variable-shape images within a single column.
Pseudocode:
1. For each binary value in the column:
   a. Detect image format from binary header
   b. Decompress/decode binary data to raw pixels
   c. Convert pixel data to target color mode (default: RGB)
   d. Store as Image type (pixels + width + height + mode)
   e. On decode error:
      - If on_error="raise": propagate error
      - If on_error="null": store null, log warning
2. Return Image column

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment