Letterbox an HWC ndarray image to fit the target width and height while updating the homogeneous transformation matrix.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
File details
Details for the file hwc_ndarray_letterbox-0.1.0a0.tar.gz.
File metadata
- Download URL: hwc_ndarray_letterbox-0.1.0a0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09079abc90d4e65059d78e1802f3bf6e0a69b3e982d8eb7d8bb438ad27f5cb81
|
|
| MD5 |
9eb88797e129adc9001ef56296f4f43d
|
|
| BLAKE2b-256 |
9e34cff158d7e3c125b17ecd736a3fc6ed1e5eac42cfe506af4beb3eec435663
|
File details
Details for the file hwc_ndarray_letterbox-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: hwc_ndarray_letterbox-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2d6193b225bc87881aae8b57fb8b0aa4a313401323e4a9ea105e88ee23885ad
|
|
| MD5 |
b329b666dfb167c7384509d7c050e359
|
|
| BLAKE2b-256 |
49e55146cb636bc9ae010dcfccf68428bacc6f8f31617831db79f66f27c17e39
|