Skip to main content

A simple utility for trimming borders from images represented as HWC ndarrays, based on the color value of a specified corner.

Project description

trim-hwc-ndarray

A simple utility for trimming borders from images represented as HWC ndarrays, based on the color value of a specified corner.

Features

  • Trim uniform borders from an HWC ndarray in which the border pixels match the color of a specified corner.
  • Flexible selection of which corner to use as the background color.
  • Preserves image channels and returns a trimmed copy.

Installation

pip install trim-hwc-ndarray

Usage

# coding=utf-8
from __future__ import print_function
from trim_hwc_ndarray import trim_hwc_ndarray, Corner
import numpy as np

# Example: Trim a border from a 3x3 RGB image
img = np.array([
    [[255, 255, 255], [255, 255, 255], [255, 255, 255]],
    [[255, 255, 255], [0, 0, 0], [255, 255, 255]],
    [[255, 255, 255], [255, 255, 255], [255, 255, 255]]
])
trimmed_img = trim_hwc_ndarray(img, Corner.TOP_LEFT)
print(trimmed_img.shape)  # Output: (1, 1, 3)

Contributing

Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.

License

This project is licensed under the MIT License.

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

trim_hwc_ndarray-0.1.0a0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

trim_hwc_ndarray-0.1.0a0-py2.py3-none-any.whl (3.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file trim_hwc_ndarray-0.1.0a0.tar.gz.

File metadata

  • Download URL: trim_hwc_ndarray-0.1.0a0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for trim_hwc_ndarray-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 eb6b4467ddce95ed424bf3a8bb9a5c6d0665730e0b9cacbaf616e7d75651e3e1
MD5 36ec767737be4c9cc3d9ed676e61d57e
BLAKE2b-256 35ee340d494a8331d5c001ae750e3aa88d3ec066a5c25ff1af7188b61207f892

See more details on using hashes here.

File details

Details for the file trim_hwc_ndarray-0.1.0a0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for trim_hwc_ndarray-0.1.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 90ea1135b9a9621484a3309e2ed970ac336272e6cb2aa89449392a116bc8495d
MD5 fb59d87c5bffccf19b4f4b7fcc264a1c
BLAKE2b-256 eb092b24715609f1725cd1ff86a474eff0c92a31db8637bc4514838327ff0a71

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