rasterregions
rasterregions extracts anonymous, ordered crop regions from raster images. It provides foreground masks, connected components, rows, crops, and diagnostics. It does not perform OCR, assign glyph identities, or interpret document semantics.
Install
python -m pip install rasterregions
Requires Python 3.10 or newer, NumPy 1.24 or newer, and Pillow 10 or newer. For a source checkout, use python -m pip install -e ".[dev]" to install development tools too.
Quick start
from rasterregions import detect_regions
from rasterregions.io import write_detection
result = detect_regions("page.png")
for region in result.regions:
print(region.region_id, region.bbox.as_tuple(), region.confidence)
manifest = write_detection(result, "build/page")
print(result.status, manifest)
Set expected_count when external evidence provides a count. The default count scope partitions one qualifying row; expected_count_scope="page" constrains a count across rows. Pass a BBox as roi to constrain analysis while keeping full-image result coordinates.
For sparse objects separated by spacing evidence, opt into detect_spaced_regions. It supports per-row exact count hints or deterministic count inference, reports ambiguity, and keeps exact foreground ownership in each region mask. This does not change detect_regions defaults; see Spaced-region segmentation.
from rasterregions import detect_spaced_regions
result = detect_spaced_regions("page.png", row_counts=[None, 4])
print(result.status, len(result.regions), result.unassigned_mask.sum())
Capabilities
- deterministic grayscale, dark-relative, color, hybrid, and adaptive foreground masks;
- 8-connected components, row grouping, anonymous ordered regions, and crops;
- optional expected-count partitioning using projection valleys and component-crossing costs;
- opt-in spacing-based row segmentation with per-row count hints, exact pixel ownership, and ambiguity diagnostics;
- nearest-component isolation proposals with explicit reason values;
- JSON, mask, crop, and overlay diagnostics through Python and the CLI.
Confidence values are heuristic scores, not calibrated probabilities. Automatic grouping is intended for separated foreground objects rather than dense prose or general document layout.
Documentation
- Installation and quickstart
- Concepts and input contracts
- Foreground masking
- Region detection
- Spaced-region segmentation
- Components and isolation
- Diagnostics and output files
- Command-line interface
- Python API reference
- Compatibility and schema policy
- Changelog
- Manual release procedure
- Visual examples
Examples
Run the complete deterministic example bundle from the repository root:
python examples/run_all.py
Inputs are regenerated from source. Diagnostics are written under build/examples/. See the examples guide for input/output figures and commands to regenerate or check them.
Metadata
Release files for rasterregions 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rasterregions-0.2.5.tar.gz | 132.9 kB | Without provenance | Details for rasterregions-0.2.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rasterregions-0.2.5-py3-none-any.whl | Python 3 | none | any | Details for rasterregions-0.2.5-py3-none-any.whl |
Total release size: 199.4 kB
Release files / rasterregions-0.2.5.tar.gz
| Download URL | rasterregions-0.2.5.tar.gz |
|---|---|
| Size | 132.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f39ef1e6ba649808e123a2b7f3aa29c966c5969f34f379373587f663a96e4f43
|
|
BLAKE2b-256 checksum How to use checksums |
8e378b01f1399e1d1a8706e646eba02ade4381db9b177951e876f59b070caae3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / rasterregions-0.2.5-py3-none-any.whl
| Download URL | rasterregions-0.2.5-py3-none-any.whl |
|---|---|
| Size | 66.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
131c86091c0243a8a270e3127b6d07a6a59592ab058f9a17ccea2295b7246515
|
|
BLAKE2b-256 checksum How to use checksums |
71a728752b0b159a67c1305de797fbe962cea533ee3276abc4342b1cfba0ac44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for rasterregions 0.2.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.