A lightweight image packing library
Project description
Simple Packer
A lightweight image packing library.
Why?
This package was created to solve color space issues with existing image packing libraries like image-packer, which use PIL/Pillow internally and can introduce unwanted RGB/BGR conversions. wsi-packer works directly with OpenCV/NumPy arrays in their native color space, making it ideal for medical imaging and other applications where color accuracy is critical.
Features
- Color preserving: No PIL/Pillow conversions - works directly with NumPy arrays
- Shelf packing algorithm: Efficient First Fit Decreasing Height (FFDH) bin packing
- Automatic sizing: Container dimensions calculated automatically based on content
- Configurable margins: Control spacing between packed images
Installation
Install via pip:
pip install wsi-packer
Or install directly from GitHub:
pip install git+https://github.com/computationalpathologygroup/wsi-packer.git
For development:
git clone https://github.com/computationalpathologygroup/wsi-packer.git
cd wsi-packer
pip install -e .
Usage
import numpy as np
from wsi_packer import pack_images
# Create some example images (or load with cv2.imread)
images = [
np.random.randint(0, 255, (100, 200, 3), dtype=np.uint8),
np.random.randint(0, 255, (150, 150, 3), dtype=np.uint8),
np.random.randint(0, 255, (80, 120, 3), dtype=np.uint8),
]
# Pack them into a single image
packed = pack_images(images, margin=5)
# Save or display
import cv2
cv2.imwrite('packed.jpg', packed)
Algorithm
Uses a shelf packing algorithm:
- Sorts images by height (tallest first)
- Creates horizontal "shelves" to place images
- Tries to fit each image on an existing shelf before creating a new one
- Automatically sizes the container based on actual content
This provides better space utilization than a simple grid layout while maintaining simplicity and color accuracy.
Parameters
images(List[np.ndarray]): List of NumPy arrays (images) to packmargin(int): Margin in pixels between images (default: 5)
Returns
Single NumPy array containing all packed images with white background (255, 255, 255).
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 wsi_packer-0.1.0.tar.gz.
File metadata
- Download URL: wsi_packer-0.1.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7ea7861130c8f5a260c53956c8b517a63a0ef4e7bf5ebc62c4bd7515289d3d3
|
|
| MD5 |
98b671f3d2ad364f3c802f4d1e32450f
|
|
| BLAKE2b-256 |
c036006d7f70a7aac0d326e797b952132213d9df1ae7b49f34aeefdba2934cf7
|
File details
Details for the file wsi_packer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wsi_packer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b35f7834614ee3f22025b58c95b4de40f8fc6ee1e5326c74cf1367affded5342
|
|
| MD5 |
69d8abd65ab5a16061066dfac103a516
|
|
| BLAKE2b-256 |
58f061b51d1d3f93717f3b6f3e9a71392297698018951e57f68d0a6d07cb849a
|