Skip to main content

OptoCalib-Lab

OptoCalib v0.5.0 Calibration Demo

What's New in v0.5.0

  • Perceptual Colorimetry (CIEDE2000 / ΔE₀₀): Verified against the Sharma et al. (2005) reference dataset.
  • 16-Bit Linear RAW Pipeline & 3×3 CCM: Ridge-regularized Color Correction Matrix, specular glare masking, and sub-pixel ArUco corner refinement.
  • Sub-1ms Numba JIT Acceleration (~0.57 ms): Fused post-detect warp + white-balance kernel with automatic pure-NumPy fallback.
  • Typed Public API & Uncertainty (PEP 561): Immutable CalibrationResult dataclass, domain exceptions (MarkersNotFound, InvalidRawLevels), 95% bootstrap confidence intervals, and CLI (python -m optocalib.cli).

pip install optocalib-lab

OptoCalib

*ArUco-locked perspective alignment with CIE L\a\b\ / CIEDE2000 colorimetry, 16-bit linear RAW, and optional Numba-fused post-detect acceleration for scientific and industrial computer vision.

optocalib-lab solves two major challenges in smartphone-based optical sensing (microfluidics, LAMP/PCR assays, water quality strips, agriculture leaf colorimetry, and industrial QC):

  1. Perspective & Scale Drift: Automatically locks onto 4 printed ArUco markers (IDs 0–3) and rectifies skewed images.
  2. Ambient Lighting Bias: Normalizes illumination using a built-in white reference patch and quantifies color accuracy via CIE ΔE₇₆ and CIEDE2000 (ΔE₀₀) in proper CIE L\*a\b\ (D65).

Quick Start

import cv2
from optocalib import calibrate_image, measure_roi_lab, generate_calibration_card

# 1. Generate a printable calibration template
generate_calibration_card("my_lab_mat.png")

# 2. Calibrate a skewed/unevenly lit photo (uint8 BGR)
img = cv2.imread("sample_photo.jpg")
result = calibrate_image(img)

print("Locked:", result["aruco_locked"])
print("Backend:", result["backend"])  # "numba" or "numpy"
print("Delta-E76:", result["delta_e_before"], "->", result["delta_e_after"])
print("Delta-E00:", result["delta_e00_before"], "->", result["delta_e00_after"])

# 3. Measure perceptual CIE L*a*b* in any ROI
lab_values = measure_roi_lab(result["image"], box=(145, 145, 199, 295))
print("CIELAB:", lab_values)

16-bit linear RAW path

import numpy as np
from optocalib import calibrate_raw

# Synthetic or demosaiced uint16 BGR/RGB sensor frame
raw16 = np.load("frame_u16.npy")  # shape (H, W, 3), dtype uint16
result = calibrate_raw(raw16, color_order="BGR", black_level=64, white_level=65535)

# Scene-linear calibrated buffer (float32 BGR in [0, 1]) + display preview
linear = result["image_linear"]
preview = result["image"]  # uint8

Optional file ingest (DNG/CR2/NEF/…): pip install optocalib-lab[raw] then pass a path to calibrate_raw("capture.dng").

Numba acceleration (optional)

pip install optocalib-lab[fast]

When Numba is installed, the post-detect stage (ROI white-balance + perspective warp + gain) runs as a fused JIT kernel targeting <1 ms on the default 820×360 canvas. Without Numba, the same API uses a pure NumPy/OpenCV fallback automatically.

from optocalib import detect_homography, benchmark_post_detect_uint8, warmup

M, locked = detect_homography(img, 820, 360)
warmup()
stats = benchmark_post_detect_uint8(img, M, repeats=50)
print(stats["median_ms"], "ms via", stats["backend"])

Latency Benchmark & Reproducibility

Post-detect homography warp + white-balance fusion benchmark (820×360 BGR uint8 frame, 50 timed runs after JIT warm-up on Apple Silicon M-series CPU):

Backend Resolution Warm-up Runs Timed Repeats Median Latency
Numba JIT (numba) 820 × 360 5 50 ~0.57 ms
Pure NumPy Fallback 820 × 360 5 50 ~3.40 ms

Note: Calibration card colors printed on standard office paper vary by printer gamut; for quantitative physical reflectance work, calibrate against measured reference patch L*a*b* values.

Development & Attribution

OptoCalib was architected, specified, and verified by Bedriye Dilmen (b-dlmnnn), combining standard OpenCV/NumPy computer-vision primitives with perceptual CIEDE2000 colorimetry, 16-bit linear sensor processing, Ridge-regularized 3×3 CCM fitting, and bootstrap uncertainty intervals. AI coding assistants were used during implementation and refactoring; all mathematical invariants and 87 unit tests were audited and verified locally.

Metadata

Release files for optocalib-lab 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optocalib-lab 0.5.1
File Size Uploaded Provenance Actions
optocalib_lab-0.5.1.tar.gz 24.5 kB Without provenance Details for optocalib_lab-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optocalib-lab 0.5.1
File Interpreter ABI Platform Actions
optocalib_lab-0.5.1-py3-none-any.whl Python 3 none any Details for optocalib_lab-0.5.1-py3-none-any.whl

Total release size: 43.8 kB

Release files / optocalib_lab-0.5.1.tar.gz

Download URL optocalib_lab-0.5.1.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
43c6c543906fea5145aea9094c108c2aff631b5b132db2149109f78ade7ff089
BLAKE2b-256 checksum
How to use checksums
5fd1ef27d7af0d9d5b6d5916dbbc948a091e65f0353550c5a2644f130658f949
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Release files / optocalib_lab-0.5.1-py3-none-any.whl

Download URL optocalib_lab-0.5.1-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d57e31723dcb6f073c5e9c0957679fafc60b97dfcb132e63eefa30b9025b017
BLAKE2b-256 checksum
How to use checksums
6de7c2b96bb526c518b9cf6bd8d221f905b9204dfdef49187c12d6fd1eeeff4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.6

Security for optocalib-lab 0.5.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page