Convert an HWC BGR 888 or BGRX 8888 NumPy ndarray to a CHW RGB PyTorch tensor, with pixel values normalized to `[0, 1]` and the alpha/unused channel discarded.
Project description
hwc-bgrx-8888-ndarray-to-chw-rgb-0-1-tensor
Convert an HWC BGR 888 or BGRX 8888 NumPy ndarray to a CHW RGB PyTorch tensor, with pixel values normalized to [0, 1]
and the alpha/unused channel discarded.
This function helps bridge interoperability between Qt, OpenCV (which often use HWC BGRX 8888 images), and PyTorch (
which often uses CHW RGB tensors with pixel values normalized to [0, 1]).
Installation
pip install hwc-bgrx-8888-ndarray-to-chw-rgb-0-1-tensor
Usage
import numpy as np
from hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor import hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor
# Example: create a dummy BGRX image
hwc_bgrx = np.random.randint(0, 256, (224, 224, 4), dtype=np.uint8)
tensor = hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor(hwc_bgrx)
print(tensor.shape) # (3, 224, 224)
print(tensor.min(), tensor.max()) # [0.0, 1.0]
Notes
- This function makes the array contiguous for compatibility with PyTorch tensors.
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_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor-0.1.0a0.tar.gz.
File metadata
- Download URL: hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor-0.1.0a0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
852d1b73567ff7f7cc8fa34e265cbca4bb56027de81a0188938bb3aea97c82b2
|
|
| MD5 |
7880b5b32567596a920f5ecddc7b2685
|
|
| BLAKE2b-256 |
5e487978d67e7a22eb52fbde87c8d36c065f83d09213aeff461377f10166f926
|
File details
Details for the file hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: hwc_bgrx_8888_ndarray_to_chw_rgb_0_1_tensor-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.6 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 |
10315171bfcab0c0f5e720dabb472e34e7e43dcadeb562e76d6ce79f428df8c1
|
|
| MD5 |
09bb9455d491227808f407b1450db3f1
|
|
| BLAKE2b-256 |
7c5e7bcfc36c4fe285d3a56db2bbfaf93d1c559ef8b22e3f04874671a3bbca34
|