Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ragaeeb/kokokor/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Preprocesses observations by filtering noise, flipping coordinates for RTL text, and normalizing x-coordinates for proper alignment. This function is the first step in the text line grouping pipeline, ensuring observations are clean and properly oriented before line detection.

Signature

flipAndAlignObservations(
    observations: Observation[],
    imageWidth: number,
    dpiX: number,
    options?: Partial<Pick<MapObservationsToTextLinesOptions, 'isRTL' | 'log'>>
): Observation[]

Parameters

observations
Observation[]
required
Array of text observations to preprocess
imageWidth
number
required
Total width of the document/image in pixels
dpiX
number
required
Horizontal DPI for coordinate normalization
options
object
Optional logging and RTL configuration
isRTL
boolean
Whether to flip coordinates for right-to-left text
log
(message: string, ...args: any[]) => void
Debug logging function

Returns

Observation[] - Preprocessed observations ready for line grouping

What It Does

  1. Noise Filtering: Removes OCR artifacts and invalid observations
  2. RTL Coordinate Flipping: When isRTL is enabled, flips x-coordinates to handle right-to-left text properly
  3. X-Coordinate Normalization: Normalizes horizontal positions using DPI for consistent alignment

Usage Example

import { flipAndAlignObservations } from 'kokokor';

const observations = [
  { text: 'مرحبا', bbox: { x: 100, y: 100, width: 200, height: 20 } },
  { text: 'بالعالم', bbox: { x: 310, y: 100, width: 150, height: 20 } },
];

const preprocessed = flipAndAlignObservations(
  observations,
  2480,  // Image width
  300,   // DPI
  { isRTL: true }
);

// Result: Observations with flipped coordinates for RTL reading order

Build docs developers (and LLMs) love