High-quality figure extraction from dense research-paper PDFs
Project description
figcrop
Extract figures from research-paper PDFs by real figure number.
figcrop uses MinerU's PP-DocLayoutV2 layout model for visual-region detection, then adds its own PDF-text and geometry logic to group panels into whole figures, remove captions, and trim page furniture. It is designed for dense semiconductor papers where simple heuristic tools often miss figures or split panels badly.
Features
- Extract whole
Fig.Noutputs, including multi-panel figures, by the real figure number found in the PDF text layer. - Keep figure-internal labels, process-flow text, axes, table borders, and panels, while excluding the caption line.
- Output modes:
figuredefault: whole figure body, no caption.panel: split figures into(a)/(b)subpanels when panel labels are available.caption: whole figure body plus the matched caption text.
- Run as a persistent local HTTP server so the layout model is loaded once.
- Use OpenVINO by default for fast local inference; torch backends remain available.
- Trim modes:
maskdefault: fast trim using an ignore mask for captions, page furniture, neighbor frame lines, and thin anti-aliased edge bleed.whiteband: extra local whitespace snapping around the detector bbox. This is slower but useful as a conservative safety mode for difficult crops.
- Handles slide/poster-style cells in some PDFs by clipping giant page-level fallback detections to the caption's local cell.
Requirements
- Python 3.10-3.13. Windows is the main tested environment.
uvis recommended; the setup scripts install into the project-local.venv.- First run downloads model weights from Hugging Face.
- OpenVINO GPU is the recommended default. NPU is not currently useful for this RT-DETR layout model.
Setup
Windows:
powershell -ExecutionPolicy Bypass -File setup.ps1 -Device xpu
Linux/macOS:
bash setup.sh
requirements.txt is a manifest for the base packages. Device-specific torch
packages are handled by the setup scripts.
Install
Install the released CLI from PyPI:
pipx install figcrop
This exposes:
figcrop help
figcrop extract paper.pdf out --mode caption
figcrop serve
figcrop-mcp
figcrop is the main human/agent CLI. figcrop-mcp is only needed when an MCP
client should call figcrop as a registered tool instead of running shell
commands.
To install directly from the current GitHub source instead:
pipx install git+https://github.com/tadalab-keio/figcrop.git
Usage
<py> means .venv\Scripts\python.exe on Windows or .venv/bin/python on Unix.
For AI agents, the shortest path is:
<py> figcrop.py extract paper.pdf out auto --mode figure
Then inspect the JPEGs and out/figures.json. Do not treat a successful command
as a successful crop until representative images have been viewed.
Start the local server:
<py> figcrop.py serve auto
Then request crops:
curl -s -X POST http://127.0.0.1:8077/extract \
-H "Content-Type: application/json" \
-d '{"pdf":"paper.pdf","out_dir":"out","figs":[1,2],"mode":"caption"}'
Useful request fields:
figs: real figure numbers to extract, for example[1,2].top: fallback positional extraction, for example2for the first two visual regions per page.mode:"figure"default,"panel"for(a)/(b)subpanels, or"caption"for whole figure plus matched caption text.panels: legacy alias formode: "panel".trim_mode:"mask"default or"whiteband".caption_mode: legacy alias;"include"meansmode: "caption".
One-shot CLI:
figcrop extract paper.pdf out auto
figcrop extract paper.pdf out auto --figs 1,2
figcrop extract paper.pdf out auto --top 3
figcrop extract paper.pdf out_panels auto --mode panel
figcrop extract paper.pdf out_whiteband auto --trim whiteband
figcrop extract paper.pdf out_with_captions auto --mode caption
figcrop help
Output files are JPEG crops plus a figures.json manifest in out_dir.
AI Connectors
- OpenAPI/REST: start
figcrop.py serve autoand use/openapi.json. - MCP: install
requirements-mcp.txtand runfigcrop_mcp.py.
See CONNECTORS.md for Claude/Codex/MCP examples and connector safety notes.
How It Works
- Render each PDF page at 150 dpi for layout detection.
- Run PP-DocLayoutV2 through OpenVINO or torch.
- Keep visual regions labeled
image,chart, ortable. - Read
Fig.N/Table Ncaptions directly from the PDF text layer. - Assign each region to the nearest same-column caption below it.
- Union regions with the same figure number into one whole-figure crop.
- In
panelmode, split whole-figure boxes using(a)/(b)label anchors. - In
captionmode, extend the crop to the matched caption paragraph. - Render the page at 300 dpi and crop with the selected trim mode.
The numbering and whole-figure grouping are local geometry logic, not MinerU's full reading-order pipeline.
Performance
For repeated extraction, use the server. In local tests, server mode avoids reloading the model for each request and is much faster than one-shot CLI runs, especially on one-page PDFs.
For occasional use, the one-shot CLI is still practical: most ordinary papers finish in a few seconds on a local OpenVINO GPU setup, so running the server is a convenience rather than a hard requirement.
The default mask trim mode is optimized for speed and is the recommended mode.
whiteband is kept as a higher-conservatism option when local whitespace around
the detector bbox matters more than speed.
Limitations
- Very dense pages can still confuse region-to-caption assignment. Use
top=as a fallback. mode=panelonly emits figures that have a clean(a),(b), ... sequence. Figures without panel labels are intentionally skipped.- Some PDFs contain slide/poster grids or decorative page furniture that can look like a large table. figcrop has a local-cell fallback for common cases, but this class of PDF may still need review.
- Outputs are intended for local research workflow use. Always inspect crops when building datasets or publications.
License
Apache-2.0. See LICENSE.
Built on MinerU and OpenVINO. See NOTICE for attribution and dependency notes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file figcrop-0.2.1.tar.gz.
File metadata
- Download URL: figcrop-0.2.1.tar.gz
- Upload date:
- Size: 35.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebfa4685a68deaab9b817e09cd5ea1005e7a0687d7dc1cffa1ceba0e7ca486b3
|
|
| MD5 |
6b6a02c46204a3b2e2a71af3e77381c6
|
|
| BLAKE2b-256 |
15a2af01362c0fd3885f6a773d43482077b40ed441107a30839c5448d3390b2c
|
File details
Details for the file figcrop-0.2.1-py3-none-any.whl.
File metadata
- Download URL: figcrop-0.2.1-py3-none-any.whl
- Upload date:
- Size: 34.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7107b891991040551b960499c93671727e7b7d53eb447e63d4ca2e86bd95c7a
|
|
| MD5 |
74af4f7ec0527eb7b16d35c2b67a2910
|
|
| BLAKE2b-256 |
4bd9b84d43ceefba7bb23aae49c8be7402e177597e83a996eeb4590ae114f624
|