extract_structures_from_image
Extract chemical structures from images and return SMILES with confidence scores and bounding boxes. Optionally detects text labels via OCR.
Instructions
Extract chemical structures from an image using DECIMER.
Takes a PNG, JPG, or PDF image and returns SMILES + confidence scores + bounding boxes for every detected chemical structure. Segments the image into individual structure regions automatically. Optionally detects nearby text labels via OCR.
DECIMER models download on first run (~570 MB to ~/.data/DECIMER-V2/). Requires: DECIMER, opencv-python, and optionally pytesseract/easyocr.
The returned SMILES should be passed through resolve_name or modify_molecule to verify and enrich — DECIMER SMILES may not be canonical and can have low confidence for complex structures.
Args: image_path: Path to PNG, JPG, or PDF file. detect_labels: Attempt OCR detection of text labels near structures. Requires pytesseract or easyocr; labels are null without an OCR library. Default True.
Returns: Dict with keys: ok, image_path, structures (list of: smiles, confidence in [0,1], bbox [x0,y0,x1,y1], label or null). Returns {ok: False, error: "..."} if DECIMER is not installed or extraction fails.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_path | Yes | ||
| detect_labels | No |