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.
The public API is pure functions and requires Python 3.12+.
Install
pip install sdimg
Modules
sdimg.image:hist_norm,clahe_norm,minmax_norm,zscore_norm,gaussian_blur,median_blur,denoise,sharpen,adjust_brightness_contrast,to_gray,to_rgb,to_uint8,get_id,encode,decode,imread,imwrite,is_image.sdimg.mask:morphology;convex_hull,concave_hull;extract_edge,distance_transform,pick_largest,fill_holes;get_box_from_mask,get_box_from_coords,get_coords,get_centroid,get_roi_size,get_box_size,to_roi_box;to_mask, andis_mask.sdimg.spatial:resize,resize_keep_ratio,crop,pad_to_square,rotate,flip,split, andmerge.sdimg.fusion:otsu_thresholdandgrabcut.
Core Contracts
- Inputs must be
numpy.ndarray. - Images use shape
(H, W)or(H, W, C)withC in 1..4. - Color images are RGB. If you read with
cv2.imread, convert BGR to RGB first withcv2.cvtColor(img, cv2.COLOR_BGR2RGB). - Pillow-backed file I/O reads images as RGB
np.uint8arrays with shape(H, W, 3). High-bit-depth integer and float sources are explicitly scaled touint8before RGB conversion. Writing accepts onlyuint8image arrays and saves RGB files. - Channel counts mean:
1grayscale,2grayscale + alpha,3RGB, and4RGBA. Alpha channels are ignored byto_grayandto_rgb. - Masks use shape
(H, W)and binary values:bool,{0, 1}, or{0, 255}. - Output images are
np.uint8; output masks are binarynp.uint8in{0, 1}. - BBox format is
(wmin, hmin, wmax, hmax), width-first, min-inclusive, max-exclusive. - Empty masks return
Nonefromto_roi_box,get_box_from_mask,get_box_from_coords, andget_centroid.
Error Policy
TypeError: wrong input type.ValueError: invalid shape, params, mask values, or bbox.RuntimeError: wrapped lower-level failures fromcv2or internal processing.
Quick Example
import numpy as np
from sdimg.fusion import grabcut
from sdimg.image import gaussian_blur, hist_norm
from sdimg.mask import morphology, to_roi_box
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 = gaussian_blur(hist_norm(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"])
Image I/O And IDs
from sdimg.image import decode, encode, get_id, imread, imwrite
image = imread("input.tif") # RGB uint8, shape (H, W, 3)
image_id = get_id(image, prefix="img_")
payload = encode(image)
restored = decode(payload)
imwrite(f"{image_id}.png", restored)
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.5.tar.gz
(16.9 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.5-py3-none-any.whl
(24.2 kB
view details)
File details
Details for the file sdimg-0.2.5.tar.gz.
File metadata
- Download URL: sdimg-0.2.5.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3401faebffc883e798af6a9ecb3ea331459e43a846da83b01e75e25ab7dd3b91
|
|
| MD5 |
0bc652fdd16bd47d35a0de60925c6c61
|
|
| BLAKE2b-256 |
b6263d5b047b60b1d4ec05626209bfdba34c863603e53094f29869cda4a56b1f
|
File details
Details for the file sdimg-0.2.5-py3-none-any.whl.
File metadata
- Download URL: sdimg-0.2.5-py3-none-any.whl
- Upload date:
- Size: 24.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec88e14fa0ea8e366d3d23480e4b2bee8ecf5b45f056c5892f52c56b72a39ea4
|
|
| MD5 |
e293811027925272ccc95c5d63266347
|
|
| BLAKE2b-256 |
1022ec8623f815b3141bcf86ae9f1415c51743d84ad11d32dbc30f3acc8336df
|