Skip to main content

WoundScan for Python

Calibrated binary-mask measurements and local ONNX segmentation for research pipelines.

Install with pip install woundscan. Requires Python 3.10 or later.

Source | Issues | OSF | Zenodo

Measure any binary mask

import json
import numpy as np
from woundscan import measure_mask, reference_scale

mask = np.zeros((100, 100), dtype=bool)
mask[20:40, 30:60] = True
scale = reference_scale(reference_pixels=100, reference_mm=10)
result = measure_mask(mask, scale, height_cm=170, weight_kg=70)
print(result.area_mm2)       # 6.0
print(result.perimeter_mm)  # 10.0
print(json.dumps(result.to_dict(), indent=2))

The API accepts masks from any segmentation model or manual annotation pipeline. Measurements use millimetres and square millimetres. Mosteller body surface area uses height in centimetres and weight in kilograms. Supply both to calculate tbsa_percent, otherwise it is None. A reference must lie in the wound plane. Curved surfaces, perspective and calibration uncertainty affect accuracy.

Optional segmentation

Install with pip install "woundscan[inference]".

import cv2
from woundscan import Segmenter, measure_mask

model = Segmenter("/path/to/wound_seg.onnx")
bgr = cv2.imread("/path/to/image.png")
if bgr is None:
    raise ValueError("Image could not be loaded")
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
probability = model.predict(rgb)
mask = model.segment(rgb, threshold=0.5)
result = measure_mask(mask, mm_per_pixel=0.1)

Supply a model you have permission to use. No weights or network downloads are included. Inference uses ONNX Runtime CPU, with float32 RGB input [1,3,256,256] in [0,1] and probability output [1,1,256,256]. The recipe follows the repository Python evaluation script, averaging original, horizontal and vertical flips. Set tta=False for a single pass. Invalid probabilities and logits are rejected.

API

Function Result
reference_scale(reference_pixels, reference_mm) Millimetres per pixel
body_surface_area(height_cm, weight_kg) Mosteller BSA in square metres
measure_mask(mask, mm_per_pixel, height_cm=None, weight_kg=None) Immutable Measurement; height and weight are keyword-only
Measurement.to_dict() JSON-compatible dictionary
Segmenter(model_path).predict(rgb, tta=True) Original-resolution probability array; tta is keyword-only
Segmenter(model_path).segment(rgb, threshold=0.5, tta=True) Boolean mask; threshold and tta are keyword-only

Functions compose with notebooks, batch processing and APIs. Import starts no server, downloads no models and performs no inference. Model loading occurs only when a Segmenter is constructed.

Scope and evidence

Version 0.1 provides measurement and optional inference. Browser reconstructive planning, tissue analysis, donor mapping and interactive editing remain in the GitHub application and are not exported by this Python API.

Area counts foreground pixel cells across all components. Perimeter counts exposed pixel edges, including holes. This lattice perimeter is orientation dependent and differs from the browser's smoothed subpixel contour algorithm. Inference does not apply browser smoothing, component removal or hole filling. Final masks can therefore differ from browser masks.

The repository model evaluation reported Dice 0.827 on 200 validation images and 0.793 on 160 external images. These describe that evaluation, not a guarantee for this package or new photographs. Small punctures and thin abrasions were important failure modes. The software is a research prototype without clinical validation and must not replace clinical judgement.

Licensing and model rights

The Python package, tests and package documentation use MIT. Wheels and source archives exclude model weights, photographs, datasets and browser libraries. Repository weights were trained on restricted noncommercial datasets and data without a documented redistribution license. Obtain appropriate permissions or train with suitably licensed data. MIT does not relicense these assets. PyPI hosting does not certify scientific accuracy or clinical suitability.

Development

Clone the repository and create a virtual environment, then run:

pip install -e ".[test,inference]" build twine
pytest
python -m build
python -m twine check dist/*

Tests cover known geometry, units, input validation and inference transforms. Default measurement tests require no model weights. Bug reports should include package versions and a minimal example without identifying patient information.

Authors: Muhammad Allam Rafi and Cindy Rizky Afrilia.

Metadata

Release files for woundscan 0.1.0

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

Source distribution (sdist)

Source distribution for woundscan 0.1.0
File Size Uploaded Provenance Actions
woundscan-0.1.0.tar.gz 15.3 kB Without provenance Details for woundscan-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for woundscan 0.1.0
File Interpreter ABI Platform Actions
woundscan-0.1.0-py3-none-any.whl Python 3 none any Details for woundscan-0.1.0-py3-none-any.whl

Total release size: 23.0 kB

Release files / woundscan-0.1.0.tar.gz

Download URL woundscan-0.1.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4c0ccc7a24cec66b52180b4368ef638b8380aed09919db3fd82c01af11e5de06
BLAKE2b-256 checksum
How to use checksums
be8bd1b628d02663b13b06518bde00a82ff3a929bd6481d019e3f5e72a3c26e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / woundscan-0.1.0-py3-none-any.whl

Download URL woundscan-0.1.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43be419a03926c94afa30b9c9fe55f520b716ea4c42546e2aec3a0ef9924f3e2
BLAKE2b-256 checksum
How to use checksums
7cad32b0eb696944a7942fa00cd732dc0b146f289553aa9e32b892c2311fc45c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for woundscan 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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