Small, function-based image and mask processing library built on numpy
Project description
sdimg
Small, function-based image and mask processing library built on numpy.ndarray.
Install
pip install sdimg
Modules
sdimg.image: normalize, blur, denoise, sharpen, color helperssdimg.mask: binary mask cleanup, hull/edge/distance, bbox/ROI helperssdimg.spatial: resize, crop, rotate/flip, pad, split/merge patchessdimg.fusion:otsu_threshold(OpenCV Otsu),grabcut
Core Contracts
- Input arrays must be
numpy.ndarray - Images: shape
(H, W)or(H, W, C)withC in 1..4 - Masks: shape
(H, W), binary values (bool,{0,1},{0,255}) - Output images are
np.uint8 - Output masks are binary
np.uint8in{0, 1} - BBox format:
(wmin, hmin, wmax, hmax) - Empty-mask returns
Nonefor:to_roi_boxget_box_from_maskget_box_from_coordsget_centroid
Error Policy
TypeError: wrong input type (non-numpy.ndarray)ValueError: invalid shape, invalid params, invalid mask values, invalid bboxRuntimeError: wrapped lower-level failures (cv2, internal processing)
Internal Structure
sdimg/_core/validate.py: shared validators (ensure_src,ensure_image,ensure_mask,ensure_bbox)sdimg/_core/types.py: shared type aliasessdimg/_core/errors.py: shared error helpers
Quick Example
import numpy as np
from sdimg.image import hist_norm, gaussian_blur
from sdimg.mask import morphology, to_roi_box
from sdimg.fusion import grabcut
image = np.random.randint(0, 256, (128, 128, 3), dtype=np.uint8)
mask = np.zeros((128, 128), dtype=np.uint8)
mask[32:96, 40:88] = 1
image = hist_norm(image)
image = gaussian_blur(image, (5, 5), 1.2)
mask = morphology(mask, "open", (3, 3), 1)
roi_box = to_roi_box(mask)
if roi_box is not None:
refined = grabcut(image=image, roi=roi_box["roi"], box=roi_box["box"])
Local Test
PYTHONPATH=. pytest -q
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sdimg-0.2.0.tar.gz
(13.6 kB
view details)
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
sdimg-0.2.0-py3-none-any.whl
(19.5 kB
view details)
File details
Details for the file sdimg-0.2.0.tar.gz.
File metadata
- Download URL: sdimg-0.2.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d749ea2c08de5a32da0fae90c18c49396520c73b21cb4728c75648e8c0493da
|
|
| MD5 |
bf0c4fcff6454b92109dae13a2865a2c
|
|
| BLAKE2b-256 |
ef8f9524a745ac0554059165d77d92d0680307efcab97d520a34c41765fb7e58
|
File details
Details for the file sdimg-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sdimg-0.2.0-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6be7e7b041096e261dc257dced20ed8979d82cd7a3a9510c811372e3199581e4
|
|
| MD5 |
e3490adc9afd2eef04cb14e948fe9676
|
|
| BLAKE2b-256 |
ee0f01e51df8376c2962c602171d15522e91321c64b05f098393fc9e30bce70d
|