Medical Image Mask Compression and Processing Library
Project description
MedMask - Medical Image Mask Processing Library
A specialized library for efficient compression, storage, and processing of medical image segmentation masks. Designed to dramatically improve medical image analysis workflow through advanced compression and semantic design.
🚀 Key Benefits
- Ultimate Compression: 50+ compression ratio using Zstandard
- File Management: 117 files → 1 archive file
- Performance: 16x faster read operations
- Semantic Mapping: Built-in name-to-label conversion
- Overlapping Masks: Multi-granularity organ combinations
- Lazy Loading: Memory-efficient on-demand construction
📦 Installation
pip install medmask
Dependencies: Python 3.8+, numpy, spacetransformer, zstandard
⚡ Usage
Basic Operations
import numpy as np
from medmask import SegmentationMask, MaskArchive, save_mask, load_mask
from spacetransformer import Space
# Create spatial information
space = Space(shape=(64, 192, 192), spacing=(2.5, 1.0, 1.0))
# -----------------------------
# Create mask – two approaches
# -----------------------------
# 1. Complete initialization
liver_data = np.zeros((64, 192, 192), dtype=np.uint8) # (Z,Y,X)
liver_data[20:40, 50:150, 60:140] = 1
mask = SegmentationMask(liver_data, {"liver": 1}, space=space)
# 2. Lazy loading (multiple organs)
combined_mask = SegmentationMask.lazy_init(bit_depth=8, space=space)
combined_mask.add_label(liver_data > 0, label=1, name="liver")
combined_mask.add_label(spleen_data > 0, label=2, name="spleen")
# Query masks
liver_region = mask.get_binary_mask_by_names("liver")
multiple_organs = combined_mask.get_binary_mask_by_names(["liver", "spleen"])
File Operations
# Single mask files (.msk)
medmask.save_mask(mask, "liver.msk")
loaded_mask = medmask.load_mask("liver.msk")
# Equivalent
mask.save('liver.msk')
loaded_mask = SegmentationMask.load('liver.msk')
# Multi-mask archives (.mska) - for collections
archive = MaskArchive("organs.mska", mode="w", space=space)
archive.add_segmask(liver_mask, "liver")
archive.add_segmask(heart_mask, "heart")
# Read from archive
archive = MaskArchive("organs.mska", mode="r")
liver = archive.load_segmask("liver")
all_names = archive.all_names()
Use Cases
Single Masks: Individual organ processing, simple storage
Combined Masks: Multiple organs in one mask, unified label management
Archives: Collections of related masks, overlapping hierarchies (e.g., individual ribs + combined rib groups)
📊 Performance Comparison
| Metric | Traditional | MedMask | Improvement |
|---|---|---|---|
| File Count | 117 .nii.gz files | 1 .mska file | 117:1 |
| Storage Size | 5.12 MB | 92 KB | 56.7:1 |
| Read Time | 1.869s | 0.117s | 16.0x |
| File Management | Complex | Simple | ✓ |
Test results based on TotalSegmentator 117-organ segmentation data
📁 Project Structure
medmask/
├── core/
│ ├── segmask.py # SegmentationMask class
│ └── mapping.py # LabelMapping class
├── storage/
│ ├── archivefile.py # MaskArchive class
│ └── maskfile.py # MaskFile class
├── compression/
│ └── zstd_codec.py # Compression implementation
└── utils/
└── utils.py # Utility functions
🧪 Testing
python -m pytest tests/
📝 License
MIT License - see LICENSE file for details.
🤝 Contributing
Issues and Pull Requests are welcome! Please follow the standard GitHub workflow.
MedMask - Making medical image segmentation mask processing simpler and more efficient!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file medmask-0.1.3.tar.gz.
File metadata
- Download URL: medmask-0.1.3.tar.gz
- Upload date:
- Size: 329.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b99c1f6b70ec0c19a290a2f7cf76d95d9612aee9725d174c6032476822c7af4a
|
|
| MD5 |
314a53ed823620ea7ca26f119ad421c5
|
|
| BLAKE2b-256 |
252ebae4812e447721a2e8891462ae7e96c2b0793dd9360f96efbc155fe74e1e
|
Provenance
The following attestation bundles were made for medmask-0.1.3.tar.gz:
Publisher:
ci.yml on fastdiag-toolbox/medmask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medmask-0.1.3.tar.gz -
Subject digest:
b99c1f6b70ec0c19a290a2f7cf76d95d9612aee9725d174c6032476822c7af4a - Sigstore transparency entry: 305269713
- Sigstore integration time:
-
Permalink:
fastdiag-toolbox/medmask@2fdbeba342746bac706e4eed9cd9934a07fdcbfb -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/fastdiag-toolbox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2fdbeba342746bac706e4eed9cd9934a07fdcbfb -
Trigger Event:
push
-
Statement type:
File details
Details for the file medmask-0.1.3-py3-none-any.whl.
File metadata
- Download URL: medmask-0.1.3-py3-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7492fea07ce269e9e238bb4ea5f2fc86ed488112443caa507873e4d7daf1fec
|
|
| MD5 |
bcbf2f7debf6d1b13315862a7663fc19
|
|
| BLAKE2b-256 |
8f6be3319b8ab32d5bbbe202bff4f2851cc6d205e7ace8d13ffb8230f354f42b
|
Provenance
The following attestation bundles were made for medmask-0.1.3-py3-none-any.whl:
Publisher:
ci.yml on fastdiag-toolbox/medmask
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medmask-0.1.3-py3-none-any.whl -
Subject digest:
d7492fea07ce269e9e238bb4ea5f2fc86ed488112443caa507873e4d7daf1fec - Sigstore transparency entry: 305269724
- Sigstore integration time:
-
Permalink:
fastdiag-toolbox/medmask@2fdbeba342746bac706e4eed9cd9934a07fdcbfb -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/fastdiag-toolbox
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2fdbeba342746bac706e4eed9cd9934a07fdcbfb -
Trigger Event:
push
-
Statement type: