$npx -y skills add ShZhao27208/Aut_Sci_Write --skill sci-figureExtracts figures and sub-figures from academic PDF papers. Supports Fig/Figure, Scheme, Chart, Supplementary Figure, Extended Data Figure (Nature), and Chinese equivalents (图/方案/示意图/附图/补充图). Sub-figure label recognition supports (a)/(A)/a)/(i)/(1)/a. formats. High-quality PNG out
| 1 | # Sci-Figure — Scientific Figure Extractor |
| 2 | |
| 3 | Precisely extract figures and sub-figures from academic PDF papers. |
| 4 | |
| 5 | > **License note**: sci-figure is licensed under **AGPL-3.0-or-later** because it links [PyMuPDF (fitz)](https://pymupdf.readthedocs.io/), which is AGPL-licensed. |
| 6 | |
| 7 | ## Installation |
| 8 | |
| 9 | Install the package from the skill directory before first use: |
| 10 | |
| 11 | ```bash |
| 12 | cd ${SKILL_DIR} |
| 13 | pip install -e . |
| 14 | ``` |
| 15 | |
| 16 | This registers the `sh-sci-fig` CLI command. Requires Tesseract OCR: |
| 17 | - Windows: `winget install UB-Mannheim.TesseractOCR` |
| 18 | - Linux: `apt install tesseract-ocr` |
| 19 | - macOS: `brew install tesseract` |
| 20 | |
| 21 | ## Preferences (EXTEND.md) |
| 22 | |
| 23 | Use Bash to check EXTEND.md existence (priority order): |
| 24 | |
| 25 | ```bash |
| 26 | # Check project-level first |
| 27 | test -f .baoyu-skills/sci-figure/EXTEND.md && echo "project" |
| 28 | |
| 29 | # Then user-level (cross-platform: $HOME works on macOS/Linux/WSL) |
| 30 | test -f "$HOME/.baoyu-skills/sci-figure/EXTEND.md" && echo "user" |
| 31 | ``` |
| 32 | |
| 33 | **EXTEND.md Supports**: Default DPI | Default output format | Tesseract path |
| 34 | |
| 35 | ## Usage |
| 36 | |
| 37 | ```bash |
| 38 | sh-sci-fig <input.pdf> [options] |
| 39 | ``` |
| 40 | |
| 41 | ## Options |
| 42 | |
| 43 | | Option | Short | Description | Default | |
| 44 | |--------|-------|-------------|---------| |
| 45 | | `<input>` | | PDF file path | Required | |
| 46 | | `--figure` | `-f` | Figure number (1, 2, 3...) | Required (except --list/--all) | |
| 47 | | `--subfigure` | `-s` | Sub-figure label (a, b, c...) | None (returns whole figure) | |
| 48 | | `--output` | `-o` | Output directory | Current directory | |
| 49 | | `--dpi` | `-d` | Output resolution | 600 | |
| 50 | | `--list` | `-l` | List all available figure numbers | false | |
| 51 | | `--all` | | Extract all figures | false | |
| 52 | | `--format` | | Output format (png/jpg) | png | |
| 53 | | `--strategy` | | Extraction strategy: hybrid/native/cv | hybrid | |
| 54 | | `--ocr` | | OCR engine: tesseract/easyocr/none | tesseract | |
| 55 | | `--render-page` | | Render full page with annotations | false | |
| 56 | | `--annotate` | | Draw bounding boxes on rendered page | false | |
| 57 | | `--bbox` | | Manual bbox override (x0,y0,x1,y1 in px) | None | |
| 58 | | `--no-trim` | | Disable whitespace trimming | false | |
| 59 | | `--debug` | | Enable debug logging | false | |
| 60 | | `--quiet` | `-q` | Suppress info messages | false | |
| 61 | |
| 62 | ## Examples |
| 63 | |
| 64 | ```bash |
| 65 | # Extract Figure 2, sub-figure c |
| 66 | sh-sci-fig paper.pdf -f 2 -s c |
| 67 | |
| 68 | # Extract entire Figure 3 |
| 69 | sh-sci-fig paper.pdf -f 3 |
| 70 | |
| 71 | # List all available figures in a PDF |
| 72 | sh-sci-fig paper.pdf --list |
| 73 | |
| 74 | # Extract all figures |
| 75 | sh-sci-fig paper.pdf --all |
| 76 | |
| 77 | # Custom output directory and DPI |
| 78 | sh-sci-fig paper.pdf -f 2 -s c -o ./output/ -d 300 |
| 79 | |
| 80 | # Use EasyOCR for sub-figure label detection |
| 81 | sh-sci-fig paper.pdf --all --ocr easyocr |
| 82 | |
| 83 | # CV-only strategy (skip native extraction) |
| 84 | sh-sci-fig paper.pdf --all --strategy cv |
| 85 | |
| 86 | # Render page with annotated bounding boxes (debugging) |
| 87 | sh-sci-fig paper.pdf -f 1 --render-page --annotate |
| 88 | |
| 89 | # Manual bbox extraction (multimodal correction) |
| 90 | sh-sci-fig paper.pdf -f 1 --bbox 100,200,800,1200 |
| 91 | ``` |
| 92 | |
| 93 | **Output**: |
| 94 | ``` |
| 95 | Extracted: figure_2c.png (1920x1080, 600 DPI) |
| 96 | ``` |
| 97 | |
| 98 | ## Error Handling |
| 99 | |
| 100 | | Scenario | Behavior | |
| 101 | |----------|----------| |
| 102 | | Figure number not found | Error + list all available figure numbers | |
| 103 | | OCR recognition failed | Return entire figure region | |
| 104 | | Sub-figure split failed | Return entire figure region | |
| 105 | | No sub-figure labels found | Return entire figure region | |
| 106 | |
| 107 | ## Tech Stack |
| 108 | |
| 109 | | Library | Role | |
| 110 | |---------|------| |
| 111 | | pdfplumber | Text + coordinate extraction (caption detection) | |
| 112 | | PyMuPDF (fitz) | Native image extraction + high-quality page rendering | |
| 113 | | opencv-python | CV region detection, connected-component analysis, content validation | |
| 114 | | Pillow | Final cropping, format conversion | |
| 115 | | pytesseract | OCR for sub-figure label recognition (default) | |
| 116 | | easyocr | Alternative OCR engine (optional, `pip install sci-figure[ocr]`) | |
| 117 | | numpy | Image array operations | |
| 118 | |
| 119 | ## Extraction Engines (v2) |
| 120 | |
| 121 | | Engine | Priority | Best For | |
| 122 | |--------|----------|----------| |
| 123 | | Native (PyMuPDF) | 1st | Raster images embedded in PDF | |
| 124 | | CV (connected-component) | 2nd | Vector graphics, colored plots | |
| 125 | | Caption-anchored | 3rd | Fallback when above engines fail | |
| 126 | |
| 127 | The `hybrid` strategy (default) tries all three in order and validates results. |
| 128 | |
| 129 | ## Detected Figure Fields |
| 130 | |
| 131 | Each figure returned by `FigureExtractor.detect_al |