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:hist_norm,clahe_norm,minmax_norm,zscore_norm,gaussian_blur,median_blur,denoise,sharpen,adjust_brightness_contrast,to_gray,to_rgb,to_uint8,is_imagesdimg.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,is_masksdimg.spatial:resize,resize_keep_ratio,crop,pad_to_square,rotate,flip,split,mergesdimg.fusion:otsu_threshold,grabcut
Core Contracts
- Input arrays must be
numpy.ndarray - Images: shape
(H, W)or(H, W, C)withC in 1..4 - Color channel order: RGB. Color images passed to
sdimgmust be in RGB order.cv2.imreadreturns BGR — callers using OpenCV I/O must convert withcv2.cvtColor(img, cv2.COLOR_BGR2RGB)before callingsdimgfunctions. - Channel-count semantics:
C == 1: grayscaleC == 2: grayscale + alpha (alpha is ignored byto_gray/to_rgb)C == 3: RGBC == 4: RGBA (alpha is ignored byto_gray/to_rgb)
- 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)
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"])
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.1.tar.gz
(14.0 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.1-py3-none-any.whl
(20.1 kB
view details)
File details
Details for the file sdimg-0.2.1.tar.gz.
File metadata
- Download URL: sdimg-0.2.1.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6392b63c9a59dc3c5211ad828ceb46e7f3cfff2295274a3cc9d5dd32bcf3768
|
|
| MD5 |
9367da975702bfae037f1ff4d5f853b7
|
|
| BLAKE2b-256 |
8126b91f26a5ab390e6ed9a66db6df676ab2d5a00976fc86a05c49804ba46045
|
File details
Details for the file sdimg-0.2.1-py3-none-any.whl.
File metadata
- Download URL: sdimg-0.2.1-py3-none-any.whl
- Upload date:
- Size: 20.1 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 |
700cf89798df6acb3413e437edad5b8b816a2d0ad6754f769896bde8ad78bbe7
|
|
| MD5 |
ec74685b5db31d66a64f2b9abb0017bb
|
|
| BLAKE2b-256 |
77d7b02b40f0eaf3aa5af7584ccaa063909aad254e9795206ac870ec91e507a0
|