Skip to main content

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_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, is_mask
  • sdimg.spatial: resize, resize_keep_ratio, crop, pad_to_square, rotate, flip, split, merge
  • sdimg.fusion: otsu_threshold, grabcut

Core Contracts

  • Input arrays must be numpy.ndarray
  • Images: shape (H, W) or (H, W, C) with C in 1..4
  • Color channel order: RGB. Color images passed to sdimg must be in RGB order. cv2.imread returns BGR — callers using OpenCV I/O must convert with cv2.cvtColor(img, cv2.COLOR_BGR2RGB) before calling sdimg functions.
  • Channel-count semantics:
    • C == 1: grayscale
    • C == 2: grayscale + alpha (alpha is ignored by to_gray/to_rgb)
    • C == 3: RGB
    • C == 4: RGBA (alpha is ignored by to_gray/to_rgb)
  • Masks: shape (H, W), binary values (bool, {0,1}, {0,255})
  • Output images are np.uint8
  • Output masks are binary np.uint8 in {0, 1}
  • BBox format: (wmin, hmin, wmax, hmax)
  • Empty-mask returns None for:
    • to_roi_box
    • get_box_from_mask
    • get_box_from_coords
    • get_centroid

Error Policy

  • TypeError: wrong input type (non-numpy.ndarray)
  • ValueError: invalid shape, invalid params, invalid mask values, invalid bbox
  • RuntimeError: 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.3.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sdimg-0.2.3-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file sdimg-0.2.3.tar.gz.

File metadata

  • Download URL: sdimg-0.2.3.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sdimg-0.2.3.tar.gz
Algorithm Hash digest
SHA256 eb42ae9c79492ae9251ce5bc694683eba41d0b179b7d57848dfc0b5c9631815b
MD5 ae87fc254bf7303721429e6f0ec0bd89
BLAKE2b-256 ac616c936288145e87afe453ad0300d4bd5a14c78113b676bcb7bee047bdf776

See more details on using hashes here.

File details

Details for the file sdimg-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: sdimg-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for sdimg-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 60e136931361d56fbb5886aea3458123cf0ea00575048c741f9f249e9ddd6c13
MD5 621e5f875896f4c485a2c71a88d8a589
BLAKE2b-256 aaafdbf7da852309e08045c6d1f84d1c4885d0c3aa869355ef98ad7abb0510ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page