decimer-segmentation 1.4.0__tar.gz → 1.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- decimer_segmentation-1.6.0/PKG-INFO +630 -0
- decimer_segmentation-1.6.0/README.md +582 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/decimer_segmentation/__init__.py +10 -1
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/decimer_segmentation/complete_structure.py +12 -16
- decimer_segmentation-1.6.0/decimer_segmentation/decimer_segmentation.py +756 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/__init__.py +20 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/config.py +142 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/detection_target_layer.py +233 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/model.py +1325 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/moldetect.py +38 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/utils.py +828 -0
- decimer_segmentation-1.6.0/decimer_segmentation/mrcnn/visualize.py +223 -0
- decimer_segmentation-1.6.0/decimer_segmentation/optimized_complete_structure.py +528 -0
- decimer_segmentation-1.6.0/decimer_segmentation.egg-info/PKG-INFO +630 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/decimer_segmentation.egg-info/SOURCES.txt +14 -1
- decimer_segmentation-1.6.0/decimer_segmentation.egg-info/requires.txt +15 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/decimer_segmentation.egg-info/top_level.txt +1 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/setup.py +18 -10
- decimer_segmentation-1.6.0/tests/__init__.py +1 -0
- decimer_segmentation-1.6.0/tests/conftest.py +164 -0
- decimer_segmentation-1.6.0/tests/helpers.py +96 -0
- decimer_segmentation-1.6.0/tests/test_decimer_segmentation.py +15 -0
- decimer_segmentation-1.6.0/tests/test_detect_forward_pass.py +245 -0
- decimer_segmentation-1.6.0/tests/test_lazy_model.py +250 -0
- decimer_segmentation-1.6.0/tests/test_mask_expansion.py +64 -0
- decimer_segmentation-1.6.0/tests/test_page_numbers.py +287 -0
- decimer_segmentation-1.6.0/tests/test_pdf_backends.py +672 -0
- decimer_segmentation-1.6.0/tests/test_segmentation.py +664 -0
- decimer_segmentation-1.4.0/PKG-INFO +0 -121
- decimer_segmentation-1.4.0/README.md +0 -99
- decimer_segmentation-1.4.0/decimer_segmentation/decimer_segmentation.py +0 -450
- decimer_segmentation-1.4.0/decimer_segmentation/mrcnn/config.py +0 -251
- decimer_segmentation-1.4.0/decimer_segmentation/mrcnn/model.py +0 -3245
- decimer_segmentation-1.4.0/decimer_segmentation/mrcnn/moldetect.py +0 -397
- decimer_segmentation-1.4.0/decimer_segmentation/mrcnn/utils.py +0 -951
- decimer_segmentation-1.4.0/decimer_segmentation/mrcnn/visualize.py +0 -619
- decimer_segmentation-1.4.0/decimer_segmentation.egg-info/PKG-INFO +0 -121
- decimer_segmentation-1.4.0/decimer_segmentation.egg-info/requires.txt +0 -9
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/LICENSE +0 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/decimer_segmentation.egg-info/dependency_links.txt +0 -0
- {decimer_segmentation-1.4.0 → decimer_segmentation-1.6.0}/setup.cfg +0 -0
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: decimer_segmentation
|
|
3
|
+
Version: 1.6.0
|
|
4
|
+
Summary: DECIMER Segmentation - Extraction of chemical structure depictions from scientific literature
|
|
5
|
+
Home-page: https://github.com/Kohulan/DECIMER-Image-Segmentation
|
|
6
|
+
Author: Kohulan Rajan
|
|
7
|
+
Author-email: kohulan.rajan@uni-jena.de
|
|
8
|
+
Maintainer: Kohulan Rajan
|
|
9
|
+
Maintainer-email: kohulan.rajan@uni-jena.de
|
|
10
|
+
License: MIT
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: tensorflow<=2.15.1,>=2.12.0
|
|
21
|
+
Requires-Dist: numpy>=1.2.0
|
|
22
|
+
Requires-Dist: scikit-image>=0.2.0
|
|
23
|
+
Requires-Dist: pillow
|
|
24
|
+
Requires-Dist: opencv-python
|
|
25
|
+
Requires-Dist: matplotlib
|
|
26
|
+
Requires-Dist: IPython
|
|
27
|
+
Requires-Dist: numba
|
|
28
|
+
Requires-Dist: scipy
|
|
29
|
+
Requires-Dist: requests
|
|
30
|
+
Requires-Dist: pystow
|
|
31
|
+
Requires-Dist: pypdfium2<6,>=4.30.0
|
|
32
|
+
Provides-Extra: pdf
|
|
33
|
+
Requires-Dist: PyMuPDF; extra == "pdf"
|
|
34
|
+
Dynamic: author
|
|
35
|
+
Dynamic: author-email
|
|
36
|
+
Dynamic: classifier
|
|
37
|
+
Dynamic: description
|
|
38
|
+
Dynamic: description-content-type
|
|
39
|
+
Dynamic: home-page
|
|
40
|
+
Dynamic: license
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
Dynamic: maintainer
|
|
43
|
+
Dynamic: maintainer-email
|
|
44
|
+
Dynamic: provides-extra
|
|
45
|
+
Dynamic: requires-dist
|
|
46
|
+
Dynamic: requires-python
|
|
47
|
+
Dynamic: summary
|
|
48
|
+
|
|
49
|
+
<div align="center">
|
|
50
|
+
|
|
51
|
+
# 🔬 DECIMER Image Segmentation 📄
|
|
52
|
+
|
|
53
|
+
### Deep Learning for Chemical Image Recognition - Automated Structure Detection & Extraction
|
|
54
|
+
|
|
55
|
+
<p align="center">
|
|
56
|
+
<img src="https://github.com/Kohulan/DECIMER-Image-Segmentation/blob/master/Validation/Abstract1.png?raw=true" alt="DECIMER Segmentation" width="700">
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
[](https://opensource.org/licenses/MIT)
|
|
60
|
+
[](https://GitHub.com/Kohulan/DECIMER-Image-Segmentation/graphs/commit-activity)
|
|
61
|
+
[](https://GitHub.com/Kohulan/DECIMER-Image-Segmentation/issues/)
|
|
62
|
+
[](https://GitHub.com/Kohulan/DECIMER-Image-Segmentation/graphs/contributors/)
|
|
63
|
+
[](https://www.tensorflow.org)
|
|
64
|
+
[](https://zenodo.org/badge/latestdoi/268631290)
|
|
65
|
+
[](https://zenodo.org/badge/latestdoi/268631290)
|
|
66
|
+
[](https://GitHub.com/Kohulan/DECIMER-Image-Segmentation/releases/)
|
|
67
|
+
[](https://pypi.python.org/pypi/decimer-segmentation/)
|
|
68
|
+
|
|
69
|
+
**🌐 Try it live at [decimer.ai](https://decimer.ai)**
|
|
70
|
+
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 📚 Table of Contents
|
|
76
|
+
|
|
77
|
+
- [📝 Overview](#-overview)
|
|
78
|
+
- [✨ Key Features](#-key-features)
|
|
79
|
+
- [🎯 How It Works](#-how-it-works)
|
|
80
|
+
- [⚙️ Installation](#️-installation)
|
|
81
|
+
- [🚀 Usage](#-usage)
|
|
82
|
+
- [Command Line](#command-line-interface)
|
|
83
|
+
- [Python API](#python-api)
|
|
84
|
+
- [Windows Users](#-notes-for-windows-users)
|
|
85
|
+
- [📊 Model Information](#-model-information)
|
|
86
|
+
- [📄 Citation](#-citation)
|
|
87
|
+
- [🙏 Acknowledgements](#-acknowledgements)
|
|
88
|
+
- [👥 Authors](#-authors)
|
|
89
|
+
- [🌐 Project Website](#-project-website)
|
|
90
|
+
- [🏛️ Research Group](#️-research-group)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## 📝 Overview
|
|
95
|
+
|
|
96
|
+
<div align="center">
|
|
97
|
+
<img src="https://github.com/Kohulan/DECIMER-Image-to-SMILES/raw/master/assets/DECIMER.gif" width="350" align="right">
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
> **Unlocking decades of chemical knowledge from scientific literature!**
|
|
101
|
+
>
|
|
102
|
+
> Chemistry has accumulated vast amounts of knowledge about chemical compounds, structures, and properties across countless scientific publications. DECIMER Segmentation is the first open-source, deep learning-based tool designed to automatically recognize and extract chemical structure depictions from scientific documents.
|
|
103
|
+
|
|
104
|
+
### 🎯 The Challenge
|
|
105
|
+
|
|
106
|
+
Converting images of chemical structures into machine-readable formats (OCSR - Optical Chemical Structure Recognition) is a crucial step in digitizing chemical knowledge. But before we can recognize structures, we need to find and extract them from complex document pages!
|
|
107
|
+
|
|
108
|
+
### 💡 The Solution
|
|
109
|
+
|
|
110
|
+
DECIMER Segmentation uses advanced deep learning to:
|
|
111
|
+
- 🔍 **Detect** chemical structure depictions in scientific publications
|
|
112
|
+
- ✂️ **Extract** individual structure images with precision
|
|
113
|
+
- 📚 **Process** both modern PDFs and scanned historical documents
|
|
114
|
+
- ⚡ **Automate** the entire workflow from document to segmented structures
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## ✨ Key Features
|
|
119
|
+
|
|
120
|
+
<table>
|
|
121
|
+
<tr>
|
|
122
|
+
<td width="33%" align="center">
|
|
123
|
+
<h3>🤖 Deep Learning Powered</h3>
|
|
124
|
+
<p>Built on Mask R-CNN architecture for state-of-the-art detection accuracy</p>
|
|
125
|
+
</td>
|
|
126
|
+
<td width="33%" align="center">
|
|
127
|
+
<h3>📖 Universal Compatibility</h3>
|
|
128
|
+
<p>Works with PDFs, scanned pages, and bitmap images from any publisher</p>
|
|
129
|
+
</td>
|
|
130
|
+
<td width="33%" align="center">
|
|
131
|
+
<h3>🆓 Open Source</h3>
|
|
132
|
+
<p>Freely available code and pre-trained models for the community</p>
|
|
133
|
+
</td>
|
|
134
|
+
</tr>
|
|
135
|
+
<tr>
|
|
136
|
+
<td width="33%" align="center">
|
|
137
|
+
<h3>⚡ High Performance</h3>
|
|
138
|
+
<p>GPU acceleration support for rapid batch processing</p>
|
|
139
|
+
</td>
|
|
140
|
+
<td width="33%" align="center">
|
|
141
|
+
<h3>🎨 Smart Post-Processing</h3>
|
|
142
|
+
<p>Automatic mask expansion to capture complete structures</p>
|
|
143
|
+
</td>
|
|
144
|
+
<td width="33%" align="center">
|
|
145
|
+
<h3>🌐 Web Application</h3>
|
|
146
|
+
<p>User-friendly interface available at decimer.ai</p>
|
|
147
|
+
</td>
|
|
148
|
+
</tr>
|
|
149
|
+
</table>
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 🎯 How It Works
|
|
154
|
+
|
|
155
|
+
DECIMER Segmentation employs a sophisticated two-stage workflow:
|
|
156
|
+
|
|
157
|
+
### 1️⃣ **Detection Stage**
|
|
158
|
+
```
|
|
159
|
+
📄 Input Document → 🤖 Mask R-CNN Model → 🎭 Structure Masks
|
|
160
|
+
```
|
|
161
|
+
The deep learning model analyzes the page and creates precise masks indicating the location of each chemical structure.
|
|
162
|
+
|
|
163
|
+
### 2️⃣ **Post-Processing Stage**
|
|
164
|
+
```
|
|
165
|
+
🎭 Initial Masks → 🔧 Expansion Algorithm → ✅ Complete Structures
|
|
166
|
+
```
|
|
167
|
+
An intelligent post-processing workflow ensures that potentially incomplete masks are expanded to capture the full structure.
|
|
168
|
+
|
|
169
|
+
### 🎨 Visual Workflow
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
┌─────────────────┐
|
|
173
|
+
│ PDF/Image File │
|
|
174
|
+
└────────┬────────┘
|
|
175
|
+
│
|
|
176
|
+
▼
|
|
177
|
+
┌─────────────────┐
|
|
178
|
+
│ Page Extraction│
|
|
179
|
+
└────────┬────────┘
|
|
180
|
+
│
|
|
181
|
+
▼
|
|
182
|
+
┌─────────────────┐
|
|
183
|
+
│ Mask R-CNN │
|
|
184
|
+
│ Detection │
|
|
185
|
+
└────────┬────────┘
|
|
186
|
+
│
|
|
187
|
+
▼
|
|
188
|
+
┌─────────────────┐
|
|
189
|
+
│ Mask Expansion │
|
|
190
|
+
└────────┬────────┘
|
|
191
|
+
│
|
|
192
|
+
▼
|
|
193
|
+
┌─────────────────┐
|
|
194
|
+
│ Segmented │
|
|
195
|
+
│ Structures │
|
|
196
|
+
└─────────────────┘
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## ⚙️ Installation
|
|
202
|
+
|
|
203
|
+
### 🐍 Prerequisites
|
|
204
|
+
|
|
205
|
+
We strongly recommend using a Conda environment for seamless dependency management.
|
|
206
|
+
|
|
207
|
+
#### Install Miniconda (if not already installed)
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
# Linux
|
|
211
|
+
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
|
|
212
|
+
bash Miniconda3-latest-Linux-x86_64.sh
|
|
213
|
+
|
|
214
|
+
# macOS
|
|
215
|
+
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
|
|
216
|
+
bash Miniconda3-latest-MacOSX-x86_64.sh
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### 📦 Installation Options
|
|
220
|
+
|
|
221
|
+
<details>
|
|
222
|
+
<summary><b>Option 1: Install from GitHub (Development Version)</b></summary>
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# Clone the repository
|
|
226
|
+
git clone https://github.com/Kohulan/DECIMER-Image-Segmentation.git
|
|
227
|
+
cd DECIMER-Image-Segmentation
|
|
228
|
+
|
|
229
|
+
# Create and activate conda environment
|
|
230
|
+
conda create --name DECIMER_IMGSEG python=3.10
|
|
231
|
+
conda activate DECIMER_IMGSEG
|
|
232
|
+
|
|
233
|
+
# Install dependencies
|
|
234
|
+
conda install pip
|
|
235
|
+
python -m pip install -U pip
|
|
236
|
+
|
|
237
|
+
# Install DECIMER-Segmentation
|
|
238
|
+
pip install .
|
|
239
|
+
|
|
240
|
+
# Optional: PyMuPDF as an alternative PDF reader (licensed under the AGPL-3.0)
|
|
241
|
+
pip install ".[pdf]"
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
</details>
|
|
245
|
+
|
|
246
|
+
<details>
|
|
247
|
+
<summary><b>Option 2: Install from PyPI (Stable Release)</b></summary>
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Create and activate conda environment
|
|
251
|
+
conda create --name DECIMER_IMGSEG python=3.10
|
|
252
|
+
conda activate DECIMER_IMGSEG
|
|
253
|
+
|
|
254
|
+
# Install from PyPI
|
|
255
|
+
pip install decimer-segmentation
|
|
256
|
+
|
|
257
|
+
# Optional: PyMuPDF as an alternative PDF reader (licensed under the AGPL-3.0)
|
|
258
|
+
pip install "decimer-segmentation[pdf]"
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
#### 📄 Reading PDFs
|
|
264
|
+
|
|
265
|
+
PDF pages are rendered at 300 DPI with [pypdfium2](https://github.com/pypdfium2-team/pypdfium2) (Apache-2.0 /
|
|
266
|
+
BSD-3-Clause), which is installed with `decimer-segmentation`, so a plain `pip install decimer-segmentation` reads PDFs.
|
|
267
|
+
No extra program is needed (Poppler is no longer used, and the `poppler_path` argument is ignored).
|
|
268
|
+
|
|
269
|
+
[PyMuPDF](https://pymupdf.readthedocs.io/) can be used instead. It is licensed under the AGPL-3.0 while this package is
|
|
270
|
+
MIT-licensed, so it is an optional extra that is never imported unless you ask for it:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
pip install "decimer-segmentation[pdf]"
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
segments = segment_chemical_structures_from_file("document.pdf", pdf_backend="pymupdf") # default: "pdfium"
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
On the command line: `python3 segment_structures_in_document.py document.pdf --pdf-backend pymupdf` (`--pdf_backend` works too). Without PyMuPDF
|
|
281
|
+
installed, `pdf_backend="pymupdf"` raises an `ImportError` that tells you how to install it. Images (PNG, JPEG, ...) and
|
|
282
|
+
numpy arrays need neither reader.
|
|
283
|
+
|
|
284
|
+
**Changed in 1.6.0:**
|
|
285
|
+
|
|
286
|
+
- PDFs are read with pypdfium2 instead of PyMuPDF, which is no longer installed with the package. The two readers draw the
|
|
287
|
+
same pages with slightly different anti-aliasing, so a few bounding boxes can differ by some pixels, or include a dashed
|
|
288
|
+
frame that the other reader leaves out; `pdf_backend="pymupdf"` renders the pages as 1.5.x did. Pages are rendered one
|
|
289
|
+
after the other, because neither reader is thread-safe.
|
|
290
|
+
- The model is downloaded and loaded on first use instead of at import, so `set_inference_config()` and the command-line
|
|
291
|
+
`--fast` flag now take effect (before, the model was already loaded when they ran). With `--fast`,
|
|
292
|
+
`DETECTION_MIN_CONFIDENCE` is 0.7 instead of 0.75; the default mode is unchanged.
|
|
293
|
+
|
|
294
|
+
#### 📥 The model is downloaded on first use
|
|
295
|
+
|
|
296
|
+
Importing `decimer_segmentation` does not download or load anything. The first segmentation (or an explicit call to
|
|
297
|
+
`decimer_segmentation.get_model()`) downloads the Mask R-CNN weights (about 270 MB) if they are missing, loads the
|
|
298
|
+
model and keeps it for later calls. The weights live in `$PYSTOW_HOME/DECIMER-Segmentation_model/`
|
|
299
|
+
(`~/.data/DECIMER-Segmentation_model/` by default); weights that are already there are used without network access.
|
|
300
|
+
|
|
301
|
+
### 🖥️ Hardware Requirements
|
|
302
|
+
|
|
303
|
+
- **CPU Mode**: Works on any modern CPU
|
|
304
|
+
- **GPU Mode** *(Recommended)*: CUDA-compatible GPU with appropriate drivers
|
|
305
|
+
- Significantly faster processing
|
|
306
|
+
- Essential for batch processing
|
|
307
|
+
|
|
308
|
+
---
|
|
309
|
+
|
|
310
|
+
## 🚀 Usage
|
|
311
|
+
|
|
312
|
+
### Command Line Interface
|
|
313
|
+
|
|
314
|
+
Process entire documents with a single command:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# Segment structures from a PDF or image file
|
|
318
|
+
python3 segment_structures_in_document.py your_document.pdf
|
|
319
|
+
|
|
320
|
+
# Output will be saved in a folder named after your input file
|
|
321
|
+
# e.g., your_document/ containing all segmented structures
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### Python API
|
|
325
|
+
|
|
326
|
+
#### 🎨 **Example 1: Segment from Image Array**
|
|
327
|
+
|
|
328
|
+
```python
|
|
329
|
+
from decimer_segmentation import segment_chemical_structures
|
|
330
|
+
import cv2
|
|
331
|
+
|
|
332
|
+
# Load your scanned page
|
|
333
|
+
page_image = cv2.imread("path/to/scanned_page.png")
|
|
334
|
+
|
|
335
|
+
# Extract all chemical structures
|
|
336
|
+
segments = segment_chemical_structures(page_image, expand=True)
|
|
337
|
+
|
|
338
|
+
# segments is a list of numpy arrays, each containing a structure
|
|
339
|
+
for idx, structure in enumerate(segments):
|
|
340
|
+
cv2.imwrite(f"structure_{idx}.png", structure)
|
|
341
|
+
print(f"✅ Saved structure {idx}")
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
#### 📄 **Example 2: Segment from File (PDF or Image)**
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
from decimer_segmentation import segment_chemical_structures_from_file
|
|
348
|
+
|
|
349
|
+
# Process a PDF file
|
|
350
|
+
segments = segment_chemical_structures_from_file(
|
|
351
|
+
"path/to/document.pdf",
|
|
352
|
+
expand=True
|
|
353
|
+
)
|
|
354
|
+
|
|
355
|
+
# Process an image file
|
|
356
|
+
segments = segment_chemical_structures_from_file(
|
|
357
|
+
"path/to/page_image.jpg",
|
|
358
|
+
expand=True
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
print(f"🎉 Extracted {len(segments)} chemical structures!")
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
To find out where each structure was found, ask for the bounding boxes and the page numbers:
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
segments, bboxes, page_numbers = segment_chemical_structures_from_file(
|
|
368
|
+
"path/to/document.pdf",
|
|
369
|
+
expand=True,
|
|
370
|
+
return_bboxes=True, # (y0, x0, y1, x1) in pixels of the page image
|
|
371
|
+
return_page_numbers=True, # the page of the PDF, counted from 1
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
for segment, bbox, page_number in zip(segments, bboxes, page_numbers):
|
|
375
|
+
print(f"Page {page_number}: structure at {bbox}")
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
There is one bounding box and one page number per segment, in the order of the segments. The pages of a PDF are
|
|
379
|
+
rendered at 300 DPI, and the bounding boxes are in pixels of these page images. Every segment of an image file is on
|
|
380
|
+
page 1. Which values are returned depends on the two options:
|
|
381
|
+
|
|
382
|
+
| `return_bboxes` | `return_page_numbers` | Returns |
|
|
383
|
+
|---|---|---|
|
|
384
|
+
| `False` (default) | `False` (default) | `segments` |
|
|
385
|
+
| `True` | `False` | `(segments, bboxes)` |
|
|
386
|
+
| `False` | `True` | `(segments, page_numbers)` |
|
|
387
|
+
| `True` | `True` | `(segments, bboxes, page_numbers)` |
|
|
388
|
+
|
|
389
|
+
#### 🔧 **Example 3: Batch Processing**
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from decimer_segmentation import segment_chemical_structures_from_file
|
|
393
|
+
import os
|
|
394
|
+
from pathlib import Path
|
|
395
|
+
|
|
396
|
+
def batch_segment(input_dir, output_dir):
|
|
397
|
+
"""Process multiple PDF files"""
|
|
398
|
+
Path(output_dir).mkdir(parents=True, exist_ok=True)
|
|
399
|
+
|
|
400
|
+
for pdf_file in Path(input_dir).glob("*.pdf"):
|
|
401
|
+
print(f"📄 Processing {pdf_file.name}...")
|
|
402
|
+
|
|
403
|
+
segments = segment_chemical_structures_from_file(
|
|
404
|
+
str(pdf_file),
|
|
405
|
+
expand=True
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
# Save each segment
|
|
409
|
+
file_output_dir = Path(output_dir) / pdf_file.stem
|
|
410
|
+
file_output_dir.mkdir(exist_ok=True)
|
|
411
|
+
|
|
412
|
+
for idx, segment in enumerate(segments):
|
|
413
|
+
output_path = file_output_dir / f"structure_{idx:03d}.png"
|
|
414
|
+
cv2.imwrite(str(output_path), segment)
|
|
415
|
+
|
|
416
|
+
print(f"✅ Extracted {len(segments)} structures from {pdf_file.name}")
|
|
417
|
+
|
|
418
|
+
# Use it
|
|
419
|
+
batch_segment("input_pdfs/", "output_structures/")
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
#### 🎯 **Example 4: Advanced Usage with Custom Parameters**
|
|
423
|
+
|
|
424
|
+
```python
|
|
425
|
+
from decimer_segmentation import segment_chemical_structures
|
|
426
|
+
import cv2
|
|
427
|
+
|
|
428
|
+
# Load image
|
|
429
|
+
image = cv2.imread("complex_page.png")
|
|
430
|
+
|
|
431
|
+
# Segment with custom settings
|
|
432
|
+
segments = segment_chemical_structures(
|
|
433
|
+
image,
|
|
434
|
+
expand=True, # Enable mask expansion
|
|
435
|
+
visualization=True # Generate visualization (if available)
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
# Process results
|
|
439
|
+
for idx, segment in enumerate(segments):
|
|
440
|
+
# You can now pass this to DECIMER Image Transformer
|
|
441
|
+
# for structure recognition
|
|
442
|
+
print(f"Structure {idx}: {segment.shape}")
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### 📓 Interactive Tutorial
|
|
446
|
+
|
|
447
|
+
For more comprehensive examples and interactive demonstrations, check out our **[Jupyter Notebook](https://github.com/Kohulan/DECIMER-Image-Segmentation/blob/master/DECIMER_Segmentation_notebook.ipynb)**!
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
### 🪟 Notes for Windows Users
|
|
452
|
+
|
|
453
|
+
<details>
|
|
454
|
+
<summary><b>Windows-Specific Instructions</b></summary>
|
|
455
|
+
|
|
456
|
+
#### 1️⃣ Use Anaconda PowerShell Prompt
|
|
457
|
+
Run all commands in the **Anaconda PowerShell Prompt** (not regular Command Prompt or PowerShell).
|
|
458
|
+
|
|
459
|
+
#### 2️⃣ PDF Support
|
|
460
|
+
|
|
461
|
+
PDF files are read with pypdfium2, which is installed with the package and needs no extra program on Windows
|
|
462
|
+
(Poppler is no longer used, and the `poppler_path` argument is ignored).
|
|
463
|
+
|
|
464
|
+
#### 3️⃣ GPU Support on Windows
|
|
465
|
+
Ensure you have:
|
|
466
|
+
- CUDA Toolkit installed
|
|
467
|
+
- cuDNN libraries configured
|
|
468
|
+
- Compatible GPU drivers
|
|
469
|
+
|
|
470
|
+
</details>
|
|
471
|
+
|
|
472
|
+
---
|
|
473
|
+
|
|
474
|
+
## 📊 Model Information
|
|
475
|
+
|
|
476
|
+
### 🤖 Pre-trained Model
|
|
477
|
+
|
|
478
|
+
The Mask R-CNN model is publicly available and ready to use:
|
|
479
|
+
|
|
480
|
+
**[](https://doi.org/10.5281/zenodo.10142866)**
|
|
481
|
+
|
|
482
|
+
### 🎓 Model Architecture
|
|
483
|
+
|
|
484
|
+
- **Base Network**: Mask R-CNN
|
|
485
|
+
- **Training Data**: Diverse chemical literature from multiple publishers
|
|
486
|
+
- **Task**: Instance segmentation of chemical structure depictions
|
|
487
|
+
- **Performance**: Manually validated on publications from various sources
|
|
488
|
+
|
|
489
|
+
### 🔍 Model Performance
|
|
490
|
+
|
|
491
|
+
The model has been rigorously evaluated on:
|
|
492
|
+
- ✅ Publications from multiple scientific publishers
|
|
493
|
+
- ✅ Documents spanning different time periods
|
|
494
|
+
- ✅ Both modern PDFs and scanned historical pages
|
|
495
|
+
- ✅ Various image qualities and layouts
|
|
496
|
+
|
|
497
|
+
---
|
|
498
|
+
|
|
499
|
+
## 📄 Citation
|
|
500
|
+
|
|
501
|
+
If DECIMER Segmentation contributes to your research, please cite:
|
|
502
|
+
|
|
503
|
+
```bibtex
|
|
504
|
+
@article{Rajan2021,
|
|
505
|
+
author = {Rajan, Kohulan and Brinkhaus, Henning Otto and Sorokina, Maria and Zielesny, Achim and Steinbeck, Christoph},
|
|
506
|
+
title = {DECIMER-Segmentation: Automated extraction of chemical structure depictions from scientific literature},
|
|
507
|
+
journal = {Journal of Cheminformatics},
|
|
508
|
+
year = {2021},
|
|
509
|
+
volume = {13},
|
|
510
|
+
number = {20},
|
|
511
|
+
doi = {10.1186/s13321-021-00496-1}
|
|
512
|
+
}
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
**Full Citation:**
|
|
516
|
+
Rajan, K., Brinkhaus, H.O., Sorokina, M. et al. *DECIMER-Segmentation: Automated extraction of chemical structure depictions from scientific literature.* J Cheminform **13**, 20 (2021). https://doi.org/10.1186/s13321-021-00496-1
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## 🙏 Acknowledgements
|
|
521
|
+
|
|
522
|
+
<div align="center">
|
|
523
|
+
|
|
524
|
+
### 🌟 Special Thanks
|
|
525
|
+
|
|
526
|
+
This project wouldn't be possible without the support and contributions from the community and funding organizations.
|
|
527
|
+
|
|
528
|
+
<table>
|
|
529
|
+
<tr>
|
|
530
|
+
<td align="center">
|
|
531
|
+
<strong>Contributors</strong><br>
|
|
532
|
+
All our amazing contributors who helped improve the codebase
|
|
533
|
+
</td>
|
|
534
|
+
<td align="center">
|
|
535
|
+
<strong>Community</strong><br>
|
|
536
|
+
Users providing feedback and reporting issues
|
|
537
|
+
</td>
|
|
538
|
+
<td align="center">
|
|
539
|
+
<strong>Open Source</strong><br>
|
|
540
|
+
Projects we build upon: TensorFlow, Mask R-CNN
|
|
541
|
+
</td>
|
|
542
|
+
</tr>
|
|
543
|
+
</table>
|
|
544
|
+
|
|
545
|
+
</div>
|
|
546
|
+
|
|
547
|
+
## 🌐 Project Website
|
|
548
|
+
|
|
549
|
+
<div align="center">
|
|
550
|
+
|
|
551
|
+
### Experience DECIMER Live!
|
|
552
|
+
|
|
553
|
+
<a href="https://decimer.ai">
|
|
554
|
+
<img src="https://github.com/Kohulan/DECIMER-Image_Transformer/blob/master/DECIMER_V2.png?raw=true" width="600" alt="DECIMER.ai">
|
|
555
|
+
</a>
|
|
556
|
+
|
|
557
|
+
**[🚀 Try DECIMER.ai](https://decimer.ai)** - Web application.
|
|
558
|
+
|
|
559
|
+
### 📦 Complete DECIMER Suite
|
|
560
|
+
|
|
561
|
+
DECIMER Segmentation is part of a comprehensive chemical structure recognition pipeline:
|
|
562
|
+
|
|
563
|
+
1. **🔍 [DECIMER Segmentation](https://github.com/Kohulan/DECIMER-Image-Segmentation)** *(You are here)*
|
|
564
|
+
Extract chemical structures from documents
|
|
565
|
+
|
|
566
|
+
2. **🧠 [DECIMER Image Transformer](https://github.com/Kohulan/DECIMER-Image_Transformer)**
|
|
567
|
+
Convert structure images to SMILES strings
|
|
568
|
+
|
|
569
|
+
3. **🗄️ [MARCUS](https://marcus.decimer.ai/)**
|
|
570
|
+
Molecular Annotation and Recognition for Curating Unravelled Structures
|
|
571
|
+
|
|
572
|
+
</div>
|
|
573
|
+
|
|
574
|
+
---
|
|
575
|
+
|
|
576
|
+
## 🏛️ Research Group
|
|
577
|
+
|
|
578
|
+
<div align="center">
|
|
579
|
+
|
|
580
|
+
### 🎓 Maintained by the [Kohulan](https://www.kohulanr.com/#) @ Steinbeck Group
|
|
581
|
+
|
|
582
|
+
<a href="https://cheminf.uni-jena.de">
|
|
583
|
+
<img src="https://github.com/Kohulan/DECIMER-Image-to-SMILES/blob/master/assets/CheminfGit.png" width="400" alt="Cheminformatics Group"/>
|
|
584
|
+
</a>
|
|
585
|
+
|
|
586
|
+
**[Natural Products Cheminformatics Research Group](https://cheminf.uni-jena.de)**
|
|
587
|
+
Institute for Inorganic and Analytical Chemistry
|
|
588
|
+
Friedrich Schiller University Jena, Germany
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
## ⭐ Star History
|
|
593
|
+
|
|
594
|
+
<div align="center">
|
|
595
|
+
|
|
596
|
+
[](https://star-history.com/#Kohulan/DECIMER-Image-Segmentation&Date)
|
|
597
|
+
|
|
598
|
+
</div>
|
|
599
|
+
|
|
600
|
+
---
|
|
601
|
+
|
|
602
|
+
## 📊 Project Analytics
|
|
603
|
+
|
|
604
|
+
<div align="center">
|
|
605
|
+
|
|
606
|
+

|
|
607
|
+
|
|
608
|
+
</div>
|
|
609
|
+
|
|
610
|
+
---
|
|
611
|
+
|
|
612
|
+
<div align="center">
|
|
613
|
+
|
|
614
|
+
### 🤝 Contributing
|
|
615
|
+
|
|
616
|
+
We welcome contributions! Please feel free to submit a Pull Request.
|
|
617
|
+
|
|
618
|
+
**[📝 Report Bug](https://github.com/Kohulan/DECIMER-Image-Segmentation/issues)** · **[💡 Request Feature](https://github.com/Kohulan/DECIMER-Image-Segmentation/issues)** · **[⭐ Star this repo](https://github.com/Kohulan/DECIMER-Image-Segmentation)**
|
|
619
|
+
|
|
620
|
+
---
|
|
621
|
+
|
|
622
|
+
**Made with ❤️ and ☕ for the global chemistry community**
|
|
623
|
+
|
|
624
|
+
**© 2025 Kohulan @ Steinbeck Lab, Friedrich Schiller University Jena**
|
|
625
|
+
|
|
626
|
+
---
|
|
627
|
+
|
|
628
|
+
<sub>🔬 Advancing Open Science in Chemistry | 🌍 Digitizing Chemical Knowledge | 🤖 Powered by Deep Learning</sub>
|
|
629
|
+
|
|
630
|
+
</div>
|