Skip to main content

Table Outliner

Overview

Table Outliner is a model designed to detect and extract tables from document images. The model processes each page of a document to identify the boundaries of tables using vertical and horizontal line detection. It groups these lines into rows and columns, matches them to form table structures, and filters out any extraneous lines that don't align with the detected table boundaries.

How It Works

  1. Line Detection: For each page, the model:

    • Converts the image to grayscale.
    • Applies thresholding and inversion to create a binary image.
    • Uses morphological operations to detect vertical and horizontal lines separately.
  2. Extracting Line Coordinates: The detected lines are converted to coordinates, representing the start and end points of each line.

  3. Grouping Lines into Rows and Columns: The lines are grouped into rows and columns using a clustering algorithm ( DBSCAN). Groups with insufficient lines are filtered out.

  4. Matching Rows and Columns: The model matches the groups of rows and columns to form potential table boundaries. It checks for intersections and distance thresholds to validate the matches.

  5. Filtering Extraneous Lines: Horizontal lines that exceed the vertical boundaries are filtered out to refine the table structure.

  6. Constructing Tables: The matched and filtered lines are used to construct tables. The model identifies cell boundaries within the tables and extracts the text contained in each cell.

  7. Sorting and Returning Tables: The extracted tables are saved and sorted based on their position on the page. The results are returned as text for further use

Installation

Prerequisites

Ensure you have the following before starting the installation:

  • Git installed on your machine
  • Python and pip installed
  • FURY authentication token

Installation Steps

  1. Clone the repository

    git clone https://github.com/cognaize/ai-core-table-outliner/tree/prod
  2. Navigate to the project directory

    cd ai-core-table-outliner
  3. Install the required Python packages

    FURY_AUTH=${FURY_AUTH} pip install -r requirements.txt

Usage

Here's a quick start example to use table outliner:

# Create an instance of SpatialTextCreator with the specified PDF path
model = TableTextFormatter(pdf_path='/path_to_your_document.pdf')

# Predict tables into strucutred text
tables_str = model.to_structured_text_table()

# Print the tables
print(tables_str)