Pre-release
This release is a pre-release and may not be stable for production use.
hwc-ndarray-letterbox
Letterbox an HWC ndarray image to fit the target width and height while updating the homogeneous transformation matrix.
Commonly used in computer vision pipelines (e.g., YOLO object detection), where you need to reverse-map coordinates such as bounding boxes from the preprocessed image back to the original image space.
Usage
import cv2
import numpy as np
from hwc_ndarray_letterbox import hwc_ndarray_letterbox
# Load an image (HWC ndarray)
image = cv2.imread('input.jpg')
current_homogeneous_transformation_matrix = np.eye(3)
# Desired output size
target_width = 640
target_height = 640
# Perform letterbox resize with matrix tracking
(
letterboxed_image,
homogeneous_transformation_matrix,
) = hwc_ndarray_letterbox(
image,
current_homogeneous_transformation_matrix,
target_width,
target_height,
)
print('Homogeneous transformation matrix:', homogeneous_transformation_matrix)
# To map points from letterboxed image back to original:
# inverse_homogeneous_transformation_matrix = np.linalg.inv(homogeneous_transformation_matrix)
# original_point = inverse_homogeneous_transformation_matrix @ np.ndarray([x, y, 1])
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Release files for hwc-ndarray-letterbox 0.1.0a0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hwc_ndarray_letterbox-0.1.0a0.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hwc_ndarray_letterbox-0.1.0a0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 7.4 kB
Release files / hwc_ndarray_letterbox-0.1.0a0.tar.gz
| Download URL | hwc_ndarray_letterbox-0.1.0a0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09079abc90d4e65059d78e1802f3bf6e0a69b3e982d8eb7d8bb438ad27f5cb81
|
|
BLAKE2b-256 checksum How to use checksums |
9e34cff158d7e3c125b17ecd736a3fc6ed1e5eac42cfe506af4beb3eec435663
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / hwc_ndarray_letterbox-0.1.0a0-py2.py3-none-any.whl
| Download URL | hwc_ndarray_letterbox-0.1.0a0-py2.py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
d2d6193b225bc87881aae8b57fb8b0aa4a313401323e4a9ea105e88ee23885ad
|
|
BLAKE2b-256 checksum How to use checksums |
49e55146cb636bc9ae010dcfccf68428bacc6f8f31617831db79f66f27c17e39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|