smorand/img2data

Extract structured data from chart/table images using IBM Granite 4.0 Vision

0

stars

1

commits

Python

primary language

Apr 3, 2026

updated

README

img2data

Extract structured data from chart and table images using IBM Granite 4.0 3B Vision.

What it does

Uses the Granite 4.0 Vision model to convert images of charts and tables into machine readable formats: JSON, CSV, HTML, Python code, or OTSL.

Installation

cd /Users/sebastien/Documents/Projects/img2data

# macOS Apple Silicon (MLX acceleration)
uv sync --extra mlx

# Linux/Windows with NVIDIA GPU (CUDA acceleration)
uv sync --extra cuda

Usage

# Default: extract table as JSON
uv run img2json.py table.png

# Extract chart data as CSV
uv run img2json.py --csv chart.png

# Generate Python code to recreate a chart
uv run img2json.py --code chart.png

# Generate a text summary of a chart
uv run img2json.py --summary chart.png

# Extract table as HTML
uv run img2json.py --html table.png

# Extract table as OTSL markup
uv run img2json.py --otsl table.png

# Specify custom output file
uv run img2json.py --json table.png -o result.json

Output formats

FlagModel TagOutput ExtensionDescription
--json (default)<tables_json>.jsonTable extraction as JSON
--csv<chart2csv>.csvChart data as CSV
--code<chart2code>.pyPython code to recreate chart
--summary<chart2summary>.txtText summary of chart
--html<tables_html>.htmlTable as HTML markup
--otsl<tables_otsl>.otslTable as OTSL markup

Output file naming

By default, the output file is the input filename with the format extension:

  • chart.png + --csv produces chart.csv
  • table.jpg + --json produces table.json

Use -o/--output to override.

Hardware acceleration

The tool auto detects the best available backend:

  1. MLX (macOS Apple Silicon): uses mlx-community/granite-4.0-3b-vision-4bit (quantized, ~3 GB)
  2. CUDA (NVIDIA GPU): uses ibm-granite/granite-4.0-3b-vision via transformers
  3. MPS (macOS fallback): uses transformers with Metal Performance Shaders
  4. CPU (last resort): uses transformers on CPU (slow)

The model is downloaded and cached on first run (~3 GB for MLX, larger for transformers).

Supported image formats

PNG, JPG, JPEG, TIFF, BMP, WEBP

Model

IBM Granite 4.0 3B Vision: a compact vision language model designed for enterprise grade document data extraction, released under Apache 2.0 license.

Contributors

smorand

1 commits

smorand/img2data

Extract structured data from chart/table images using IBM Granite 4.0 Vision

0

stars

1

commits

Python

primary language

Apr 3, 2026

updated

README

img2data

Extract structured data from chart and table images using IBM Granite 4.0 3B Vision.

What it does

Uses the Granite 4.0 Vision model to convert images of charts and tables into machine readable formats: JSON, CSV, HTML, Python code, or OTSL.

Installation

cd /Users/sebastien/Documents/Projects/img2data

# macOS Apple Silicon (MLX acceleration)
uv sync --extra mlx

# Linux/Windows with NVIDIA GPU (CUDA acceleration)
uv sync --extra cuda

Usage

# Default: extract table as JSON
uv run img2json.py table.png

# Extract chart data as CSV
uv run img2json.py --csv chart.png

# Generate Python code to recreate a chart
uv run img2json.py --code chart.png

# Generate a text summary of a chart
uv run img2json.py --summary chart.png

# Extract table as HTML
uv run img2json.py --html table.png

# Extract table as OTSL markup
uv run img2json.py --otsl table.png

# Specify custom output file
uv run img2json.py --json table.png -o result.json

Output formats

FlagModel TagOutput ExtensionDescription
--json (default)<tables_json>.jsonTable extraction as JSON
--csv<chart2csv>.csvChart data as CSV
--code<chart2code>.pyPython code to recreate chart
--summary<chart2summary>.txtText summary of chart
--html<tables_html>.htmlTable as HTML markup
--otsl<tables_otsl>.otslTable as OTSL markup

Output file naming

By default, the output file is the input filename with the format extension:

  • chart.png + --csv produces chart.csv
  • table.jpg + --json produces table.json

Use -o/--output to override.

Hardware acceleration

The tool auto detects the best available backend:

  1. MLX (macOS Apple Silicon): uses mlx-community/granite-4.0-3b-vision-4bit (quantized, ~3 GB)
  2. CUDA (NVIDIA GPU): uses ibm-granite/granite-4.0-3b-vision via transformers
  3. MPS (macOS fallback): uses transformers with Metal Performance Shaders
  4. CPU (last resort): uses transformers on CPU (slow)

The model is downloaded and cached on first run (~3 GB for MLX, larger for transformers).

Supported image formats

PNG, JPG, JPEG, TIFF, BMP, WEBP

Model

IBM Granite 4.0 3B Vision: a compact vision language model designed for enterprise grade document data extraction, released under Apache 2.0 license.

Contributors

smorand

1 commits

Languages

Python

100.0%