Aspect-Pad 📐
A lightweight, PyTorch-compatible computer vision transform that perfectly scales and mathematically pads images without distorting their aspect ratios.
When feeding unconstrained real-world images (like drone photography, medical scans, or OCR inputs) into Convolutional Neural Networks (CNNs), standard resizing often squishes and warps the data. Aspect-Pad intelligently scales the image and dynamically pads the remaining space to create a perfect square (or custom rectangle) tensor, preserving the original spatial features of your dataset.
🚀 Installation
You can install the package directly from PyPI:
pip install aspect-pad
💻 Quick Start
Aspect-Pad works natively with PIL Images and drops directly into standard PyTorch transforms.
import torchvision.transforms as transforms
from PIL import Image
from aspect_pad import AspectPad
# Load a raw, irregularly-shaped image
raw_image = Image.open("messy_drone_photo.jpg")
# Target a 512x512 square tensor, dynamically padding the empty space with black (0)
pipeline = transforms.Compose([
AspectPad(target_size=512, fill=0),
transforms.ToTensor()
])
# Pass the image through the pipeline
tensor_image = pipeline(raw_image)
print(tensor_image.shape) # Output: torch.Size([3, 512, 512])
⚙️ Features
-
Drop-in PyTorch Compatibility: Built to work flawlessly inside torchvision.transforms.Compose.
-
Universal "Anti-Squish" Math: Automatically calculates the delta for wide or tall images and centers the original image perfectly.
-
Custom Target Sizes: Target a single integer for standard square CNNs (e.g., 224 for ResNet) or pass a tuple for specific architectures (e.g., (1920, 1080)).
-
Custom Fill Colors: Support for grayscale padding (e.g., 0 for black), RGB padding (e.g., (255, 255, 255) for white), or any arbitrary background color.
Author: Shin Thant Tun
Release files for aspect-pad 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aspect_pad-0.1.3.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aspect_pad-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.6 kB
Release files / aspect_pad-0.1.3.tar.gz
| Download URL | aspect_pad-0.1.3.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea86a39d6c796c2a9a0db3ec4291ec5a9034b0f66ddab451eecc47453057f80c
|
|
BLAKE2b-256 checksum How to use checksums |
0c799c6b0bf1ec4eeb6983ab01f9031fe7eb2244d06975c20bc6c9ce17d1c237
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|
Release files / aspect_pad-0.1.3-py3-none-any.whl
| Download URL | aspect_pad-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
658936cab860ea41562e3b5195688d7ca4f8c1bb44351e2e3d44a892a9222c28
|
|
BLAKE2b-256 checksum How to use checksums |
d6ce5ec7801511e6328a59d25888e40253a3adb1a07492ab1416635866ca3bfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.13
|